1.0.3 • Published 7 years ago

@hexelnet/get v1.0.3

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
7 years ago

#get

get nested property in a safe way with the option to provide an optional value

##Examples

const get = require('@hexelnet/get')
//Or
import get from '@hexelnet/get'

const bigDataObject ={
  user: {
    post: [
       { 
         title: 'This is a post',
         comments: ['Hello', 'Fluffykins'] 
       }
    ]
  }
}

get(bigDataObject, 'user.posts.0.comments') // ['Hello', 'Fluffykins']

/**
 * When an property doesn't exist
 */
get(bigDataObject, 'user.posts.2.comments') // null

/**
 * When an property doesn't exist and there's a default value
 */
get(bigDataObject, 'user.posts.2.comments', 'No comments found') // 'No comments found'

##Params:

@param {Object} Object to travel @param {Array|string} path Properties @param {any} Optional default value when not found (Null by default)

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago