A lodash mixin for namespacing objects
This module has a very simple purpose, which is to namespace an object at varying
$ npm install --save lodash-namespace
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: {}}
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.
MIT © Nate Cavanaugh