Skip to content

A wrapper around the window.localStorage API supporting non-string types & convenience methods like pop & push.

Notifications You must be signed in to change notification settings

banterability/depot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A wrapper around the window.localStorage API supporting non-string types & convenience methods like pop & push.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published