Skip to content

mike-marcacci/objectpath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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']"

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published