2.0.1 • Published 9 years ago
deeppi v2.0.1
deeppi
Set and get values on objects via dot-notation strings or array notation.
Example
var deep = require('deeppi');
var obj = {
foo: {
bar: 'baz'
qux: ['quix']
}
};
// Get
console.log(deep(obj, 'foo.bar'));
// => "baz"
// Get
console.log(deep(obj, 'foo.qux[0]'));
// => "quix"
// Set
deep(obj, 'foo.bar', 'hello');
console.log(obj.foo.bar);
// => "hello"
// Set
deep(obj, 'foo.qux[1]', 'baz');
console.log(obj.foo.qux[1]);
// => "baz"API
deep(object, path, value)
Where path is a dot-notation string foo.bar or array notation string foo[0].
- If
valueis passed it will be set on the path. - Set
deep.p = trueif you want non-existent paths to be initialized. - If you want to unset (or delete), pass
undefinedas thevalue.
Installation
With npm do:
npm install deeppiNote
There's a dozen modules like this on npm. This is a fork from @acstll's deep-get-set module, with additional array notation access
License
MIT