包详细信息

chensley-objectpath

CliftonH399MIT1.1.1

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

js object, dot notation, bracket notation, path

自述文件

Important!

This was all blatantly stolen from Mike Marcacci here: https://github.com/mike-marcacci/objectpath.git I've made changes so that I can use this module with webpack and have submitted a PR to the original source. When (if) that gets merged, I'll delete this repo.

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)

```js var ObjectPath = require('objectpath');

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