A simple localstorage api with uses ES6 classes. This library saves data from localstorage in local variable and syncs this variable with localstorage. When you try to get data, library doesn't read localstorage it just returns data from local variable.
npm i es6-store --save
Just import Store
from Store.js if you use ES6
import Store from 'node_module/es6-store/src/Store.js'
Just require es6-store
if you use browserify
var Store = require(es6-store);
Create instance of Store
var store = new Store('NameOfYourStore')
store.set
store.get
store.getAll
store.remove
store.clear
store.destructor
Store.serialize
Store.deserialize
Store.clone
Persists value
under key
in local storage.
Key will be removed if value
is undefined
.
You can use multi key!
- An error if
key
isn'tstring
or set failed. - Set
value
or remotevalue
store.set('foo', 'bar');
-> 'bar'
store.set('bar.baz', 'bar');
-> 'bar'
store.getAll();
->
{
foo: 'bar',
bar: {
baz: 'bar'
}
}
Return value
under key
in local storage.
Will be return defaultValue
if key
is not defined.
You can use multi key!
- An error if
key
isn'tstring
or set failed. value
underkey
ordefaultValue
.
store.get('foo');
-> 'bar'
store.get('bar.baz');
-> 'bar'
store.get('baz', 'bar'); // baz is not defined
-> 'bar'
Return local storage object.
- local storage object.
store.getAll();
->
{
foo: 'bar',
bar: {
baz: 'bar'
}
}
Removes key
from local storage.
You can use multi key!
- An error if
key
isn'tstring
or remove failed. undefined
ifkey
is not defined.value
of removedkey
.
store.remove('foo');
-> 'bar'
store.remove('bar.baz');
-> 'bar'
store.get('baz', 'bar'); // baz is not defined
-> undefined
Clear local storage object.
undefined
.
Remove event listener.
If first argument is true
, local storage item will be removed
undefined
.
Static method. Convert from JSON to string.
Static method. Convert from string to JSON.
Static method. Clone object. Use JSON.stringify and JSON.parse.