Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
data-store
Advanced tools
Easily get, set and persist config data.
Install with npm
$ npm i data-store --save
var Store = require('data-store');
// default cwd is `~/data-store/`
var store = new Store('app', {cwd: 'actual'});
store
.set('a', 'b')
.set('c.d', {e: 'f'})
.set('c.d', {g: 'h'});
console.log(store.get('c.d'));
//=> { e: 'f', g: 'h' }
console.log(store.get());
//=> { name: 'app', data: { a: 'b', c: { d: { e: 'f', g: 'h' } } } }
console.log(store.data);
//=> { a: 'b', c: { d: { e: 'f', g: 'h' } } }
Initialize a new Store
with the given name
and options
.
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.Example
var store = new Store('abc');
//=> '~/data-store/a.json'
var store = new Store('abc', {cwd: 'test/fixtures'});
//=> './test/fixtures/abc.json'
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 to key
. Must be a valid JSON type: String, Number, Array or Object.returns
{Object} Store
: for chainingExample
// key, value
store.set('a', 'b');
//=> {a: 'b'}
// extend the store with an object
store.set({a: 'b'});
//=> {a: 'b'}
// extend the the given value
store.set('a', {b: 'c'});
store.set('a', {d: 'e'}, true);
//=> {a: {b 'c', d: 'e'}}
// overwrite the the given value
store.set('a', {b: 'c'});
store.set('a', {d: 'e'});
//=> {d: 'e'}
Assign or concat an array of unique values to the given key
.
Params
key
{String}returns
{any}: The value to store for key
.Example
store.set('a', {b: 'c'});
store.get('a');
//=> {b: 'c'}
store.get();
//=> {b: 'c'}
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 for key
.Example
store.set('a', {b: 'c'});
store.get('a');
//=> {b: 'c'}
store.get();
//=> {b: 'c'}
Returns true
if the specified key
has.
Params
key
{String}returns
{Boolean}: Returns true if key
hasExample
store.set('a', 'b');
store.has('a');
//=> true
Persist the store to disk.
Params
dest
{String}: Optionally define an alternate destination file path.Example
store.save();
Delete keys
from the store, or delete the entire store if no keys are passed.
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
store.del();
// to delete paths outside cwd
store.del({force: true});
a.b.c
) to get a nested value from an object.'a.b.c'
) paths.Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Install dev dependencies:
$ npm i -d && npm test
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on July 05, 2015.
[0.8.0] - 2015-07-05
union
methodFAQs
Easily persist and load config data. No dependencies.
The npm package data-store receives a total of 23,360 weekly downloads. As such, data-store popularity was classified as popular.
We found that data-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.