| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Plugin for getting and persisting config values with your base-methods application. Adds a 'store' object that exposes all of the methods from the data-store library. Also now supports sub-stores!
You might also be interested in base-data.
Install with npm:
$ npm install base-store --saveAdds store methods for doing things like this:
app.store.set('a', 'z'); // DOES persist
console.log(app.store.get('a'));
//=> 'z';Add a .store method to your base application:
var store = require('base-store');
var Base = require('base');
var base = new Base();
// store `name` is required
base.use(store('foo'));
// optionally define a cwd to use for persisting the store
// default cwd is `~/data-store/`
base.use(store('foo', {cwd: 'a/b/c'}));example usage
base.store
.set('a', 'b')
.set({c: 'd'})
.set('e.f', 'g')
console.log(base.store.get('e.f'));
//=> 'g'
console.log(base.store.data);
//=> {a: 'b', c: 'd', e: {f: 'g'}}A sub-store is a custom store that is persisted to its own file in a sub-folder of its "parent" store.
Create a sub-store
app.store.create('foo');
// creates an instance of store on `app.store.foo`
app.store.foo.set('a', 'b');
app.store.foo.get('a');
//=> 'b'Sub-store data is also persisted to a property on the "parent" store:
// set data on a sub-store
app.store.foo.set('a', 'b');
// get the value from parent store
app.store.get('foo.a');
//=> 'b'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 to JSON.stringify when saving the data. Defaults to 2 if null or undefined
Assign value to key and save to disk. Can be a key-value pair or an object.
Params
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'}Add or append an array of unique values to the given key.
Params
Example
base.store.union('a', ['a']);
base.store.union('a', ['b']);
base.store.union('a', ['c']);
base.store.get('a');
//=> ['a', 'b', 'c']Get the stored value of key, or return the entire store if no key is defined.
Params
Example
base.store.set('a', {b: 'c'});
base.store.get('a');
//=> {b: 'c'}
base.store.get();
//=> {b: 'c'}Returns true if the specified key has truthy value.
Params
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'); //=> falseReturns true if the specified key exists.
Params
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'); //=> falsePersist the store to disk.
Params
Example
base.store.save();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
Example
base.store.del();
// to delete paths outside cwd
base.store.del({force: true});v0.3.1
v0.3.0
Other plugins for extending your base application:
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docsOr, if verb is installed globally:
$ verbInstall dev dependencies:
$ npm install -d && npm testJon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on May 19, 2016.
| Back | FazBrowse Home | New Git URL |