@jsier/deep-value
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

@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'); // -> 'Gia'
deepValue(employee, 'gender'); // -> null
deepValue(employee, 'skill[0]'); // -> ['ts', 'js']
deepValue(employee, 'skill[0][1]'); // -> 'js'
deepValue(employee, 'children[0].name'); // -> 'Mia'
deepValue(employee.children, '[0].name'); // -> 'Mia'
deepValue(employee.children, '[0].gender'); // -> undefined

Support

All suggestions and improvements are welcomed and appreciated.

License

The MIT License.

Package Sidebar

Install

npm i @jsier/deep-value

Weekly Downloads

3

Version

1.2.1

License

MIT

Unpacked Size

4.11 kB

Total Files

5

Last publish

Collaborators

  • seidme