property-value
v0.0.2
Published
A template for creating npm packages using TypeScript and VSCode
Downloads
4
Maintainers
Readme
property-value
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