1.0.2 • Published 10 years ago
localstorage-ns v1.0.2
localStorage-ns 
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
keyis being set. Both thekeybeing set and thevalueofkeywill 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