0.2.0 • Published 7 years ago
key.path v0.2.0
key.path
Performant micro library for managing values for the derived property identified by a given key path.
Install
Install with npm:
$ npm install key.path --save
Install with yarn
$ yarn add key.path --save
Usage
String based key path:
import { valueForKeyPath } from 'key.path'
const post = {title: 'post', author: {name: 'Stephen King'}}
valueForKeyPath('author.name', post)
//=> Stephen King
Array based key path:
Optionally pass the key as an array (this is useful when you need to dynamically build up the property name)
const post = {title: 'post', author: {name: 'Stephen King'}}
valueForKeyPath(['author', 'name'], post)
//=> Stephen King
License
Copyright © 2017, Patrick Kempff. Released under the MIT license.