JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 306
  • Score
    100M100P100Q85578F

General purpose JavaScript cache methods.

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 NPM version

General purpose JavaScript cache methods.

Install

Install with npm:

npm i config-cache --save-dev

Usage

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();

## option

Set or get an option.

  • key {String}: The option name.
  • value {*}: The value to set.
  • returns {*|Object}: Returns value if key is supplied, or Cache for chaining when an option is set.
cache.option('a', true)
cache.option('a')
// => true

## set

Assign value to key or return the value of key.

  • key {String}
  • value {*}
  • expand {Boolean}: Resolve template strings with expander
  • returns {Cache}: for 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 getobject to initialize the value as an empty object.

  • key {*}
  • create {Boolean}
  • returns: {*}
cache.set('foo', 'bar');
cache.get('foo');
// => "bar"

## constant

Set a constant on the cache.

  • key {String}
  • value {*}

Example

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

## enabled

Check if key is enabled (truthy).

  • key {String}
  • returns: {Boolean}
cache.enabled('foo')
// => false

cache.enable('foo')
cache.enabled('foo')
// => true

## disabled

Check if key is disabled.

  • key {String}
  • returns: {Boolean}
cache.disabled('foo')
// => true

cache.enable('foo')
cache.disabled('foo')
// => false

## enable

Enable key.

  • key {String}
  • returns {Cache}: for chaining

Example

cache.enable('foo');

## disable

Disable key.

  • key {String}
  • returns {Cache}: for chaining

Example

cache.disable('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 {Cache}: for 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 {Cache}: for 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 {Cache}: for 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 {Cache}: for 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', ...]

## each

Call fn on each property in this.cache.

  • fn {Function}
  • obj {Object}: Optionally pass an object to iterate over.
  • returns {Object}: Resulting object.
cache.each(fn, obj);

## visit

Traverse each own property of this.cache or the given object, recursively calling fn on child objects.

  • obj {Object|Function}: Optionally pass an object.
  • fn {Function}
  • returns {Object}: Return the resulting object.
cache.visit(obj, fn);

## process

Methods for reading data files, processing template strings and extending the cache.data object.

  • lookup {*}: Any value to process, usually strings with a cache template, like <%= foo %> or ${foo}.
  • opts {*}: Options to pass to Lo-Dash _.template.

Use expander to recursively expand template strings into their resolved values.

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 {Cache}: for 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}: If true,
  • returns {Cache}: for 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'}}

## omit

Methods for clearing the cache, removing or reseting specific values on the cache.

  • returns {Cache}: for chaining

Omit properties and their from the cache.

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 August 16, 2014.