🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

namespace-data

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

namespace-data

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

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

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.

Keywords

array

FAQs

Package last updated on 19 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts