gracepull

1.1.3 • Public • Published

A smarter way to extract nested JavaScript properties.

Build Status

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'

Readme

Keywords

none

Package Sidebar

Install

npm i gracepull

Weekly Downloads

1

Version

1.1.3

License

ISC

Last publish

Collaborators

  • whirlwin