0.1.0 • Published 7 years ago

object-keypath v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

object-keypath

Return a string representing the keypath to a key of a specified value.

API

var getPath = require('object-keypath');

var person = {
  name: 'estrattonbailey',
  meta: {
    occupation: {
      title: 'Developer',
      company: 'Barrel'
    },
    other: {
      title: 'Duplicate Key'
    }
  }
}

getPath(person, name, 'estrattonbailey')
// returns `name`

getPath(person, title, 'Developer')
// returns `meta.occupation.title`

getPath(person, title, 'Duplicate Key')
// returns `meta.other.title`

MIT License