Skip to content

Commit 55f37db

Browse files
committed
initial release
1 parent 696a905 commit 55f37db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1880
-1486
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ end_of_line = lf
55
insert_final_newline = true
66
trim_trailing_whitespace = true
77

8-
[*.{ts,mjs,js,json}]
8+
[*.{ts,js,json}]
99
charset = utf-8
1010
indent_style = space
1111
indent_size = 2

.github/workflows/main.yml

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,65 @@ name: CI
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88
branches:
9-
- master
10-
11-
workflow_dispatch:
9+
- main
1210
jobs:
13-
test:
11+
lint-and-test:
1412
runs-on: ubuntu-latest
1513

1614
steps:
17-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1816

19-
- uses: actions/setup-node@v2
17+
- uses: actions/setup-node@v4
2018
with:
21-
node-version: '18'
19+
node-version-file: .nvmrc
20+
21+
- name: Install Dependencies
22+
run: npm ci --ignore-scripts
2223

23-
- name: Install Dependencies and Build Code
24-
run: |
25-
npm ci --ignore-scripts
26-
npm run build
24+
- name: Build Parser
25+
run: node --run build.parser
2726

2827
- name: Lint
29-
run: npm run lint
28+
run: node --run lint
29+
30+
- name: Run type-check
31+
run: tsc --noEmit
3032

3133
- name: Run Tests
32-
run: npm run test
34+
run: node --run test
3335

34-
- name: Codecov
36+
- name: Upload Coverage to Codecov
3537
uses: codecov/[email protected]
3638
with:
37-
directory: ./coverage
39+
directory: .
40+
41+
release:
42+
runs-on: ubuntu-latest
43+
needs:
44+
- lint-and-test
45+
if: startsWith(github.ref, 'refs/tags/')
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- uses: actions/setup-node@v4
51+
with:
52+
node-version-file: .nvmrc
53+
54+
- name: Install Dependencies
55+
run: npm ci --ignore-scripts
56+
57+
- name: Build Parser
58+
run: node --run build.parser
59+
60+
- name: Build Code
61+
run: node --run build
62+
63+
- name: Login to NPM
64+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
65+
66+
- name: Publish to NPM
67+
run: npm publish

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea/
22
node_modules/
3-
.cache/
4-
*.log
5-
.gen/
3+
dist/
4+
lcov.info
5+
.tsbuildinfo

