client-side-storage
Provides key value pair storage. Right now only localStorage is implemented.
You want code coverage? We got code coverage so good it will make your head spin.
Installation
This package is distributed via npm:
npm install client-side-storage
Usage
var StorageAPI = ; //Optional name 'MyStorage' prevents namespace collisionsvar MyStorage = 'MyStorage'; MyStorage; MyStorage;
Set / Retrieve multiple items
MyStorage;
Remove item
MyStorage;
Clear storage
MyStorageclear;
Implement your own Storage Method
Implementing new methods is easy. Simply return a value from your implemented methods as below. See client-side-storage/methods/localStorage.js for example
{ //Save use for prefixing when viable thisname = name; } //This method must be synchronous { //Return true if the storage method will work in the current enviroment if typeofRandomGlobalStoragePlugin != 'undefined' return true; } { return '42'; //OR - if you need async, simply return a promise var deferred = Qdefer; deferred; return deferredpromise; } { //getMultiple will be called when Storage.get is called with an array of values //Your class should return an object of key-value pairs (or a promise which resolves to one) return key1: 'cool_value' key2: 'cool_value2' } { //set key equal to value in your method //if async, return a promise that will resolve when the process is complete //i.e. var deffered = Qdefer; ; return deferredpromise; } { //Called when Storage.set is called with an object of key value pairs //Set all keys in storage, return a promise or value as above } { //Delete variable, then return promise or value as above } { //Clear your storage then return promise or value as above }