Skip to content

🔥 Library for accessing arbitrarily nested, possibly nullable properties on a JavaScript object or array.

License

Notifications You must be signed in to change notification settings

jalbertsr/deepdrain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deepdrain

npm Travis npm GitHub code size in bytes

deep is a utility function for traversing properties on objects and arrays.

If an intermediate property is either null or undefined, it is instead returned. The purpose of this function is to simplify extracting properties from a chain of maybe-typed properties.

This module exists as a stop-gap solution because JavaScript does not currently support optional chaining.

Simpler, smaller and faster than lodash/get , facebook's idx and rambda methods. Also f*ck underscore/propertyOf.

Install

npm
npm install deepdrain 
yarn
yarn add deepdrain

Description

deep(obj, path, defaultValue)

obj: Object | Array
path: Array
defaultValue: any

Example

var deep = require('deepdrain')

var obj = {
  animal: {
    cat: ['meow', 'miau', 'nya-ong', 'meu'],
    dog: 'woof'
  }
}

deep(obj, ['animal', 'cat', '2'])
// nya-ong

deep(obj, ['animal', 'age'], 5)
// 5

About

🔥 Library for accessing arbitrarily nested, possibly nullable properties on a JavaScript object or array.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published