birkin
simple and immutable key/value-bag for storing session and configuration data in client-side applications
Installation
$ npm install birkin --save
In ES5:
var Bag = ;var sessionbag = ;
Using Babel / ES6:
;const sessionbag = ;
API
Constructor(objects...)
The instance can be passed any number of objects on instantiation that will serve as base data:
var emptyBag = ;var prepopulated = key: 'value';var numbers = one: 1 two: 2 three: 3;
set(key, value)
Associates any value with the given key:
var sessionbag = ;sessionbag;sessionbag;
set(objects...)
Merges the given object into the store:
var sessionbag = ;sessionbag;sessionbag;
get(key)
Retrieves a value by the given key:
sessionbag;sessionbag; // => 'Christ is risen'sessionbag; // => undefined
get(keys...)
Retrieves a value inside a stored object:
var sessionbag = ;sessionbag;sessionbag; // => 'not too sure'
get()
Retrieves the store as an object:
var sessionbag = ;sessionbag;sessionbag; // => {foo: 'bar'}
has(key)
Checks if the given key exists:
var sessionbag = ;sessionbag;sessionbag; // => truesessionbag; // => false
has()
Checks if the instance contains any keys:
var sessionbag = ;sessionbag; // => falsesessionbag;sessionbag; // => true
Immutability
birkin
is designed to be immutable. Keys cannot be overridden or unset. Returned values will be clones. This enforces well designed data structures and handling.
var sessionbag = ;sessionbag;sessionbag;sessionbag;sessionbag; // => {foo: 'bar', bar: 'foo'}sessionbag;var obj = sessionbag;obja = 'c';sessionbag; // => {a: 'b'}
If you are sure that mutating values is the right approach for your problem at hand, do so explicitly:
var sessionbag = key: 'value';var data = sessionbag;datakey = 'updated value';sessionbag = data;sessionbag; // => 'updated value'
License
MIT © Frederik Ring