0.0.11 • Published 6 years ago
@mzvonar/getin v0.0.11
getIn
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