6.1.0 • Published 9 months ago

@finnair/path-parser v6.1.0

Weekly downloads
33
License
MIT
Repository
github
Last release
9 months ago

Path Parser

@finnair/path-parser contains nearley.js based parsers for Path and PathMatcher.

See @finnair/path or instructions on how to use Path and PathMatcher.

Getting Started

Install v-validation using yarn:

yarn add @finnair/path-parser

Or npm:

npm install @finnair/path-parser

Parsing Paths

import { parsePath } from '@finnair/path-parser';

parsePath(`$.array[1]["\\"property\\" with spaces and 'quotes'"]`); // JSON string encoded in brackets!
// Path.of('array', 1, `"property" with spaces and 'quotes'`);

// Single quotes also work, but encoding is still JSON string so the value cannot contain ' character
parsePath(`$['single quotes']`); // Path.of('single quotes')
parsePath(`$['single\'quote']`); // Fail!

// ...without using unicode escape
parsePath(`$['\\u0027']`); // Path.of("'");

Parsing PathMatchers

parsePathMatcher parses simple JsonPath like expressions. Supported expressions are

ExpressionDescription 
$.propertyIdentifiers matching RegExp /^[a-zA-Z_][a-zA-Z0-9_]*$/
$[0]Index match
$.*Any property matcher, wildcard (matches also array indexes)
$[*]Any index matcher, wildcard (matches only array indexes)
$["JSON string encoded property"]Property as JSON encoded string
$['JSON string encoded property']Property as single quoted, but otherwise JSON encoded, string(*)
$[union,"of",4,'components']Union matcher that also supports identifiers and JSON encoded strings

*) This is the official way of JsonPath, but the specification is a bit unclear on the encoding. In this library we prefer proper JSON string encoding with double quotes.

import { parsePathMatcher } from '@finnair/path-parser';

parsePathMatcher(`$.array[0][*].*['union',"of",properties,1]`);
// PathMatcher.of(
//   'array',
//    0,
//   AnyIndex,
//   AnyProperty,
//   UnionMatcher.of('union', 'of', 'properties', 1)
// )
6.1.0

9 months ago

6.0.1

10 months ago

6.0.0

10 months ago

6.0.2

10 months ago

5.4.0

1 year ago

5.3.0

1 year ago

5.2.0

1 year ago

5.1.0

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

3.1.0

3 years ago

4.0.0

3 years ago

3.0.0

3 years ago

3.0.0-alpha.1

3 years ago

3.0.0-alpha.2

3 years ago

2.0.0

3 years ago

1.1.0

3 years ago

1.1.0-alpha.0

3 years ago

1.1.0-alpha.5

3 years ago

1.1.0-alpha.6

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago