gracepull
v1.1.3
Published
A smarter way to extract nested JavaScript properties.
Downloads
8
Readme
A smarter way to extract nested JavaScript properties.
Usage
Syntax
gracepull(extractFn, [fallback])
extractFn
The function used to extract the property.
fallback
The fallback value to be used if the property is absent. Can either be a value or a function returning a value.
Basic example
var gracepull = require('gracepull');
var person = {
address: {
street: {
name: 'Acacia Avenue',
number: 22
}
}
};
var result = gracepull(() => person.address.street.name); // 'Acacia Avenue'
Missing property example
var gracepull = require('gracepull');
var person = {
address: {}
};
var result = gracepull(() => person.address.street.name); // null
Missing property fallback example
var gracepull = require('gracepull');
var person = {
address: {}
};
var result = gracepull(() => person.address.street.name, 'Default Road'); // 'Default Road'