localstorage-ns

1.0.2 • Public • Published

localStorage-ns travis ci

Namespaced key/value store backed by localStorage with events and default value loading.

Example:

import Store from 'localStorage-ns'
 
let foo = Store('foo', {age: 34})
let bar = Store('bar', {age: 29})
 
foo.set('name', 'Kevin')
bar.set('name', 'Charlie')
 
foo.get('name') //=> 'Kevin'
foo.get('age') //=> '34'
 
bar.get('name') //=> 'Charlie'
bar.get('age') //=> '29'

API

Store(name, [defaults])

Create a new namespaced store with name and optional defaults.

store#set(key, value)

Set key to value.

store#get(key)

Return value of key.

store#clear()

Clear the namespaced store.

store#on(event, fn)

Listen for the given event and execute callback fn. Available events are:

  • set: Emitted whenever a key is being set. Both the key being set and the value of key will be passed to the callback.
  • change: Emitted on any change. No values are passed to the callback.
  • clear: Emitted when the store is cleared. No values are passed to the callback.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i localstorage-ns

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • kvnneff