@veams/utility-storage
v1.0.1
Published
Offers a simple API for storing Javascript objects in HTML5 web storage using distinct namespaces.
Downloads
24
Readme
Storage
Description
This utility offers a simple API for storing Javascript objects in HTML5 web storage using distinct namespaces
Requirements
- @veams/helpers - Object extend helper.
Installation
Installation with Veams
veams install u storage
veams -i u storage
Usage (API)
Just initialize on demand like this:
let myStorage = new Storage({
type: 'permanent', // or 'session'
name: 'someName' // custom namespace (e.g. from module)
});
Constructor
Storage(opts: StorageOptions)
/**
* Constructor
*
* @param {Object} opts - options which will be passed as object
* @param {String} opts.type - storage type ('permanent' || 'session')
* @param {String} opts.name - namespace in which items will be saved
*/
Properties
- length {
Number
} - item count
Methods
setItem(name:String, obj:Object)
/**
* Set item
*
* @param {String} name - item name
* @param {Object} obj - object to save
*/
getItem (name:String)
/**
* Get item by name
*
* @param {String} name - item name
* @return {Object} - object retrieved by item name
*/
getAllItems ()
/**
* Get all items
*
* @public
*
* @return {Object} - object containing all items
*/
removeItem (name:String)
/**
* Remove item by name
*
* @param {String} name - item name
*/
clear ()
/**
* Clear all items
*/