1.0.0 • Published 9 years ago

browser-async-store v1.0.0

Weekly downloads
14
License
MIT
Repository
github
Last release
9 years ago

browser-async-store Build Status

Wrap Web Storage APIs in an asynchronous API

Install

$ npm install --save browser-async-store

Usage

var createStore = require('browser-async-store')
var store = createStore(window.localStorage)

store.put('foo', 'bar', function (err) {
  if (!err) {
    store.get('foo', console.log.bind(console))
  }
})
//=> logs: bar

API

createStore(storage, options) -> store

Returns a store object.

storage

A Storage API, e.g. localStorage or sessionStorage.

options
parse

Type: function
Default: JSON.parse

format

Type: function
Default: JSON.stringify


store.get(key, callback) -> undefined

Get data from the store.

key

Required
Type: string

callback

Required
Type: function
Arguments: err, value

store.put(key, value, [callback]) -> undefined

Add an item to the store (or overwrite an existing item).

key

Required
Type: string

value

Required
Type: any

callback

Required
Type: function
Arguments: err

store.remove(key, [callback]) -> undefined

Remove an item.

key

Required
Type: string

callback

Required
Type: function
Arguments: err

store.clear([callback]) -> undefined

Clear the store.

callback

Required
Type: function
Arguments: err

License

MIT © Ben Drucker