Home

Awesome

plasma-cache NPM version

Object cache for Plasma.

Install

Install with npm

$ npm i plasma-cache --save

Install with bower

$ bower install plasma-cache --save

Usage

var PlasmaCache = require('plasma-cache');
var cache = new PlasmaCache();

API

PlasmaCache

Initialize a new PlasmaCache.

.plasma

Extend the data object with the value returned by plasma.

See the plasma documentation for all available options.

Params

Example

cache
  .plasma({foo: 'bar'}, {baz: 'quux'});
  .plasma({fez: 'bang'});

.dataLoader

Register a dataLoader that will read and load data from files with the given ext.

Params

Example

var fs = require('fs');
var yaml = require('js-yaml');

plasma.dataLoader('yml', function (fp) {
  var str = fs.readFileSync(fp, 'utf8');
  return yaml.safeLoad(str);
});

.process

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

Params

Example

cache.process({a: '<%= b %>', b: 'c'});
//=> {a: 'c', b: 'c'}

.flattenData

If a data property is on the given data object (e.g. data.data, like when files named data.json or data.yml are used), data.data is flattened to just data

Params

.extendData

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

Example

cache
  .extendData({foo: 'bar'}, {baz: 'quux'});
  .extendData({fez: 'bang'});

.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.

Params

Example

cache
  .data({a: 'b'})
  .data({c: 'd'});

console.log(cache);
//=> {data: {a: 'b', c: 'd'}}

cache.data('*.{json,yml}');
// or
cache.data('package.json');
//=> {name: 'plasma-cache', ...}

// process config templates
cache.data({a: '<%= b %>', b: 'z'})
//=> {data: {a: 'z', b: 'z'}}

Related projects

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

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

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


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