js-select-from-object
v0.0.1
Published
A JS util to select a property from an object, without throwing errors.
Downloads
1
Maintainers
Readme
js-select-from-object
A JS util to select a property from an object, and if it doesn't exist, return a default value, instead of throwing an error or returning an undefined value.
Installation
To start using this library, first install the package:
npm install js-select-from-object --save
Usage
An example of how it can be used:
import select from 'js-select-from-object';
const o = {
foo: 'bar',
xxx: {
yyy: 'zzz'
}
};
select(o, 'foo', 'wut?'); // => returns 'bar'
select(o, 'xxx.yyy', 'wut?'); // => returns 'zzz'
select(o, 'aaa.bbb'); // => returns null
select(o, 'aaa.bbb', 'wut?'); // => returns 'wut?'
Todo
- Allow for selection of arrays within objects