objectpath

2.0.0 • Public • Published

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-f"].g');
// => ['a','1','b','c','d','e','f-f','g']

Build a Path String

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

var ObjectPath = require('objectpath');
 
ObjectPath.stringify(['a','1','b','c','d-d','e']);
// => "a[1].b.c['d-d'].e"
 
 
ObjectPath.stringify(['a','1','b','c','d-d','e'],'"');
// => 'a[1].b.c["d-d"].e'
 
 
ObjectPath.stringify(['a','1','b','c','d-d','e'],"'", true);
// => "['a']['1']['b']['c']['d-d']['e']"

Normalize a Path

ObjectPath.normalize(str, [quote="'"], [forceQuote=false])

var ObjectPath = require('objectpath');
 
ObjectPath.normalize('a[1].b.c.d["e"]["f-f"].g');
// => "a[1].b.c.d.e['f-f'].g"
 
ObjectPath.normalize('a[1].b.c.d["e"]["f-f"].g', '"');
// => 'a[1].b.c.d.e["f-f"].g'
 
ObjectPath.normalize('a[1].b.c.d["e"]["f-f"].g', "'", true);
// => "['a']['1']['b']['c']['d']['e']['f-f']['g']"

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.05,002latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.05,002
1.2.25,742
1.2.1599
1.2.00
1.1.01,815
1.0.51
1.0.10
1.0.01
0.0.30

Package Sidebar

Install

npm i objectpath

Weekly Downloads

13,160

Version

2.0.0

License

MIT

Unpacked Size

17.3 kB

Total Files

8

Last publish

Collaborators

  • mike-marcacci