diggs
A lightweight utility to safely dig into nested properties – because safety is number one priority.
Installation
To install diggs
:
npm install --save diggs
That's it!
diggs
?
Why diggs allows you to access deeply nested properties without having to worry about undefined properties, null, or TypeErrors.
// Uncaught TypeError: Cannot read property 'foo' of null// Uncaught TypeError: Cannot read property 'foo' of undefined
Examples
; let data = a: b: c: 'foo' d: 'bar' z: null // retrieve deeply nested properties // => ['foo', { d: 'bar' }] // even array items // => 'bar' // returns undefined instead of throwing TypeErrors // => undefined // returns a default value // => false
API
get(object, path, defaultValue)
Returns the value at the specified path
of object
. If the value is not found (undefined
), defaultValue will be returned instead.
Arguments
object
(Object): The object to querypath
(String): The path of the property to get- [
defaultValue
] (Any): The value returned forundefined
values
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
- ...
- Profit
License
MIT