object-locator
v1.0.2
Published
Retrieve object inside an object my giving a path to the object, you no need to care for nulls/undefined
Downloads
18
Maintainers
Readme
object-locator
This small lib helps a developer to go directly inside object properties for any given depth and to return the datat
The problem
const obj = {a: {b: {c: 'd'}}};
// get a.b.c - verbose way
if(a && a.b && a.c)
return a.b.c
object-locator solution
const locator = require('object-locator');
const obj = {a: {b: {c: 'd'}}};
// elegant way
locator(obj).a.b.c.getOrElse('bla') // === 'd'
// or for non exist object
locator(obj).a.b.not.exist.getOrElse('bla') // === 'bla'
Install
$ npm install --save-dev object-locator
- Implemented via ES6 proxy, so it it compatible with node 6 >