@jsier/deep-value
A simple, efficient and lightweight package without external dependencies intended for safely resolving deep value of an object or array by providing path to the targeted property. deepValue
is built with TypeScript (preserves full compatibility with pure JavaScript) and is easy to use.
Getting Started
$ npm install @jsier/deep-value --save
Usage
deepValue
as first argument expects object or array as a source. Second argument should be string representing the path to the targeted property.
Non-existing properties or invalid paths provided will return undefined as the result.
import { deepValue } from '@jsier/deep-value';
const employee = {
name: 'Gia',
age: 44,
gender: null,
skills: [['ts', 'js'], ['en', 'fr']],
children: [{name: 'Mia'}]
};
deepValue(employee, 'name');
deepValue(employee, 'gender');
deepValue(employee, 'skill[0]');
deepValue(employee, 'skill[0][1]');
deepValue(employee, 'children[0].name');
deepValue(employee.children, '[0].name');
deepValue(employee.children, '[0].gender');
Support
All suggestions and improvements are welcomed and appreciated.
License
The MIT License.