0.0.2 • Published 6 months ago

property-value v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

property-value

npm package Build Status Downloads Issues Code Coverage

Module to get property value with property path

Install

npm install property-value

Usage

import { getPropertyValue } from 'property-value';

interface Person {
  age: number;
  name: {
    first: string;
    middle?: string;
    last: string;
  };
}

const p: Person = {
  age: 15,
  name: {
    first: 'Yuyi',
    last: 'Xue',
  },
};

const firstName = getPropertyValue(p, 'name.first');
//=> 'Yuyi'

API

getPropertyValue<T, P>(obj: T, path: P)

obj

Type: object

The source object

path

Type: string

The path of the property to be received