.husky/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
npm run lint
2-
npm test
1+
node --run lint
2+
node --run test

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/jod

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# jsonpath-rfc9535
2+
3+
A JSONPath implementation based on [RFC 9535](https://datatracker.ietf.org/doc/rfc9535/).
4+
5+
Works in any environment complying with ECMAScript 2022.
6+
7+
It passes the entire [JSONPath Compliance Test Suite](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite) with 100% success rate (tested against commit 9277705).
8+
9+
If you are interested in a legacy specification, please check out my other package [nimma](https://github.com/P0lip/nimma).
10+
11+
## Installation
12+
13+
To install the package, you can use npm:
14+
15+
```sh
16+
npm install jsonpath-rfc9535
17+
```
18+
19+
or a package manager of your choice.
20+
21+
## Usage
22+
23+
```js
24+
import { query } from 'jsonpath-rfc9535';
25+
26+
const document = {
27+
"store": {
28+
"book": [
29+
{
30+
"category": "reference",
31+
"author": "Nigel Rees",
32+
"title": "Sayings of the Century",
33+
"price": 8.95,
34+
},
35+
{
36+
"category": "fiction",
37+
"author": "Evelyn Waugh",
38+
"title": "Sword of Honour",
39+
"price": 12.99,
40+
},
41+
{
42+
"category": "fiction",
43+
"author": "Herman Melville",
44+
"title": "Moby Dick",
45+
"isbn": "0-553-21311-3",
46+
"price": 8.99,
47+
},
48+
{
49+
"category": "fiction",
50+
"author": "J. R. R. Tolkien",
51+
"title": "The Lord of the Rings",
52+
"isbn": "0-395-19395-8",
53+
"price": 22.99,
54+
},
55+
],
56+
"bicycle": {
57+
"color": "red",
58+
"price": 399,
59+
},
60+
},
61+
};
62+
63+
const path = '$.store.book[*].author';
64+
const result = query(document, path);
65+
66+
console.log(result); // Outputs: ['Nigel Rees', 'Evelyn Waugh', 'Herman Melville', 'J. R. R. Tolkien']
67+
```
68+
69+
You can also import `exec` member that takes a callback.
70+
71+
```ts
72+
import { exec } from 'jsonpath-rfc9535';
73+
74+
const document = {
75+
// ...
76+
}
77+
78+
const path = '$.store.book[*].author';
79+
const result = exec(document, path, (value) => {
80+
// consume matched value
81+
});
82+
```
83+
## Parser
84+
85+
The parser is generated using [Peggy](https://peggyjs.org/). In the future, I would like to merge it with the Nimma's [parser](https://github.com/P0lip/nimma/blob/master/src/parser/parser.mjs) to shrink down the package size as well as improve the performance.
86+
87+
The parser can be imported as a standalone module:
88+
89+
```js
90+
import parse from 'jsonpath-rfc9535/parser';
91+
92+
const ast = parse('$.store.book[*].author');
93+
// consume ast
94+
```
95+
96+
## Regular Expressions
97+
98+
Bear in mind that `match` and `search` functions accept regular expressions in the form of I-Regexp ([RFC 9485](https://datatracker.ietf.org/doc/rfc9485/)).
99+
These regular expressions are largely compatible with the standard ECMAScript regular expressions, but there is one relatively minor difference.
100+
In I-Regexp, the dot (.) character matches any character except for `\n` and `\r`.
101+
On top of that, Unicode is enabled by default.
102+
103+
## Custom Function Extensions
104+
105+
At the moment, custom function extensions are not supported.
106+
However, the API is designed to support them, so they might be added in the future if there is a demand for them.

biome.jsonc

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,60 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3-
"files": {
4-
"include": ["src/**/*.js", "src/**/*.ts"]
5-
},
6-
"formatter": {
7-
"enabled": true
8-
},
9-
"linter": {
10-
"enabled": false
11-
},
12-
"organizeImports": {
13-
"enabled": false
14-
}
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"include": ["src/**/*.js", "src/**/*.ts", "src/**/*.json"],
10+
"ignore": [
11+
"src/__tests__/jsonpath-compliance-test-suite",
12+
"src/parser/parser.js",
13+
"src/parser/parser.d.ts"
14+
]
15+
},
16+
"formatter": {
17+
"enabled": true
18+
},
19+
"linter": {
20+
"enabled": true,
21+
"rules": {
22+
"complexity": {
23+
"noExcessiveCognitiveComplexity": {
24+
"level": "error",
25+
"options": {
26+
"maxAllowedComplexity": 20
27+
}
28+
}
29+
},
30+
"nursery": {
31+
"noProcessEnv": "error"
32+
},
33+
"correctness": {
34+
"noUnusedImports": "error",
35+
"noVoidTypeReturn": "off"
36+
},
37+
"performance": {
38+
"noBarrelFile": "error",
39+
"noReExportAll": "error"
40+
},
41+
"style": {
42+
"useNodeAssertStrict": "error",
43+
"useDefaultSwitchClause": "info"
44+
},
45+
"suspicious": {
46+
"noConsole": "error",
47+
"noEvolvingTypes": "error"
48+
}
49+
}
50+
},
51+
"organizeImports": {
52+
"enabled": true
53+
},
54+
"json": {
55+
"formatter": {
56+
"indentStyle": "space",
57+
"trailingCommas": "none"
58+
}
59+
}
1560
}

package-lock.json

Lines changed: 18 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)