node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Build Status

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.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' 


$ npm install --save-dev object-locator
  • Implemented via ES6 proxy, so it it compatible with node 6 >