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 = require('client-side-storage');
var MyStorage = new StorageAPI('MyStorage');
MyStorage.addStorageMethod(require('client-side-storage/methods/localStorage');
MyStorage.set('stuff', 'things')
.then(function() {
return MyStorage.get('stuff');
})
.then(function(stuff) {
console.log(stuff);
});
Set / Retrieve multiple items
MyStorage.set({stuff: 'things', children: 'the future'})
.then(function() {
return MyStorage.get(['stuff', 'children']);
})
.then(function(obj) {
console.log(obj);
});
Remove item
MyStorage.remove('stuff')
.then(function() {
console.log('stuff is gone');
});
Clear storage
MyStorage.clear()
.then(function() {
console.log('the past is dead, hoss...');
});
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
class MyStorageMethod() {
constructor(name) {
this.name = name;
}
isSupported() {
if (typeof(RandomGlobal.Storage.Plugin) != 'undefined') {
return true;
}
}
get(variable) {
return '42';
var deferred = Q.defer();
deferred.resolve(42);
return deferred.promise;
}
getMultiple(array_of_values) {
return {key1: 'cool_value', key2: 'cool_value2'}
}
set(key, value) {
var deffered = Q.defer();
setValueOnServer(function() {
deferred.resolve(true);
});
return deferred.promise;
}
setMultiple(obj) {
}
remove(variable) {
}
clear() {
}
}