object-locator

1.0.2 • Public • Published

object-locator

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'

Install

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

Package Sidebar

Install

npm i object-locator

Weekly Downloads

1

Version

1.0.2

License

SEE LICENSE IN LICENSE.md

Last publish

Collaborators

  • kfiron