config-cache
General purpose JavaScript object storage methods.
Last updated 10 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install config-cache 
SYNC missed versions from official npm registry.

config-cache NPM version Build Status

General purpose JavaScript object storage methods.

Breaking changes in 5.0!

Major breaking changes were made in 5.0!

In an effort to simplify the library, the following methods were removed:

  • clone: use clone-deep, example: var obj = cloneDeep(config.cache)
  • keys: use Object.keys(config.cache)
  • omit: use .del()
  • exists: use config.cache.hasOwnProperty() or has-value
  • has: use config.cache.hasownProperty() or has-value
  • hasOwn: use config.cache.hasOwnProperty() or has-value

The following data methods were also removed, use plasma-cacheif you need these methods:

  • data
  • process
  • plasma
  • extendData

Install

Install with npm

$ npm i config-cache --save

Usage

var Config = require('config-cache');
var config = new Config();

API

Config

Initialize a new Config, optionally passing an object to initialize with.

Params

  • cache {Object}

Example

var config = new Config();

.mixin

Static method for mixing Config prototype properties onto obj.

Params

  • obj {Object}
  • returns {Object}

Example

function App() {
  Config.call(this);
}
Config.mixin(App.prototype);

.set

Assign value to key or return the value of key.

Params

  • key {String}
  • value {*}
  • returns {Object} Config: to enable chaining

Example

config.set(key, value);

.get

Return the stored value of key. Dot notation may be used to get nested property values.

Params

  • key {*}
  • escape {Boolean}
  • returns {*}

Example

config.set('foo', 'bar');
config.get('foo');
// => "bar"

// also takes an array or list of property paths
config.set({data: {name: 'Jon'}})
config.get('data', 'name');
//=> 'Jon'

.constant

Create a constant (getter/setter) for setting and getting values on the given namespace or this.cache.

Params

  • key {String}
  • value {*}

Example

config.constant('site.title', 'Foo');

.union

Add values to an array on the cache.

  • returns {Object} Config: to enable chaining

Example

// config.cache['foo'] => ['a.hbs', 'b.hbs']
config
  .union('foo', ['b.hbs', 'c.hbs'], ['d.hbs']);
  .union('foo', ['e.hbs', 'f.hbs']);

// config.cache['foo'] => ['a.hbs', 'b.hbs', 'c.hbs', 'd.hbs', 'e.hbs', 'f.hbs']

.extend

Extend the cache with the given object. This method is chainable.

Or define the property to extend:

  • returns {Object} Config: to enable chaining

Examples

config
  .extend({foo: 'bar'}, {baz: 'quux'});
  .extend({fez: 'bang'});
config
  // extend `cache.a`
  .extend('a', {foo: 'bar'}, {baz: 'quux'})
  // extend `cache.b`
  .extend('b', {fez: 'bang'})
  // extend `cache.a.b.c`
  .extend('a.b.c', {fez: 'bang'});

.del

Remove keys from the cache. If no value is specified the entire cache is reset.

Example

config.del();

Usage Examples

.set

If expand: true is defined on the options, the value will be set using [expander].

Examples:

// as a key-value pair
config.set('a', {b: 'c'});

// or as an object
config.set({a: {b: 'c'}});

// chaining is possible
cache
  .set({a: {b: 'c'}})
  .set('d', 'e');

Expand template strings with expander:

config.set('a', {b: '${c}', c: 'd'}, true);

Visit the [expander] docs for more info.

Related

  • cache-base: Generic object cache for node.js/javascript projects.
  • engine-cache: express.js inspired template-engine manager.
  • get-value: Use property paths (a.b.c) to 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
  • helper-cache: Easily register and get helper functions to be passed to any template engine or node.js… more
  • loader-cache: Register loader functions that dynamically read, parse or otherwise transform file contents when the name… more
  • map-cache: Basic cache object for storing key-value pairs.
  • option-cache: Simple API for managing options in JavaScript applications.
  • plasma-cache: Object cache for [Plasma].
  • parser-cache: Cache and load parsers, similiar to consolidate.js engines.
  • 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 © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on June 13, 2015.

Current Tags

  • 6.0.1                                ...           latest (9 years ago)

32 Versions

  • 6.0.1                                ...           9 years ago
  • 6.0.0                                ...           9 years ago
  • 5.0.1                                ...           9 years ago
  • 5.0.0                                ...           9 years ago
  • 4.0.0                                ...           10 years ago
  • 3.1.0                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 2.0.0                                ...           10 years ago
  • 1.3.2                                ...           10 years ago
  • 1.3.1                                ...           10 years ago
  • 1.3.0                                ...           10 years ago
  • 1.2.0                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.5.0                                ...           10 years ago
  • 0.4.0                                ...           10 years ago
  • 0.3.4                                ...           10 years ago
  • 0.3.3                                ...           10 years ago
  • 0.3.2                                ...           10 years ago
  • 0.3.1                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.3                                ...           10 years ago
  • 0.2.2                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.7                                ...           10 years ago
  • 0.1.6                                ...           10 years ago
  • 0.1.5                                ...           10 years ago
  • 0.1.4                                ...           10 years ago
  • 0.1.3                                ...           10 years ago
  • 0.1.2                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (15)
Dev Dependencies (3)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE