
Read data files and extend the data from each onto an object or objects named using the given string or [propstring].
Install with npm:
npm i namespace-data --save-dev
var namespace = require('namespace-data');
console.log(namespace(':basename', 'package.json'));
//=> {"package": {"name": "namespace-data", "version": "0.1.0" ...}}
namespace(':propstring', [glob], {context: {}});
:propstring A variable, like a template, which will be replaced with the
value of any matching property on the context. You can use any prop strings that
match properties on the context. The default context consists of all the method
names from the node.js path module, (e.g. :basename, :extname, etc.)glob: File path, paths or glob patterns for data files to read.context: Extend the context to enable additional values to be used as propstrings.Read data files and extend the data from each onto an object or objects named using the given string or propstring.
Given you have two JSON files, a.json and b.json, with the following contents:
// a.json
{
"foo": "I'm a.json!"
}
// b.json
{
"bar": "I'm b.json!"
}
propstrings
You can namespace the data from each file onto an object where the object name is
dynamically generated using :propstrings.
data.namespace(':basename', ['a.json', 'b.json']);
//=> '{ "a": {"foo": "I'm a.json!"}, "b": {"bar": "I'm b.json!"} }'
// if a single argument is passed, `basename` is used by default, so this:
data.namespace(['a.json', 'b.json']);
// also results in '{ "a": {"foo": "I'm a.json!"}, "b": {"bar": "I'm b.json!"} }'
Same data but namespaced using :ext (file extension) instead:
data.namespace(':ext', ['a.json', 'b.json']);
{ "json": {"foo": "I'm a.json!", "bar": "I'm b.json!"} }
patterns {*}: Filepaths or glob patterns.return {null}Jon Schlinkert
Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license
This file was generated by verb-cli on July 19, 2014.