Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

object-value-path

m31271n2MIT1.1.0

readme

object-value-path

Prerequisite

  • Node >= 6.0.0
  • the value you wanna search for is unique.

Installation

npm install -S object-value-path

Usage

Suppose the Object is:

const object = [
  {
    uuid: '123e4567-e89b-12d3-a456-426655440007',
    name: 'merlin',
    children: [
      {
        uuid: '123e4567-e89b-12d3-a456-426655440002',
        name: 'berlin',
        children: [
          {
            uuid: '123e4567-e89b-12d3-a456-426655440001',
            name: 'julia',
          }
        ]
      }
    ]
  },
  {
    uuid: '123e4567-e89b-12d3-a456-426655440012',
    name: 'spike',
    children: [
      {
        uuid: '123e4567-e89b-12d3-a456-426655440009',
        name: 'jet',
      }
    ]
  }
]

Calculate value path:

const ovp = require('object-value-path');

ovp(object, '123e4567-e89b-12d3-a456-426655440001');
// [ '0', 'children', '0', 'children', '0', 'uuid' ]

Todo

Rewrite with more robust backtrack algorithm.

License

MIT