Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
data-store
Advanced tools
Easily get, set and persist config data.
Install with npm:
$ npm install data-store --save
// default cwd is `~/data-store/`
var store = require('data-store')('app', {cwd: 'actual'});
store
.set('a', 'b')
.set({c: 'd'})
.set('e.f', 'g')
console.log(store.get('e.f'));
//=> 'g'
console.log(store.get());
//=> {name: 'app', data: {a: 'b', c: 'd', e: {f: 'g' }}}
console.log(store.data);
//=> {a: 'b', c: 'd', e: {f: 'g'}}
Initialize a new Store
with the given name
and options
.
Params
name
{String}: Store name to use for the basename of the .json
file.options
{Object}options.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.options.indent
{Number}: Number passed to JSON.stringify
when saving the data. Defaults to 2
if null
or undefined
Example
var store = require('data-store')('abc');
//=> '~/data-store/a.json'
var store = require('data-store')('abc', {
cwd: 'test/fixtures'
});
//=> './test/fixtures/abc.json'
Create a namespaced "sub-store" that persists data to its file in a sub-folder of the same directory as the "parent" store.
Params
name
{String}: The name of the sub-store.options
{Object}returns
{Object}: Returns the sub-store instance.Example
store.create('foo');
store.foo.set('a', 'b');
console.log(store.foo.get('a'));
//=> 'b'
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'}
Add or append an array of unique values to the given key
.
Params
key
{String}returns
{any}: The array to add or append for key
.Example
store.union('a', ['a']);
store.union('a', ['b']);
store.union('a', ['c']);
store.get('a');
//=> ['a', '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 truthy value.
Params
key
{String}returns
{Boolean}: Returns true if key
hasExample
store.set('a', 'b');
store.set('c', null);
store.has('a'); //=> true
store.has('c'); //=> false
store.has('d'); //=> false
Returns true
if the specified key
exists.
Params
key
{String}returns
{Boolean}: Returns true if key
existsExample
store.set('a', 'b');
store.set('b', false);
store.set('c', null);
store.set('d', true);
store.hasOwn('a'); //=> true
store.hasOwn('b'); //=> true
store.hasOwn('c'); //=> true
store.hasOwn('d'); //=> true
store.hasOwn('foo'); //=> false
Persist the store to disk.
Params
dest
{String}: Optionally define an alternate destination file path.Example
store.save();
Clear in-memory cache.
Example
store.clear();
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
store.del();
// to delete paths outside cwd
store.del({force: true});
Define a non-enumerable property on the instance.
Params
key
{String}value
{any}returns
{Object}: Returns the instance for chaining.get
, set
, del
, and has
methods for node.js/javascript projects. | homepage a.b.c
) to get a nested value from an object. | homepage'a.b.c'
) paths. | homepagePull 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 docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb, v0.9.0, on March 02, 2016.
[0.15.5] - 2016-03-02
FAQs
Easily persist and load config data. No dependencies.
The npm package data-store receives a total of 39,877 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.