1.0.0 • Published 9 years ago

lodash-namespace v1.0.0

Weekly downloads
31
License
MIT
Repository
github
Last release
9 years ago

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