delve
v0.3.2
Published
Delve recursively into a value to retrieve a property; without erroring.
Downloads
2,118
Readme
delve
Delve recursively into a value to retrieve a property; without erroring.
Why
It sucks to have to do if ( obj && obj.prop && obj.prop.secondProp ) { ... }
.
Example
var delve = require('delve')
var o = { x: { y: { z: 'my val' } } }
delve(o, 'x.y') //= { z: 'my val' }
delve(o, 'x.y.z') //= 'my val'
delve(o, 'x.y.z.foo') //= undefined
delve(undefined, 'x.y.z.foo') //= undefined
For more examples, see the tests/delve-test.js
Install
npm
npm install delve
browser
Download src/delve.js, and include it as a script tag.