Cross-browser key-value store database to store data locally in the browser.
simpleStorage is a fork of jStorage that only includes the minimal set of features. Basically it is a wrapper for native JSON + localStorage with some TTL magic mixed in.
The module has no dependencies, you can use it as a standalone script (introduces simpleStorage global) or as an AMD module. All modern browsers (including mobile) are supported, older browsers (IE7, Firefox 3) are not.
simpleStorage is very small - about 1kB in size when minimized and gzipped.
Quickest way to get up and running woulr be to use jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/simplestorage/0.2.0/simpleStorage.min.js"></script>
Otherwise you can download simpleStorage.js or install it with bower:
bower install simpleStorage
and include the following script in your web application: bower_components/simpleStorage/simpleStorage.js
or install with npm
npm install simplestorage.js
If you want to support with Bitcoins, then my wallet address is 15Z8ADxhssKUiwP3jbbqJwA21744KMCfTM
simpleStorage API is a subset of jStorage with slight modifications, so for most cases it should work out of the box if you are converting from jStorage. Main difference is between return values - if an action failed because of an error (storage full, storage not available, invalid data used etc.), you get the error object as the return value. jStorage never indicated anything if an error occurred.
Possible error codes (from err.code):
Store or update a value in local storage.
simpleStorage.set(key, value[, options])
Where
TTL which sets the time-to-live (TTL) value in milliseconds for the given key/value// the following entry expires in 100 seconds
simpleStorage.set(key, value, {TTL: 100000})
Return values
error.code for explanationRetrieve a value from local storage.
value = simpleStorage.get(key)
Where
Method returns the value for a key or undefined if the key was not found.
Removes a value from local storage.
simpleStorage.deleteKey(key)
Return values
error.code for explanationSet a millisecond timeout. When the timeout is reached, the key is removed automatically from local storage.
simpleStorage.setTTL(key, ttl)
Where
Return values
error.code for explanationRetrieve remaining milliseconds for a key with TTL
ttl = simpleStorage.getTTL(key)
Where
Return values
Clear all values
simpleStorage.flush()
Return values
error.code for explanationRetrieve all used keys as an array
list = simpleStorage.index()
Returns an array of keys.
Get used storage in symbol count
simpleStorage.storageSize()
Check if local storage can be used
simpleStorage.canUse()
Returns true if storage is available
See demo here.
See QUnit tests here.
JavaScript
68.1%
HTML
31.9%
Cross-browser key-value store database to store data locally in the browser.
simpleStorage is a fork of jStorage that only includes the minimal set of features. Basically it is a wrapper for native JSON + localStorage with some TTL magic mixed in.
The module has no dependencies, you can use it as a standalone script (introduces simpleStorage global) or as an AMD module. All modern browsers (including mobile) are supported, older browsers (IE7, Firefox 3) are not.
simpleStorage is very small - about 1kB in size when minimized and gzipped.
Quickest way to get up and running woulr be to use jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/simplestorage/0.2.0/simpleStorage.min.js"></script>
Otherwise you can download simpleStorage.js or install it with bower:
bower install simpleStorage
and include the following script in your web application: bower_components/simpleStorage/simpleStorage.js
or install with npm
npm install simplestorage.js
If you want to support with Bitcoins, then my wallet address is 15Z8ADxhssKUiwP3jbbqJwA21744KMCfTM
simpleStorage API is a subset of jStorage with slight modifications, so for most cases it should work out of the box if you are converting from jStorage. Main difference is between return values - if an action failed because of an error (storage full, storage not available, invalid data used etc.), you get the error object as the return value. jStorage never indicated anything if an error occurred.
Possible error codes (from err.code):
Store or update a value in local storage.
simpleStorage.set(key, value[, options])
Where
TTL which sets the time-to-live (TTL) value in milliseconds for the given key/value// the following entry expires in 100 seconds
simpleStorage.set(key, value, {TTL: 100000})
Return values
error.code for explanationRetrieve a value from local storage.
value = simpleStorage.get(key)
Where
Method returns the value for a key or undefined if the key was not found.
Removes a value from local storage.
simpleStorage.deleteKey(key)
Return values
error.code for explanationSet a millisecond timeout. When the timeout is reached, the key is removed automatically from local storage.
simpleStorage.setTTL(key, ttl)
Where
Return values
error.code for explanationRetrieve remaining milliseconds for a key with TTL
ttl = simpleStorage.getTTL(key)
Where
Return values
Clear all values
simpleStorage.flush()
Return values
error.code for explanationRetrieve all used keys as an array
list = simpleStorage.index()
Returns an array of keys.
Get used storage in symbol count
simpleStorage.storageSize()
Check if local storage can be used
simpleStorage.canUse()
Returns true if storage is available
See demo here.
See QUnit tests here.
JavaScript
68.1%
HTML
31.9%