Package Exports
- config-cache
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 (config-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
config-cache 
General purpose JavaScript object storage methods.
Install
Install with npm:
npm i config-cache --save-devUsage
var Config = require('config-cache');
var config = new Config();API
Cache
Initialize a new Cache
obj{Object}: Optionally pass an object to initialize with.
var cache = new Cache();.set
Assign value to key or return the value of key.
key{String}value{*}expand{Boolean}: Resolve template strings with expanderreturns{Object}Cache: to enable chaining
cache.set(key, value);If expand is defined as true, the value will be set using expander.
Examples:
// as a key-value pair
cache.set('a', {b: 'c'});
// or as an object
cache.set({a: {b: 'c'}});
// chaining is possible
cache
.set({a: {b: 'c'}})
.set('d', 'e');Expand template strings with expander:
cache.set('a', {b: '${c}', c: 'd'}, true);Visit the expander docs for more info.
.get
Return the stored value of key. If the value does not exist on the cache, you may pass true as a second parameter to tell [set-object] to initialize the value as an empty object.
key{*}create{Boolean}returns: {*}
cache.set('foo', 'bar');
cache.get('foo');
// => "bar"
// also takes an array or list of property paths
cache.set({data: {name: 'Jon'}})
cache.get('data', 'name');
//=> 'Jon'.constant
Set a constant on the cache.
key{String}value{*}
Example
cache.constant('site.title', 'Foo');.exists
Return true if the element exists. Dot notation may be used for nested properties.
key{String}returns: {Boolean}
Example
cache.exists('author.name');
//=> true.union
Add values to an array on the cache. This method is chainable.
returns{Object}Cache: to enable chaining
Example
// config.cache['foo'] => ['a.hbs', 'b.hbs']
cache
.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'].defaults
Extend the cache with the given object. This method is chainable.
returns{Object}Cache: to enable chaining
Example
cache
.defaults({foo: 'bar'}, {baz: 'quux'});
.defaults({fez: 'bang'});Or define the property to defaults:
cache
// defaults `cache.a`
.defaults('a', {foo: 'bar'}, {baz: 'quux'})
// defaults `cache.b`
.defaults('b', {fez: 'bang'})
// defaults `cache.a.b.c`
.defaults('a.b.c', {fez: 'bang'});.extend
Extend the cache with the given object. This method is chainable.
returns{Object}Cache: to enable chaining
Example
cache
.extend({foo: 'bar'}, {baz: 'quux'});
.extend({fez: 'bang'});Or define the property to extend:
cache
// 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'});.merge
Extend the cache with the given object. This method is chainable.
returns{Object}Cache: to enable chaining
Example
cache
.merge({foo: 'bar'}, {baz: 'quux'});
.merge({fez: 'bang'});.keys
Return the keys on this.cache.
returns: {Boolean}
cache.keys();.hasOwn
Return true if key is an own, enumerable property of this.cache or the given obj.
key{String}obj{Object}: Optionally pass an object to check.returns: {Boolean}
cache.hasOwn([key]);.clone
Clone the given obj or cache.
obj{Object}: Optionally pass an object to clone.returns: {Boolean}
cache.clone();.methods
Return methods on this.cache or the given obj.
obj{Object}returns: {Array}
cache.methods('foo')
//=> ['set', 'get', 'enable', ...]Data methods
Methods for reading data files, processing template strings and extending the
cache.dataobject.
.process
Use expander to recursively expand template strings into their resolved values.
lookup{*}: Any value to process, usually strings with a cache template, like<%= foo %>or${foo}.opts{*}: Options to pass to Lo-Dash_.template.
Example
cache.process({a: '<%= b %>', b: 'c'});
//=> {a: 'c', b: 'c'}.extendData
Extend the cache.data object with the given data. This method is chainable.
returns{Object}Cache: to enable chaining
Example
cache
.extendData({foo: 'bar'}, {baz: 'quux'});
.extendData({fez: 'bang'});.plasma
Extend the data object with the value returned by plasma.
data{Object|String|Array}: File path(s), glob pattern, or object of data.options{Object}: Options to pass to plasma.
Example:
cache
.plasma({foo: 'bar'}, {baz: 'quux'});
.plasma({fez: 'bang'});See the plasma documentation for all available options.
.namespace
Expects file path(s) or glob pattern(s) to any JSON or YAML files to be merged onto the data object. Any data files read in by the .namespace() method will extend the data object with an object named after the basename of each file.
patterns{String|Array}: Filepaths or glob patterns.returns: {null}
Example
cache.namespace(['alert.json', 'nav*.json']);The data from each file is namespaced using the name of the file:
{
alert: {},
navbar: {}
}See the plasma documentation for all available options.
.data
Extend the cache.data object with data from a JSON or YAML file, or by passing an object directly - glob patterns or file paths may be used.
values{Object|Array|String}: Values to pass to plasma.process{Boolean}: Iftrue,returns{Object}Cache: to enable chaining
cache
.data({a: 'b'})
.data({c: 'd'});
console.log(config.cache);
//=> {data: {a: 'b', c: 'd'}}When true is passed as the last argumemnt data will
be processed by expander before extending cache.data.
cache.data({a: '<%= b %>', b: 'z'})
//=> {data: {a: 'z', b: 'z'}}Clearing the cache
Methods for clearing the cache, removing or reseting specific values on the cache.
.omit
Omit properties from the cache.
returns{Object}Cache: to enable chaining
Example:
cache
.omit('foo');
.omit('foo', 'bar');
.omit(['foo']);
.omit(['foo', 'bar']);.clear
Remove key from the cache, or if no value is specified the entire cache is reset.
Example:
cache.clear();Author
Jon Schlinkert
Brian Woodward
License
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on November 06, 2014.