1.1.0 • Published 8 years ago

object-value-path v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

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.

Related packages

License

MIT