Skip to content

Latest commit

 

History

History
87 lines (60 loc) · 1.67 KB

README.md

File metadata and controls

87 lines (60 loc) · 1.67 KB

Depot

Treat window.localStorage more like Redis

Build Status

Usage

```javascript
store = new Depot
```

Features

  • The basics – get, set, del:

    // tk
  • Store non-string values:

    store.set('album', {album: "Mass Romantic", band: "The New Pornographers", year: 2000});
  • Array methods:

    store.set('extracurriculars', [
        'Yankee Review',
        'French Club',
        'Model UN',
        '2nd Chorale'
    ]);
    • pop:

      store.pop('extracurriculars')
      -> '2nd Chorale'
      // 'numbers' = ['Yankee Review', 'French Club', 'Model UN']
    • push:

      store.push('extracurriculars', 'Kite Flying Society')
      // 'numbers' = ['Yankee Review', 'French Club', 'Model UN', 'Kite Flying Society']
    • len:

      // tk
  • Simple counter manipulation with incr and decr:

    // key 'bottlesOfBeerOnTheWall' = 99
    store.decr('bottlesOfBeerOnTheWall')
    -> 98
    
    store.incr('visitors', 10)
    -> 10
  • Key prefixing:

    var store = new Depot('myapp');
    value = store.get('username');
    // same as: window.localStorage.getItem('myapp:username');

Non-features

  • Doesn't emulate localStorage for older browsers (and never will)

Future development

  • Events API