StorkJS
Simple key-value storage in your browser.
Easiest way to install is via bower with bower install storkjs
.
View Documentation / Download stork.js / Download stork.min.js
stork.js
is110KB
(17KB
gzipped)stork.min.js
is26KB
(7KB
gzipped)
StorkJS allows you to store key-value pairs & records in the browser, so when your user returns that data is still there. Inspired by lawnchair, StorkJS is a more robust option with error handling, key customization, and much more!
StorkJS uses the most preferred & supported storage available based on your browser.
Features
- Clean and simple API
- Pure Javascript, no dependencies
- Graceful degradation of storage backends, uses the best one available!
- Keys & Values can be any data type
- All stored key-value pairs/records can be loaded on initialization or lazy loaded upon request
- Promises & chaining allow for cleaner code, since saving and retrieving data isn't always synchronous
- Plugins can be added to alter behavior
- Everything is cached to avoid unnessary retrievals
API
then(callback)
: Start a chain of asynchronous callsget(key, [success], [failure])
: Return a single value if it existsgetMany(keys, [success], [failure])
: Return several values at oncesave(record, [success], [failure])
: Save a record, generating a key if one doesn't existbatch(records, [success], [failure])
: Save multuple records at onceput(key, value, [success], [failure])
: Save a key-value pairremove(key, [success], [failure])
: Removes a value/record based on their keyremoveMany(keys, [success], [failure])
: Removes several values/records at oncedestroy([success], [failure])
: Remove all key-values/recordsreload([success], [failure])
: Load all records into cacheeach(callback, [failure])
: Invokes the callback for all key-value pairsall([success], [failure])
: Returns all keys and values to the callbacksize([success], [failure])
: Returns the number of key-value pairs to the callback
Functionality added through plugins
where(condition, [success], [failure])
: Returns a subset of all key-value pairs that match some conditionselect(columns, [success], [failure])
: Returns an array of specified propertiessort(comparator, [success], [failure])
: Sorts keys and values and returns the sorted valueaggregate(property, accumulate, getResult, [success], [failure])
: Performs an aggregation on a propertycount(property, [success], [failure])
: Returns the number of objects with a propertysum(property, [success], [failure])
: Returns the sum of a property on object valuesavg(property, [success], [failure])
: Returns the average of a property on object valuesmin(property, [success], [failure])
: Returns the minimum value of a property on object valuesmax(property, [success], [failure])
: Returns the maximum value of a property on object values
Examples
Using StorkJS as a record store
var db = name: 'todos' ;// Save one recorddb;// Save multiple at oncedb;// Save one without an ID, an ID is placed in the record automaticallydb;// Remove onedb;// Retrieve a recorddb;// Retrieve all recordsdball{ // todos = array of all todo records};
Using StorkJS as a key-value store
var db = name: 'settings' ;db;db;db;db;db;// Remove onedb;// Retrieve one key-value pairdb;// Retrieve all key-value pairsdball{ // values = array of all values, keys = array of corresponding keys};
Listening for success or failure
// All saving, removal, & retrieval operations can be passed success & failure callbacksdb; // All saving, removal, & retrieval operations return promisesdb ; // If a result of a callback is a promise, YOU CAN CHAIN THEM!db ;
Building
npm install
gulp
Building Documentation
gulp docs
Testing
Once built, view test/index.html
in the browser.
TODO
- Test
chrome-storage-local
adapter - Test
ie-userdata
adapter - Add Blackberry Persistent storage
- Add HTML5 Filesystem storage
- Add IE Userdata storage
- Add IndexedDB storage
- Add CouchDB storage