Nonlinear Performance Magnification

npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

stor

0.1.5 • Public • Published

stor

build status

Figure out the best option for storing things in the browser and do it.

Example

// @todo: add a not ridiculous example
var stor = require('stor/stor.set('actor', {username: 'yolo17'}, function(err){
  stor.get('actor', function(err, actor){
    console.log(actor);
  });
});

Docs

stor.get(key, fn)

stor.set(key, value, fn)

stor.remove(key, fn)

stor.key(n, fn)

Backwards compat for localStorage.key. Get the key value in the store at position n.

stor.length(fn)

stor.clear(fn)

stor.use(name)

Manually switch to a different backend

stor.use(name).adapter(adapter, ns)

Get an adapter for your framework of choice.

Adapters

Backbone

var Backbone = require('backbone');
var sessionStorage = require('stor').use('session');
var historyBackend = sessionStorage.adapter('backbone', 'history');
var History = Backbone.Collection.extend({
  sync: historyBackend.sync
});

Todo

  • proper api for applying partial updates like Backbone's patch method.
  • id generation
  • namespace support in all stores translated where needed (eg localstorage -> use prefix, indexeddb -> use table name)

License

MIT

install

npm i stor

Downloadsweekly downloads

6

version

0.1.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability