plasma-cache
Object cache for Plasma.
Install
Install with npm
$ npm i plasma-cache --save
Install with bower
$ bower install plasma-cache --save
Usage
var PlasmaCache = ;var cache = ;
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
data
{Object|String|Array}: File path(s), glob pattern, or object of data.options
{Object}: Options to pass to plasma.
Example
cache ; ;
.dataLoader
Register a dataLoader
that will read and load data from files with the given ext
.
Params
ext
{String}: The extension of files to read.fn
{String}: The loader function
Example
var fs = ;var yaml = ; plasma;
.process
Use expander to recursively expand template strings into their resolved values.
Params
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;//=> {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
data
{Object}returns
{Object}: Flattened object.
.extendData
Extend the cache.data
object with the given data. This
method is chainable.
returns
{Object}PlasmaCache
: to enable chaining
Example
cache ; ;
.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
values
{Object|Array|String}: Values to pass to plasma.process
{Boolean}: Iftrue
is passed as the last argumemnt data willreturns
{Object}PlasmaCache
: to enable chaining
Example
cache dataa: 'b' datac: 'd'; console;//=> {data: {a: 'b', c: 'd'}} cachedata'*.{json,yml}';// orcachedata'package.json';//=> {name: 'plasma-cache', ...} // process config templatescachedataa: '<%= b %>' b: 'z'//=> {data: {a: 'z', b: 'z'}}
Related projects
- config-cache: General purpose JavaScript object storage methods.
- data-store: Easily get, set and persist config data.
- option-cache: Simple API for managing options in JavaScript applications.
- plasma: Load data from globs or files or directly from objects.
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.