JSPM

namespace-data

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

Read data files and extend the data from each onto an object or objects named using the given string or [propstring].

Package Exports

  • namespace-data

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 (namespace-data) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

namespace-data NPM version

Read data files and extend the data from each onto an object or objects named using the given string or [propstring].

Install

Install with npm:

npm i namespace-data --save-dev

Usage

var namespace = require('namespace-data');
console.log(namespace(':basename', 'package.json'));
//=> {"package": {"name": "namespace-data", "version": "0.1.0" ...}}

API

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.

Examples

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}

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on July 19, 2014.