npm.io
1.0.6 • Published 8 years ago

object-path-resolve

Licence
MIT
Version
1.0.6
Deps
0
Size
148 kB
Vulns
0
Weekly
0
Stars
1

object-path-resolve

A 200b (gzipped) utility function to resolve object properties with string paths

API

resolve(obj: Object, path: String)

Retrieve a value from the obj based on the path (accepts dot and bracket notation)

Usage

import resolve from 'object-path-resolve'

const obj = {
  prop: { name: 'John' },
  arr: [
    'one', 'two', 'three'
  ]
}

resolve(obj, 'prop.name') // => 'John'
resolve(obj, 'prop.age') // => undefined
resolve(obj, 'arr[1]') // => 'two'

License

MIT