Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

delve

hughfdjackson1.7kBSD0.3.2

Delve recursively into a value to retrieve a property; without erroring.

property, accessor, utility, sugar

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.