Skip to content
/ getIn Public

Get value from object by path. Undefined-safe and accepts default value

License

Notifications You must be signed in to change notification settings

mzvonar/getIn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Get value from object by path. Undefined-safe and accepts default value

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •