@mzvonar/getin

0.0.11 • Public • Published

getIn Build Status Coverage Status npm version

Get value from object by path. Path can be string or array (e.g. ['user', 'profile', 'gender']).
If any value in path is undefined then undefined is returned or defaultValue if provided.

Installation

npm install @mzvonar/getin

Usage

const getIn = require('@mzvonar/getin');
  
const context = {
    user: {
        profile: {
            gender: 'female'
        }
    }
};
  
const gender = getIn(context, ['user', 'profile', 'gender']);

gender is female

const country = getIn(context, ['user', 'address', 'country']);

country is undefined

const verified = getIn(context, ['user', 'profile', 'verified'], false);

verified is false

Tests

npm test

Package Sidebar

Install

npm i @mzvonar/getin

Weekly Downloads

5

Version

0.0.11

License

MIT

Unpacked Size

4.14 kB

Total Files

4

Last publish

Collaborators

  • mzvonar