Cross-browser key-value store database.
chasStorage is a lightweight replacement of jStorage that also contain some additional features.
Download chasStorage.js
Or install via npm:
npm install chas-storage
Attention: You must call chasStorage.load() manually!
Get value from storage
- name - the name of the value
- [defaultValue] - the defaultValue (if value not in storage). Default:
null
Returns: value, if found, else defaultValue
chasStorage.getItem('foo.bar.baz')
chasStorage.getItem(7577, 'lorem ipsum')Store value in storage
- name - the name of the value
- value - value itself
- [allowRewrite] - flag: is rewrite is allowed (i.e. if value is already in storage then it won't be changed). Default:
true
Returns: is value setted (if allowRewrite == true, always true)
chasStorage.setItem('foo', 56)
chasStorage.setItem('unique value', 'ipsum lorem', false)Remove value form storage
- name - the name of the value
Returns: is value were exist
chasStorage.delete('foo')Check is value in storage
- name - the name of the value
Returns: does storage contain value?
if (chasStorage.contains('foo')) {
console.log('key "foo" exists');
}Remove all items from storage
NOTE: It ignore autoFlush-flag
- flush - flag to flush after clear. Default:
false
chasStorage.clear();Load data
chasStorage.load();Save data
chasStorage.flush();Flag of autoFlush-mode:
Call chasStorage.flush() after every change.
Default: false
Contents of storage.
READONLY
Is chasStorage available.
Attention: domData is not depended on basic API of chasStorage
Using this extension you can save state of elements (of whole page or concrete DOM element) to storage.
domData handling every element with attribute data-chasstorage-id (you can change this name via domData.idAttriubte).
In data-chasstorage-id stored id of this element's record. In optional attribute data-chasstorage-conf you can specify things must be saved.
Those words with ! means exclude, else include:
value- value of element (only for inputs)checked- is checkbox checked (only for checkboxes)innerHtml- innerHtml of DOM elementvisible- isstyle.display != 'none'
Also you can exclude every thing by default with !*.
Priority of lexems:
!lexemlexem!*
ID attribute
Default: data-chasstorage-id
Configuration attribute
Default: data-chasstorage-conf
Load values to elements of domElement
- [domElement] - element of DOM. Default:
document
chasStorage.domData.load()
chasStorage.domData.load(document.getElementById('text-areas'))Save values of elements of domElement
- [domElement] - element of DOM. Default:
document
chasStorage.domData.save()
chasStorage.domData.save(document.getElementById('some-id'))