Package Exports
- base-store
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (base-store) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
base-store 
base-methods plugin for getting and persisting config values. Adds a 'store' object that has all of the methods from the data-store library.
For example, by adding this plugin you can do this:
app.set('a', 'b');
app.store.set('a', 'z');
console.log(app.get('a'));
//=> 'b';
console.log(app.store.get('a'));
//=> 'z';Additionally, store.set persists values to disk, but set does not.
The goal is to have methods dedicated to getting and persisting config values, while cleanly co-existing with the methods that deal with getting and setting values in-memory.
Install
Install with npm
$ npm i base-store --saveRelated projects
- base-data: adds a
datamethod to base-methods. | homepage - base-methods: Starter for creating a node.js application with a handful of common methods, like
set,get,… more | homepage - base-options: Adds a few options methods to base-methods, like
option,enableanddisable. See the readme… more | homepage - base-plugins: Upgrade's plugin support in base-methods to allow plugins to be called any time after init. | homepage
API
Add store and base to your application:
var store = require('base-store');
var Base = require('base-methods');
var base = new Base();Register the store plugin with base-methods:
// store `name` is required
base.use(store('foo'));
// pass options (like cwd) as the second arg.
// default cwd is `~/data-store/`
base.use(store('foo', {cwd: 'a/b/c'}));example
base.store
.set('a', 'b')
.set({c: 'd'})
.set('e.f', 'g')
console.log(base.store.get('e.f'));
//=> 'g'
console.log(base.store.get());
//=> {name: 'app', data: {a: 'b', c: 'd', e: {f: 'g' }}}
console.log(base.store.data);
//=> {a: 'b', c: 'd', e: {f: 'g'}}plugin params
name{String}: Store name.options{Object}cwd{String}: Current working directory for storage. If not defined, the user home directory is used, based on OS. This is the only option currently, other may be added in the future.indent{Number}: Number passed toJSON.stringifywhen saving the data. Defaults to2ifnullorundefined
methods
.store.set
Assign value to key and save to disk. Can be a key-value pair or an object.
Params
key{String}val{any}: The value to save tokey. Must be a valid JSON type: String, Number, Array or Object.returns{Object}Store: for chaining
Example
// key, value
base.store.set('a', 'b');
//=> {a: 'b'}
// extend the store with an object
base.store.set({a: 'b'});
//=> {a: 'b'}
// extend the the given value
base.store.set('a', {b: 'c'});
base.store.set('a', {d: 'e'}, true);
//=> {a: {b 'c', d: 'e'}}
// overwrite the the given value
base.store.set('a', {b: 'c'});
base.store.set('a', {d: 'e'});
//=> {d: 'e'}.store.union
Add or append an array of unique values to the given key.
Params
key{String}returns{any}: The array to add or append forkey.
Example
base.store.union('a', ['a']);
base.store.union('a', ['b']);
base.store.union('a', ['c']);
base.store.get('a');
//=> ['a', 'b', 'c'].store.get
Get the stored value of key, or return the entire store if no key is defined.
Params
key{String}returns{any}: The value to store forkey.
Example
base.store.set('a', {b: 'c'});
base.store.get('a');
//=> {b: 'c'}
base.store.get();
//=> {b: 'c'}.store.has
Returns true if the specified key has truthy value.
Params
key{String}returns{Boolean}: Returns true ifkeyhas
Example
base.store.set('a', 'b');
base.store.set('c', null);
base.store.has('a'); //=> true
base.store.has('c'); //=> false
base.store.has('d'); //=> false.store.hasOwn
Returns true if the specified key exists.
Params
key{String}returns{Boolean}: Returns true ifkeyexists
Example
base.store.set('a', 'b');
base.store.set('b', false);
base.store.set('c', null);
base.store.set('d', true);
base.store.hasOwn('a'); //=> true
base.store.hasOwn('b'); //=> true
base.store.hasOwn('c'); //=> true
base.store.hasOwn('d'); //=> true
base.store.hasOwn('foo'); //=> false.store.save
Persist the store to disk.
Params
dest{String}: Optionally define a different destination than the default path.
Example
base.store.save();.store.del
Delete keys from the store, or delete the entire store if no keys are passed. A del event is also emitted for each key deleted.
Note that to delete the entire store you must pass {force: true}
Params
keys{String|Array|Object}: Keys to remove, or options.options{Object}
Example
base.store.del();
// to delete paths outside cwd
base.store.del({force: true});Running tests
Install dev dependencies:
$ npm i -d && npm testContributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on October 24, 2015.