lodash-namespace

1.0.0 • Public • Published

lodash-namespace

NPM version build status Test coverage

A lodash mixin for namespacing objects

This module has a very simple purpose, which is to namespace an object at varying

Install

$ npm install --save lodash-namespace

Usage

var _ = require('lodash-namespace')();
 
// or, providing your own lodash object
var _ = require('lodash-namespace')(require('lodash'));
 
var myObj = {};
 
var myNamespace = _.namespace(myObj, 'hello.world');
//=> {}
console.log(myObj);
//=> {hello: {world: {}}}
 
console.log(myObj.hello.world === myNamespace);
//=> true
 
// Or, you can use it to namespace lodash itself, or a wrapped object
 
var myNamespace = _(myObj).namespace('hello.world');
//=> {}
console.log(myObj);
//=> {hello: {world: {}}}
 
var myNamespace = _.namespace('hello.world');
//=> {}
 
console.log(_.hello);
//=> {world: {}}

API

_.namespace(obj, path);

If obj is not provided, it will use either lodash itself, or if it's a wrapped object, it will use that object.

path can be any value that you would be able to pass to get or set.

License

MIT © Nate Cavanaugh

Readme

Keywords

none

Package Sidebar

Install

npm i lodash-namespace

Weekly Downloads

4

Version

1.0.0

License

MIT

Last publish

Collaborators

  • natecavanaugh