Parse js object paths using both dot and bracket notation. Stringify an array of properties into a valid path.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
bower.json
index.js
license
package-lock.json
package.json
readme.md

readme.md

ObjectPath

Join the chat at https://gitter.im/mike-marcacci/objectpath

Build Status

Parse js object paths using both dot and bracket notation. Stringify an array of properties into a valid path.

  • parse JS object reference fragments
  • build JS object reference fragments
  • supports presence of unicode characters
  • supports presence of control characters in key names

Parse a Path

ObjectPath.parse(str)

var ObjectPath = require('objectpath');

ObjectPath.parse('a[1].b.c.d["e"]["f"].g');
// => ['a','1','b','c','d','e','f','g']

Build a Path String

ObjectPath.stringify(arr, [quote=''']);

var ObjectPath = require('objectpath');

ObjectPath.stringify(['a','1','b','c','d','e','f','g']);
// => '[\'a\'][\'1\'][\'b\'][\'c\'][\'d\'][\'e\'][\'f\'][\'g\']'


ObjectPath.stringify(['a','1','b','c','d','e','f','g'],'"');
// => '["a"]["1"]["b"]["c"]["d"]["e"]["f"]["g"]'

Normalize a Path

ObjectPath.normalize(str)

var ObjectPath = require('objectpath');

ObjectPath.normalize('a[1].b.c.d["e"]["f"].g');
// => '["a"]["1"]["b"]["c"]["d"]["e"]["f"]["g"]'