JSPM

  • Created
  • Published
  • Downloads 43302
  • Score
    100M100P100Q135907F
  • License

Easily get, set and persist config data.

Package Exports

  • data-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 (data-store) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

data-store Build Status NPM version

Easily get, set and persist config data.

Install

Install with npm

npm i data-store --save

Usage example

var Store = require('./');
// 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' } } }

API

Store

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'

.set

Assign value to key and save to disk. Can be a key-value pair or an object.

Params

  • key {String}
  • val _{}_*: The value to save to key. Must be a valid JSON type: String, Number, Array or Object.
  • returns {Object} Store: for chaining

Example

// 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'}

.get

Get the stored value of key, or return the entire store if no key is defined.

Params

  • key {String}
  • returns _{}_*: The value to store for key.

Example

store.set('a', {b: 'c'});
store.get('a');
//=> {b: 'c'}

store.get();
//=> {b: 'c'}

.has

Returns true if the specified key has.

Params

  • key {String}
  • returns {Boolean}: Returns true if key has

Example

store.set('a', 'b');
store.has('a');
//=> true

.save

Persist the store to disk.

Params

  • dest {String}: Optionally define an alternate destination file path.

Example

store.save();

.omit

Delete a property or array of properties from the store then re-save the store.

Params

  • key {String|Array}: The key(s) to omit from the store
  • returns {Object} Store: for chaining

Example

// string
store.omit('a');

// array
store.omit(['a', 'b']);

.del

Delete the entire store.

Note that you must pass {force: true} to delete paths outside the current working directory.

Example

store.del();

// to delete paths outside cwd
store.del({force: true});
  • config-cache: General purpose JavaScript object storage methods.
  • cache-base: Generic object cache for node.js/javascript projects.
  • get-value: Use property paths ( a.b.c) get a nested value from an object.
  • has-value: Returns true if a value exists, false if empty. Works with deeply nested values using… more
  • map-cache: Basic cache object for storing key-value pairs.
  • option-cache: Simple API for managing options in JavaScript applications.
  • set-value: Create nested values and any intermediaries using dot notation ('a.b.c') paths.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Running tests

Install dev dependencies:

npm i -d && npm test

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on May 07, 2015.