mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-04-25 01:12:17 +00:00
Not support 'jsonpath-rs' since 0.2.4
This commit is contained in:
parent
7597325f59
commit
ffd87cfbe4
50
README.md
50
README.md
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/freestrings/jsonpath)
|
[](https://travis-ci.org/freestrings/jsonpath)
|
||||||

|

|
||||||

|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
@ -12,7 +11,6 @@ It is JsonPath [JsonPath](https://goessner.net/articles/JsonPath/) engine writte
|
|||||||
|
|
||||||
- [Webassembly Demo](https://freestrings.github.io/jsonpath/)
|
- [Webassembly Demo](https://freestrings.github.io/jsonpath/)
|
||||||
- [NPM jsonpath-wasm - webassembly](https://www.npmjs.com/package/jsonpath-wasm)
|
- [NPM jsonpath-wasm - webassembly](https://www.npmjs.com/package/jsonpath-wasm)
|
||||||
- [NPM jsonpath-rs - native addon](https://www.npmjs.com/package/jsonpath-rs)
|
|
||||||
|
|
||||||
## Rust API
|
## Rust API
|
||||||
|
|
||||||
@ -388,18 +386,6 @@ import * as jsonpath from "jsonpath-wasm";
|
|||||||
const jsonpath = require('jsonpath-wasm');
|
const jsonpath = require('jsonpath-wasm');
|
||||||
```
|
```
|
||||||
|
|
||||||
##### jsonpath-rs (NodeJS only)
|
|
||||||
|
|
||||||
Goto [`jsonpath-rs` npmjs.org](https://www.npmjs.com/package/jsonpath-rs)
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const jsonpath = require('jsonpath-rs');
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.Selector class</b></summary>
|
|
||||||
|
|
||||||
##### jsonpath-wasm
|
##### jsonpath-wasm
|
||||||
`wasm-bindgen` 리턴 타입 제약 때문에 빌더 패턴은 지원하지 않는다.
|
`wasm-bindgen` 리턴 타입 제약 때문에 빌더 패턴은 지원하지 않는다.
|
||||||
|
|
||||||
@ -435,42 +421,6 @@ console.log(JSON.stringify(ret) == JSON.stringify(retObj));
|
|||||||
// => true
|
// => true
|
||||||
```
|
```
|
||||||
|
|
||||||
##### jsonpath-rs
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selector = new jsonpath.Selector()
|
|
||||||
.path('$..friends[0]')
|
|
||||||
.value(jsonObj);
|
|
||||||
|
|
||||||
let retObj = selector.select();
|
|
||||||
|
|
||||||
console.log(JSON.stringify(ret) == JSON.stringify(retObj));
|
|
||||||
|
|
||||||
// => true
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.SelectorMut class</b></summary>
|
|
||||||
|
|
||||||
빌더 패턴 제약은 `Selector class`와 동일하다.
|
빌더 패턴 제약은 `Selector class`와 동일하다.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
DIR="$(pwd)"
|
|
||||||
|
|
||||||
cd "${DIR}"/bench_bin && cargo build --release
|
|
||||||
|
|
||||||
ITER=100000
|
|
||||||
|
|
||||||
printf "\n\n$..book[?(@.price<30 && @.category=="fiction")] (loop ${ITER})"
|
|
||||||
printf "\n\n"
|
|
||||||
|
|
||||||
__default () {
|
|
||||||
echo "Rust - select: " && time ./bench.sh select ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
sleep 1
|
|
||||||
cd "${DIR}"/javascript && echo "NodeJs - jsonpath - query: " && time ./bench.sh jsonpath ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
sleep 1
|
|
||||||
cd "${DIR}"/javascript && echo "NodeJs - jsonpath-rs - select:" && time ./bench.sh nativeSelect ${ITER}
|
|
||||||
}
|
|
||||||
|
|
||||||
__extra () {
|
|
||||||
echo "Rust - selector: " && time ./bench.sh selector ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
sleep 1
|
|
||||||
echo "Rust - compile: " && time ./bench.sh compile ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
sleep 1
|
|
||||||
cd "${DIR}"/javascript && echo "NodeJs - jsonpath - query: " && time ./bench.sh jsonpath ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
sleep 1
|
|
||||||
cd "${DIR}"/javascript && echo "NodeJs - jsonpath-rs - selector: " && time ./bench.sh nativeSelector ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
sleep 1
|
|
||||||
cd "${DIR}"/javascript && echo "NodeJs - jsonpath-rs - compile: " && time ./bench.sh nativeCompile ${ITER}
|
|
||||||
printf "\n"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$1" = "extra" ]; then
|
|
||||||
__extra
|
|
||||||
else
|
|
||||||
__default
|
|
||||||
fi
|
|
@ -43,7 +43,6 @@ function getJson() {
|
|||||||
const path = '$..book[?(@.price<30 && @.category=="fiction")]';
|
const path = '$..book[?(@.price<30 && @.category=="fiction")]';
|
||||||
const jp = require('jsonpath');
|
const jp = require('jsonpath');
|
||||||
const jpw = require('jsonpath-wasm');
|
const jpw = require('jsonpath-wasm');
|
||||||
const jpwRs = require('jsonpath-rs');
|
|
||||||
|
|
||||||
function jsonpath() {
|
function jsonpath() {
|
||||||
for (var i = 0; i < iter; i++) {
|
for (var i = 0; i < iter; i++) {
|
||||||
@ -51,26 +50,6 @@ function jsonpath() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function nativeCompile() {
|
|
||||||
let template = jpwRs.compile(path);
|
|
||||||
for (var i = 0; i < iter; i++) {
|
|
||||||
let _ = template(JSON.stringify(json));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function nativeSelector() {
|
|
||||||
let selector = jpwRs.selector(getJson());
|
|
||||||
for (var i = 0; i < iter; i++) {
|
|
||||||
let _ = selector(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function nativeSelect() {
|
|
||||||
for (var i = 0; i < iter; i++) {
|
|
||||||
let _ = jpwRs.select(JSON.stringify(json), path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function wasmSelector() {
|
function wasmSelector() {
|
||||||
let selector = jpw.selector(getJson());
|
let selector = jpw.selector(getJson());
|
||||||
for (var i = 0; i < iter; i++) {
|
for (var i = 0; i < iter; i++) {
|
||||||
|
3
build.sh
3
build.sh
@ -106,8 +106,7 @@ cd "${WASM_WWW_BENCH}" && \
|
|||||||
npm link jsonpath-wasm
|
npm link jsonpath-wasm
|
||||||
|
|
||||||
cd "${BENCHES_JS}" && \
|
cd "${BENCHES_JS}" && \
|
||||||
npm link jsonpath-wasm && \
|
npm link jsonpath-wasm
|
||||||
npm link jsonpath-rs
|
|
||||||
|
|
||||||
cd "${WASM_TEST}" && \
|
cd "${WASM_TEST}" && \
|
||||||
npm link jsonpath-wasm
|
npm link jsonpath-wasm
|
||||||
|
2
examples/nodejs-rs/.gitignore
vendored
2
examples/nodejs-rs/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
node_modules
|
|
||||||
dist
|
|
@ -1,37 +0,0 @@
|
|||||||
const jsonpath = require('jsonpath-rs');
|
|
||||||
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
const path = '$..friends[0]';
|
|
||||||
|
|
||||||
let ret1 = jsonpath.select(jsonObj, path);
|
|
||||||
let ret2 = jsonpath.compile(path)(jsonObj);
|
|
||||||
let ret3 = jsonpath.selector(jsonObj)(path);
|
|
||||||
|
|
||||||
let selector = new jsonpath.Selector();
|
|
||||||
selector.path(path);
|
|
||||||
selector.value(jsonObj);
|
|
||||||
let ret4 = selector.select();
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
JSON.stringify(ret) == JSON.stringify(ret1),
|
|
||||||
JSON.stringify(ret) == JSON.stringify(ret2),
|
|
||||||
JSON.stringify(ret) == JSON.stringify(ret3),
|
|
||||||
JSON.stringify(ret) == JSON.stringify(ret4)
|
|
||||||
);
|
|
719
examples/nodejs-rs/package-lock.json
generated
719
examples/nodejs-rs/package-lock.json
generated
@ -1,719 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "jsonpath-rs-example",
|
|
||||||
"requires": true,
|
|
||||||
"lockfileVersion": 1,
|
|
||||||
"dependencies": {
|
|
||||||
"ansi-escape-sequences": {
|
|
||||||
"version": "4.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ansi-escape-sequences/-/ansi-escape-sequences-4.1.0.tgz",
|
|
||||||
"integrity": "sha512-dzW9kHxH011uBsidTXd14JXgzye/YLb2LzeKZ4bsgl/Knwx8AtbSFkkGxagdNOoh0DlqHCmfiEjWKBaqjOanVw==",
|
|
||||||
"requires": {
|
|
||||||
"array-back": "^3.0.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"array-back": {
|
|
||||||
"version": "3.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz",
|
|
||||||
"integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ansi-escapes": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz",
|
|
||||||
"integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ=="
|
|
||||||
},
|
|
||||||
"ansi-regex": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
|
|
||||||
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
|
|
||||||
},
|
|
||||||
"ansi-styles": {
|
|
||||||
"version": "3.2.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
|
|
||||||
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
|
|
||||||
"requires": {
|
|
||||||
"color-convert": "^1.9.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"array-back": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-eJv4pLLufP3g5kcZry0j6WXpIbzYw9GUB4mVJZno9wfwiBxbizTnHCw3VJb07cBihbFX48Y7oSrW9y+gt4glyw==",
|
|
||||||
"requires": {
|
|
||||||
"typical": "^2.6.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"balanced-match": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
|
||||||
},
|
|
||||||
"brace-expansion": {
|
|
||||||
"version": "1.1.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
|
||||||
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
|
||||||
"requires": {
|
|
||||||
"balanced-match": "^1.0.0",
|
|
||||||
"concat-map": "0.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"builtins": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz",
|
|
||||||
"integrity": "sha1-y5T662HIaWRR2zZTThQi+U8K7og="
|
|
||||||
},
|
|
||||||
"chalk": {
|
|
||||||
"version": "2.4.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
|
|
||||||
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
|
|
||||||
"requires": {
|
|
||||||
"ansi-styles": "^3.2.1",
|
|
||||||
"escape-string-regexp": "^1.0.5",
|
|
||||||
"supports-color": "^5.3.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"chardet": {
|
|
||||||
"version": "0.4.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz",
|
|
||||||
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I="
|
|
||||||
},
|
|
||||||
"check-node-version": {
|
|
||||||
"version": "4.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/check-node-version/-/check-node-version-4.0.1.tgz",
|
|
||||||
"integrity": "sha512-pWV+uuJJoOGbODDC6+DPUYeprv1CUg/jr1SGKpgkANstGN22f9T0Vn40mdv6hvRZ25KMH/IjkVc0LZH5ms+qEg==",
|
|
||||||
"requires": {
|
|
||||||
"chalk": "^2.3.0",
|
|
||||||
"map-values": "^1.0.1",
|
|
||||||
"minimist": "^1.2.0",
|
|
||||||
"object-filter": "^1.0.2",
|
|
||||||
"run-parallel": "^1.1.4",
|
|
||||||
"semver": "^5.7.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cli-cursor": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz",
|
|
||||||
"integrity": "sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=",
|
|
||||||
"requires": {
|
|
||||||
"restore-cursor": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"cli-width": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz",
|
|
||||||
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk="
|
|
||||||
},
|
|
||||||
"color-convert": {
|
|
||||||
"version": "1.9.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
|
|
||||||
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
|
|
||||||
"requires": {
|
|
||||||
"color-name": "1.1.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"color-name": {
|
|
||||||
"version": "1.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
|
||||||
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
|
|
||||||
},
|
|
||||||
"command-line-args": {
|
|
||||||
"version": "4.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-4.0.7.tgz",
|
|
||||||
"integrity": "sha512-aUdPvQRAyBvQd2n7jXcsMDz68ckBJELXNzBybCHOibUWEg0mWTnaYCSRU8h9R+aNRSvDihJtssSRCiDRpLaezA==",
|
|
||||||
"requires": {
|
|
||||||
"array-back": "^2.0.0",
|
|
||||||
"find-replace": "^1.0.3",
|
|
||||||
"typical": "^2.6.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"command-line-commands": {
|
|
||||||
"version": "2.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/command-line-commands/-/command-line-commands-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-m8c2p1DrNd2ruIAggxd/y6DgygQayf6r8RHwchhXryaLF8I6koYjoYroVP+emeROE9DXN5b9sP1Gh+WtvTTdtQ==",
|
|
||||||
"requires": {
|
|
||||||
"array-back": "^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"command-line-usage": {
|
|
||||||
"version": "4.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/command-line-usage/-/command-line-usage-4.1.0.tgz",
|
|
||||||
"integrity": "sha512-MxS8Ad995KpdAC0Jopo/ovGIroV/m0KHwzKfXxKag6FHOkGsH8/lv5yjgablcRxCJJC0oJeUMuO/gmaq+Wq46g==",
|
|
||||||
"requires": {
|
|
||||||
"ansi-escape-sequences": "^4.0.0",
|
|
||||||
"array-back": "^2.0.0",
|
|
||||||
"table-layout": "^0.4.2",
|
|
||||||
"typical": "^2.6.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"commander": {
|
|
||||||
"version": "2.20.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
|
|
||||||
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"concat-map": {
|
|
||||||
"version": "0.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
|
||||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
|
||||||
},
|
|
||||||
"deep-extend": {
|
|
||||||
"version": "0.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
|
|
||||||
"integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA=="
|
|
||||||
},
|
|
||||||
"escape-string-regexp": {
|
|
||||||
"version": "1.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
|
||||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
|
|
||||||
},
|
|
||||||
"external-editor": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz",
|
|
||||||
"integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==",
|
|
||||||
"requires": {
|
|
||||||
"chardet": "^0.4.0",
|
|
||||||
"iconv-lite": "^0.4.17",
|
|
||||||
"tmp": "^0.0.33"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"figures": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/figures/-/figures-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=",
|
|
||||||
"requires": {
|
|
||||||
"escape-string-regexp": "^1.0.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"find-replace": {
|
|
||||||
"version": "1.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/find-replace/-/find-replace-1.0.3.tgz",
|
|
||||||
"integrity": "sha1-uI5zZNLZyVlVnziMZmcNYTBEH6A=",
|
|
||||||
"requires": {
|
|
||||||
"array-back": "^1.0.4",
|
|
||||||
"test-value": "^2.1.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"array-back": {
|
|
||||||
"version": "1.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-1.0.4.tgz",
|
|
||||||
"integrity": "sha1-ZEun8JX3/898Q7Xw3DnTwfA8Bjs=",
|
|
||||||
"requires": {
|
|
||||||
"typical": "^2.6.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"fs.realpath": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
|
||||||
},
|
|
||||||
"git-config": {
|
|
||||||
"version": "0.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/git-config/-/git-config-0.0.7.tgz",
|
|
||||||
"integrity": "sha1-qcij7wendsPXImE1bYtye2IgKyg=",
|
|
||||||
"requires": {
|
|
||||||
"iniparser": "~1.0.5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"glob": {
|
|
||||||
"version": "7.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
|
|
||||||
"integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",
|
|
||||||
"requires": {
|
|
||||||
"fs.realpath": "^1.0.0",
|
|
||||||
"inflight": "^1.0.4",
|
|
||||||
"inherits": "2",
|
|
||||||
"minimatch": "^3.0.4",
|
|
||||||
"once": "^1.3.0",
|
|
||||||
"path-is-absolute": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"handlebars": {
|
|
||||||
"version": "4.5.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.3.tgz",
|
|
||||||
"integrity": "sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA==",
|
|
||||||
"requires": {
|
|
||||||
"neo-async": "^2.6.0",
|
|
||||||
"optimist": "^0.6.1",
|
|
||||||
"source-map": "^0.6.1",
|
|
||||||
"uglify-js": "^3.1.4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"has-flag": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
|
||||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
|
||||||
},
|
|
||||||
"iconv-lite": {
|
|
||||||
"version": "0.4.24",
|
|
||||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
|
||||||
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
|
||||||
"requires": {
|
|
||||||
"safer-buffer": ">= 2.1.2 < 3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"inflight": {
|
|
||||||
"version": "1.0.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
|
||||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
|
||||||
"requires": {
|
|
||||||
"once": "^1.3.0",
|
|
||||||
"wrappy": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"inherits": {
|
|
||||||
"version": "2.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
|
||||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
|
||||||
},
|
|
||||||
"iniparser": {
|
|
||||||
"version": "1.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/iniparser/-/iniparser-1.0.5.tgz",
|
|
||||||
"integrity": "sha1-g21r7+bfv87gvM8c+fKsxwJ/eD0="
|
|
||||||
},
|
|
||||||
"inquirer": {
|
|
||||||
"version": "3.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz",
|
|
||||||
"integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==",
|
|
||||||
"requires": {
|
|
||||||
"ansi-escapes": "^3.0.0",
|
|
||||||
"chalk": "^2.0.0",
|
|
||||||
"cli-cursor": "^2.1.0",
|
|
||||||
"cli-width": "^2.0.0",
|
|
||||||
"external-editor": "^2.0.4",
|
|
||||||
"figures": "^2.0.0",
|
|
||||||
"lodash": "^4.3.0",
|
|
||||||
"mute-stream": "0.0.7",
|
|
||||||
"run-async": "^2.2.0",
|
|
||||||
"rx-lite": "^4.0.8",
|
|
||||||
"rx-lite-aggregates": "^4.0.8",
|
|
||||||
"string-width": "^2.1.0",
|
|
||||||
"strip-ansi": "^4.0.0",
|
|
||||||
"through": "^2.3.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"is-fullwidth-code-point": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8="
|
|
||||||
},
|
|
||||||
"is-promise": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz",
|
|
||||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
|
|
||||||
},
|
|
||||||
"jsonpath-rs": {
|
|
||||||
"version": "0.2.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/jsonpath-rs/-/jsonpath-rs-0.2.2.tgz",
|
|
||||||
"integrity": "sha512-mKthE5svt4A1LO6cn7RRSexOM5RuKvPhBRRLsi95rTFQsHWhWpqkgmBzNGPuDEiGDyW3ED8c/zp/YtTHTBUFzA==",
|
|
||||||
"requires": {
|
|
||||||
"check-node-version": "*",
|
|
||||||
"neon-cli": "^0.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"lodash": {
|
|
||||||
"version": "4.17.14",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.14.tgz",
|
|
||||||
"integrity": "sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw=="
|
|
||||||
},
|
|
||||||
"lodash.padend": {
|
|
||||||
"version": "4.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.padend/-/lodash.padend-4.6.1.tgz",
|
|
||||||
"integrity": "sha1-U8y6BH0G4VjTEfRdpiX05J5vFm4="
|
|
||||||
},
|
|
||||||
"map-values": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/map-values/-/map-values-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-douOecAJvytk/ugG4ip7HEGQyZA="
|
|
||||||
},
|
|
||||||
"mimic-fn": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ=="
|
|
||||||
},
|
|
||||||
"minimatch": {
|
|
||||||
"version": "3.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
|
||||||
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
|
|
||||||
"requires": {
|
|
||||||
"brace-expansion": "^1.1.7"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"minimist": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
|
||||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
|
||||||
},
|
|
||||||
"mkdirp": {
|
|
||||||
"version": "0.5.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
|
||||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
|
||||||
"requires": {
|
|
||||||
"minimist": "0.0.8"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"minimist": {
|
|
||||||
"version": "0.0.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
|
||||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"mute-stream": {
|
|
||||||
"version": "0.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
|
|
||||||
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s="
|
|
||||||
},
|
|
||||||
"neo-async": {
|
|
||||||
"version": "2.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz",
|
|
||||||
"integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw=="
|
|
||||||
},
|
|
||||||
"neon-cli": {
|
|
||||||
"version": "0.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/neon-cli/-/neon-cli-0.2.0.tgz",
|
|
||||||
"integrity": "sha512-IsrxCyUcuAyWiq4Z+JnTXrjurj2SAL2VtWnCXS8iBYGJeIs1NIhFuLaM6fe7+rOyFfDcqUUTWGxZmkvUqwweRA==",
|
|
||||||
"requires": {
|
|
||||||
"chalk": "~2.1.0",
|
|
||||||
"command-line-args": "^4.0.2",
|
|
||||||
"command-line-commands": "^2.0.0",
|
|
||||||
"command-line-usage": "^4.0.0",
|
|
||||||
"git-config": "0.0.7",
|
|
||||||
"handlebars": "^4.0.3",
|
|
||||||
"inquirer": "^3.0.6",
|
|
||||||
"mkdirp": "^0.5.1",
|
|
||||||
"quickly-copy-file": "^1.0.0",
|
|
||||||
"rimraf": "^2.6.1",
|
|
||||||
"rsvp": "^4.6.1",
|
|
||||||
"semver": "^5.1.0",
|
|
||||||
"toml": "^2.3.0",
|
|
||||||
"ts-typed-json": "^0.2.2",
|
|
||||||
"validate-npm-package-license": "^3.0.1",
|
|
||||||
"validate-npm-package-name": "^3.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"chalk": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz",
|
|
||||||
"integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==",
|
|
||||||
"requires": {
|
|
||||||
"ansi-styles": "^3.1.0",
|
|
||||||
"escape-string-regexp": "^1.0.5",
|
|
||||||
"supports-color": "^4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"has-flag": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE="
|
|
||||||
},
|
|
||||||
"supports-color": {
|
|
||||||
"version": "4.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.5.0.tgz",
|
|
||||||
"integrity": "sha1-vnoN5ITexcXN34s9WRJQRJEvY1s=",
|
|
||||||
"requires": {
|
|
||||||
"has-flag": "^2.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"object-filter": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/object-filter/-/object-filter-1.0.2.tgz",
|
|
||||||
"integrity": "sha1-rwt5f/6+r4pSxmN87b6IFs/sG8g="
|
|
||||||
},
|
|
||||||
"once": {
|
|
||||||
"version": "1.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
|
||||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
|
||||||
"requires": {
|
|
||||||
"wrappy": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"onetime": {
|
|
||||||
"version": "2.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz",
|
|
||||||
"integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=",
|
|
||||||
"requires": {
|
|
||||||
"mimic-fn": "^1.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"optimist": {
|
|
||||||
"version": "0.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
|
|
||||||
"integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=",
|
|
||||||
"requires": {
|
|
||||||
"minimist": "~0.0.1",
|
|
||||||
"wordwrap": "~0.0.2"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"minimist": {
|
|
||||||
"version": "0.0.10",
|
|
||||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
|
|
||||||
"integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"os-tmpdir": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
|
|
||||||
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
|
|
||||||
},
|
|
||||||
"path-is-absolute": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
|
||||||
},
|
|
||||||
"quickly-copy-file": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/quickly-copy-file/-/quickly-copy-file-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-n4/wZiMFEO50IrASFHKwk6hpCFk=",
|
|
||||||
"requires": {
|
|
||||||
"mkdirp": "~0.5.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"reduce-flatten": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/reduce-flatten/-/reduce-flatten-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-JYx479FT3fk8tWEjf2EYTzaW4yc="
|
|
||||||
},
|
|
||||||
"restore-cursor": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-n37ih/gv0ybU/RYpI9YhKe7g368=",
|
|
||||||
"requires": {
|
|
||||||
"onetime": "^2.0.0",
|
|
||||||
"signal-exit": "^3.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rimraf": {
|
|
||||||
"version": "2.6.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
|
|
||||||
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
|
|
||||||
"requires": {
|
|
||||||
"glob": "^7.1.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rsvp": {
|
|
||||||
"version": "4.8.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/rsvp/-/rsvp-4.8.5.tgz",
|
|
||||||
"integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA=="
|
|
||||||
},
|
|
||||||
"run-async": {
|
|
||||||
"version": "2.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz",
|
|
||||||
"integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=",
|
|
||||||
"requires": {
|
|
||||||
"is-promise": "^2.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"run-parallel": {
|
|
||||||
"version": "1.1.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.1.9.tgz",
|
|
||||||
"integrity": "sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q=="
|
|
||||||
},
|
|
||||||
"rx-lite": {
|
|
||||||
"version": "4.0.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz",
|
|
||||||
"integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ="
|
|
||||||
},
|
|
||||||
"rx-lite-aggregates": {
|
|
||||||
"version": "4.0.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz",
|
|
||||||
"integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=",
|
|
||||||
"requires": {
|
|
||||||
"rx-lite": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"safer-buffer": {
|
|
||||||
"version": "2.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
|
||||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
|
||||||
},
|
|
||||||
"semver": {
|
|
||||||
"version": "5.7.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz",
|
|
||||||
"integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA=="
|
|
||||||
},
|
|
||||||
"signal-exit": {
|
|
||||||
"version": "3.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
|
||||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
|
|
||||||
},
|
|
||||||
"source-map": {
|
|
||||||
"version": "0.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
|
||||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
|
|
||||||
},
|
|
||||||
"spdx-correct": {
|
|
||||||
"version": "3.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz",
|
|
||||||
"integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==",
|
|
||||||
"requires": {
|
|
||||||
"spdx-expression-parse": "^3.0.0",
|
|
||||||
"spdx-license-ids": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"spdx-exceptions": {
|
|
||||||
"version": "2.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz",
|
|
||||||
"integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA=="
|
|
||||||
},
|
|
||||||
"spdx-expression-parse": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==",
|
|
||||||
"requires": {
|
|
||||||
"spdx-exceptions": "^2.1.0",
|
|
||||||
"spdx-license-ids": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"spdx-license-ids": {
|
|
||||||
"version": "3.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.4.tgz",
|
|
||||||
"integrity": "sha512-7j8LYJLeY/Yb6ACbQ7F76qy5jHkp0U6jgBfJsk97bwWlVUnUWsAgpyaCvo17h0/RQGnQ036tVDomiwoI4pDkQA=="
|
|
||||||
},
|
|
||||||
"string-width": {
|
|
||||||
"version": "2.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
|
||||||
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
|
|
||||||
"requires": {
|
|
||||||
"is-fullwidth-code-point": "^2.0.0",
|
|
||||||
"strip-ansi": "^4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"strip-ansi": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
|
|
||||||
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
|
|
||||||
"requires": {
|
|
||||||
"ansi-regex": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"supports-color": {
|
|
||||||
"version": "5.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
|
||||||
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
|
||||||
"requires": {
|
|
||||||
"has-flag": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"table-layout": {
|
|
||||||
"version": "0.4.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/table-layout/-/table-layout-0.4.4.tgz",
|
|
||||||
"integrity": "sha512-uNaR3SRMJwfdp9OUr36eyEi6LLsbcTqTO/hfTsNviKsNeyMBPICJCC7QXRF3+07bAP6FRwA8rczJPBqXDc0CkQ==",
|
|
||||||
"requires": {
|
|
||||||
"array-back": "^2.0.0",
|
|
||||||
"deep-extend": "~0.6.0",
|
|
||||||
"lodash.padend": "^4.6.1",
|
|
||||||
"typical": "^2.6.1",
|
|
||||||
"wordwrapjs": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"test-value": {
|
|
||||||
"version": "2.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/test-value/-/test-value-2.1.0.tgz",
|
|
||||||
"integrity": "sha1-Edpv9nDzRxpztiXKTz/c97t0gpE=",
|
|
||||||
"requires": {
|
|
||||||
"array-back": "^1.0.3",
|
|
||||||
"typical": "^2.6.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"array-back": {
|
|
||||||
"version": "1.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-1.0.4.tgz",
|
|
||||||
"integrity": "sha1-ZEun8JX3/898Q7Xw3DnTwfA8Bjs=",
|
|
||||||
"requires": {
|
|
||||||
"typical": "^2.6.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"through": {
|
|
||||||
"version": "2.3.8",
|
|
||||||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
|
|
||||||
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
|
|
||||||
},
|
|
||||||
"tmp": {
|
|
||||||
"version": "0.0.33",
|
|
||||||
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
|
|
||||||
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
|
|
||||||
"requires": {
|
|
||||||
"os-tmpdir": "~1.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"toml": {
|
|
||||||
"version": "2.3.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/toml/-/toml-2.3.6.tgz",
|
|
||||||
"integrity": "sha512-gVweAectJU3ebq//Ferr2JUY4WKSDe5N+z0FvjDncLGyHmIDoxgY/2Ie4qfEIDm4IS7OA6Rmdm7pdEEdMcV/xQ=="
|
|
||||||
},
|
|
||||||
"ts-typed-json": {
|
|
||||||
"version": "0.2.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/ts-typed-json/-/ts-typed-json-0.2.2.tgz",
|
|
||||||
"integrity": "sha1-UxhL7ok+RZkbc8jEY6OLWeJ81H4=",
|
|
||||||
"requires": {
|
|
||||||
"rsvp": "^3.5.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"rsvp": {
|
|
||||||
"version": "3.6.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/rsvp/-/rsvp-3.6.2.tgz",
|
|
||||||
"integrity": "sha512-OfWGQTb9vnwRjwtA2QwpG2ICclHC3pgXZO5xt8H2EfgDquO0qVdSb5T88L4qJVAEugbS56pAuV4XZM58UX8ulw=="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"typical": {
|
|
||||||
"version": "2.6.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/typical/-/typical-2.6.1.tgz",
|
|
||||||
"integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0="
|
|
||||||
},
|
|
||||||
"uglify-js": {
|
|
||||||
"version": "3.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz",
|
|
||||||
"integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==",
|
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
|
||||||
"commander": "~2.20.0",
|
|
||||||
"source-map": "~0.6.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"validate-npm-package-license": {
|
|
||||||
"version": "3.0.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",
|
|
||||||
"integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==",
|
|
||||||
"requires": {
|
|
||||||
"spdx-correct": "^3.0.0",
|
|
||||||
"spdx-expression-parse": "^3.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"validate-npm-package-name": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/validate-npm-package-name/-/validate-npm-package-name-3.0.0.tgz",
|
|
||||||
"integrity": "sha1-X6kS2B630MdK/BQN5zF/DKffQ34=",
|
|
||||||
"requires": {
|
|
||||||
"builtins": "^1.0.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"wordwrap": {
|
|
||||||
"version": "0.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
|
|
||||||
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc="
|
|
||||||
},
|
|
||||||
"wordwrapjs": {
|
|
||||||
"version": "3.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/wordwrapjs/-/wordwrapjs-3.0.0.tgz",
|
|
||||||
"integrity": "sha512-mO8XtqyPvykVCsrwj5MlOVWvSnCdT+C+QVbm6blradR7JExAhbkZ7hZ9A+9NUtwzSqrlUo9a67ws0EiILrvRpw==",
|
|
||||||
"requires": {
|
|
||||||
"reduce-flatten": "^1.0.1",
|
|
||||||
"typical": "^2.6.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"wrappy": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
|
||||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "jsonpath-rs-example",
|
|
||||||
"scripts": {
|
|
||||||
"start": "node index.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"jsonpath-rs": "^0.2.2"
|
|
||||||
}
|
|
||||||
}
|
|
7
nodejs/.gitignore
vendored
7
nodejs/.gitignore
vendored
@ -1,7 +0,0 @@
|
|||||||
native/target
|
|
||||||
native/index.node
|
|
||||||
native/artifacts.json
|
|
||||||
**/*~
|
|
||||||
**/node_modules
|
|
||||||
.idea
|
|
||||||
build
|
|
334
nodejs/README.md
334
nodejs/README.md
@ -1,334 +0,0 @@
|
|||||||
# jsonpath-rs
|
|
||||||
|
|
||||||
[](https://travis-ci.org/freestrings/jsonpath)
|
|
||||||
|
|
||||||
It is native-addon of [jsonpath_lib](https://github.com/freestrings/jsonpath) that is [JsonPath](https://goessner.net/articles/JsonPath/) engine written in Rust.
|
|
||||||
|
|
||||||
## Notice
|
|
||||||
|
|
||||||
Pre-built 바이너리는 제공하진 않고 소스를 컴파일해서 설치한다. 만약 Rust가 설치되지 않았다면 자동으로 설치된다.
|
|
||||||
|
|
||||||
Build from source instead of using pre-built binary, and if Rust is not installed, the latest version is automatically installed.
|
|
||||||
|
|
||||||
> Not yet tested in Windows.
|
|
||||||
|
|
||||||
> Supported node version is under v12.0.
|
|
||||||
|
|
||||||
## APIs
|
|
||||||
|
|
||||||
<details><summary><b>npm package</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const jsonpath = require('jsonpath-rs');
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.Selector class</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selector = new jsonpath.Selector()
|
|
||||||
.path('$..friends[0]')
|
|
||||||
.value(jsonObj);
|
|
||||||
|
|
||||||
let retObj = selector.select();
|
|
||||||
|
|
||||||
console.log(JSON.stringify(ret) == JSON.stringify(retObj));
|
|
||||||
|
|
||||||
// => true
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.SelectorMut class</b></summary>
|
|
||||||
|
|
||||||
빌더 패턴 제약은 `Selector class`와 동일하다.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
'school': {
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구1', 'age': 20},
|
|
||||||
{'name': '친구2', 'age': 20},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구3', 'age': 30},
|
|
||||||
{'name': '친구4'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
let selector = new jsonpath.SelectorMut();
|
|
||||||
selector.path('$..[?(@.age == 20)]');
|
|
||||||
|
|
||||||
{
|
|
||||||
selector.value(jsonObj);
|
|
||||||
selector.deleteValue();
|
|
||||||
|
|
||||||
let resultObj = {
|
|
||||||
'school': {'friends': [null, null]},
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구3', 'age': 30},
|
|
||||||
{'name': '친구4'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
console.log(JSON.stringify(selector.take()) !== JSON.stringify(resultObj));
|
|
||||||
|
|
||||||
// => true
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
selector.value(jsonObj);
|
|
||||||
selector.replaceWith((v) => {
|
|
||||||
v.age = v.age * 2;
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
|
|
||||||
let resultObj = {
|
|
||||||
'school': {
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구1', 'age': 40},
|
|
||||||
{'name': '친구2', 'age': 40},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구3', 'age': 30},
|
|
||||||
{'name': '친구4'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
console.log(JSON.stringify(selector.take()) !== JSON.stringify(resultObj));
|
|
||||||
|
|
||||||
// => true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.select(json: string|object, jsonpath: string)</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
let selectAsString = jsonpath.select(JSON.stringify(jsonObj), '$..friends[0]');
|
|
||||||
let selectAsObj = jsonpath.select(jsonObj, '$..friends[0]');
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
JSON.stringify(ret) == JSON.stringify(selectAsString),
|
|
||||||
JSON.stringify(ret) == JSON.stringify(selectAsObj)
|
|
||||||
);
|
|
||||||
|
|
||||||
// => true, true
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.compile(jsonpath: string)</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let template = jsonpath.compile('$..friends[0]');
|
|
||||||
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selectAsString = template(JSON.stringify(jsonObj));
|
|
||||||
let selectAsObj = template(jsonObj);
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
JSON.stringify(ret) == JSON.stringify(selectAsString),
|
|
||||||
JSON.stringify(ret) == JSON.stringify(selectAsObj)
|
|
||||||
);
|
|
||||||
|
|
||||||
// => true, true
|
|
||||||
|
|
||||||
let jsonObj2 = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "Millicent Norman"},
|
|
||||||
{"name": "Vincent Cannon"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [ {"age": 30}, {"age": 40} ]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret2 = [
|
|
||||||
{"age": 30},
|
|
||||||
{"name": "Millicent Norman"}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selectAsString2 = template(JSON.stringify(jsonObj2));
|
|
||||||
let selectAsObj2 = template(jsonObj2);
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
JSON.stringify(ret2) == JSON.stringify(selectAsString2),
|
|
||||||
JSON.stringify(ret2) == JSON.stringify(selectAsObj2)
|
|
||||||
);
|
|
||||||
|
|
||||||
// => true, true
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.selector(json: string|object)</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret1 = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let ret2 = [
|
|
||||||
{"name": "친구4"},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selector = jsonpath.selector(jsonObj);
|
|
||||||
// or as json string
|
|
||||||
// let selector = jsonpath.selector(JSON.stringify(jsonObj));
|
|
||||||
|
|
||||||
let select1 = selector('$..friends[0]');
|
|
||||||
let select2 = selector('$..friends[1]');
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
JSON.stringify(ret1) == JSON.stringify(select1),
|
|
||||||
JSON.stringify(ret2) == JSON.stringify(select2)
|
|
||||||
);
|
|
||||||
|
|
||||||
// => true, true
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.deleteValue(json: string|object, path: string)</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let _1 = jsonpath.deleteValue(jsonObj, '$..friends[0]');
|
|
||||||
let result = jsonpath.deleteValue(_1, '$..friends[1]');
|
|
||||||
|
|
||||||
console.log(JSON.stringify(result) !== JSON.stringify({
|
|
||||||
"school": { "friends": [null, null]},
|
|
||||||
"friends": [null, null]
|
|
||||||
}));
|
|
||||||
|
|
||||||
// => true
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details><summary><b>Javascript - jsonpath.replaceWith(json: string|object, path: string, fun: function(json: object) => json: object</b></summary>
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = jsonpath.replaceWith(jsonObj, '$..friends[0]', (v) => {
|
|
||||||
v.age = v.age * 2;
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(JSON.stringify(result) === JSON.stringify({
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 40},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 60},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
|
|
||||||
// => true
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
[Javascript - Other Examples](https://github.com/freestrings/jsonpath/wiki/Javascript-examples)
|
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if ! [ -x "$(command -v rustc)" ]; then
|
|
||||||
echo "install rust"
|
|
||||||
curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
|
|
||||||
sh /tmp/rustup.sh -y
|
|
||||||
export PATH="$HOME/.cargo/bin:$PATH"
|
|
||||||
source "$HOME/.cargo/env"
|
|
||||||
fi
|
|
||||||
check-node-version --node '<12.0' && neon build --release
|
|
@ -1,149 +0,0 @@
|
|||||||
const {
|
|
||||||
CompileFn,
|
|
||||||
SelectorFn,
|
|
||||||
selectStr,
|
|
||||||
deleteValue: _deleteValue,
|
|
||||||
replaceWith: _replaceWith,
|
|
||||||
Selector: _Selector,
|
|
||||||
SelectorMut: _SelectorMut
|
|
||||||
} = require('../native');
|
|
||||||
|
|
||||||
function compile(path) {
|
|
||||||
let compile = new CompileFn(path);
|
|
||||||
return (json) => {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
return JSON.parse(compile.template(json));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function selector(json) {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
let selector = new SelectorFn(json);
|
|
||||||
return (path) => {
|
|
||||||
return JSON.parse(selector.select(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function select(json, path) {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
return JSON.parse(selectStr(json, path));
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteValue(json, path) {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
return JSON.parse(_deleteValue(json, path));
|
|
||||||
}
|
|
||||||
|
|
||||||
function replaceWith(json, path, fun) {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
let result = _replaceWith(json, path, (v) => {
|
|
||||||
let result = fun(JSON.parse(v));
|
|
||||||
if(typeof result != 'string') {
|
|
||||||
result = JSON.stringify(result)
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
if(typeof result == 'string') {
|
|
||||||
result = JSON.parse(result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Selector {
|
|
||||||
constructor() {
|
|
||||||
this._selector = new _Selector();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
path(path) {
|
|
||||||
this._selector.path(path);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
value(json) {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
this._selector.value(json);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
select() {
|
|
||||||
return JSON.parse(this._selector.select());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SelectorMut {
|
|
||||||
constructor() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
path(path) {
|
|
||||||
this._path = path;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
value(json) {
|
|
||||||
if(typeof json != 'string') {
|
|
||||||
json = JSON.stringify(json)
|
|
||||||
}
|
|
||||||
this._json = json;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteValue() {
|
|
||||||
let selector = new _SelectorMut();
|
|
||||||
if(!this._path) {
|
|
||||||
selector.emptyPathError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!this._json) {
|
|
||||||
selector.emptyValueError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._json = deleteValue(this._json, this._path);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceWith(fun) {
|
|
||||||
let selector = new _SelectorMut();
|
|
||||||
if(!this._path) {
|
|
||||||
selector.emptyPathError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!this._json) {
|
|
||||||
selector.emptyValueError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._json = replaceWith(this._json, this._path, fun);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
take() {
|
|
||||||
let json = this._json;
|
|
||||||
delete this._json;
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
compile,
|
|
||||||
selector,
|
|
||||||
select,
|
|
||||||
deleteValue,
|
|
||||||
replaceWith,
|
|
||||||
Selector,
|
|
||||||
SelectorMut
|
|
||||||
};
|
|
5
nodejs/native/.gitignore
vendored
5
nodejs/native/.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
.idea/*
|
|
||||||
.vscode
|
|
||||||
!.idea/runConfigurations/
|
|
||||||
/target/
|
|
||||||
Cargo.lock
|
|
@ -1,24 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "jsonpath4nodejs"
|
|
||||||
version = "0.2.4"
|
|
||||||
authors = ["Changseok Han <freestrings@gmail.com>"]
|
|
||||||
description = "jsonpath_lib bindings for nodejs"
|
|
||||||
keywords = ["library", "jsonpath", "json", "nodejs"]
|
|
||||||
repository = "https://github.com/freestrings/jsonpath"
|
|
||||||
license = "MIT"
|
|
||||||
|
|
||||||
build = "build.rs"
|
|
||||||
exclude = ["artifacts.json", "index.node"]
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
neon-build = "0.2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
jsonpath_lib = "0.2.3"
|
|
||||||
#jsonpath_lib = { path = "../../" }
|
|
||||||
neon = "0.2.0"
|
|
||||||
serde_json = { version = "1.0", features = ["preserve_order"] }
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "jsonpath4nodejs"
|
|
||||||
crate-type = ["dylib"]
|
|
@ -1,7 +0,0 @@
|
|||||||
extern crate neon_build;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
neon_build::setup(); // must be called in build.rs
|
|
||||||
|
|
||||||
// add project-specific build logic here...
|
|
||||||
}
|
|
@ -1,268 +0,0 @@
|
|||||||
extern crate jsonpath_lib as jsonpath;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate neon;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
use jsonpath::{JsonPathError, Node, Parser, Selector};
|
|
||||||
use neon::prelude::*;
|
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
fn select_str(mut ctx: FunctionContext) -> JsResult<JsValue> {
|
|
||||||
let json_val = ctx.argument::<JsString>(0)?.value();
|
|
||||||
let path = ctx.argument::<JsString>(1)?.value();
|
|
||||||
match jsonpath::select_as_str(&json_val, path.as_str()) {
|
|
||||||
Ok(value) => Ok(JsString::new(&mut ctx, &value).upcast()),
|
|
||||||
Err(e) => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete(mut ctx: FunctionContext) -> JsResult<JsValue> {
|
|
||||||
let json_val = ctx.argument::<JsString>(0)?.value();
|
|
||||||
let json: Value = match serde_json::from_str(&json_val) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
};
|
|
||||||
let path = ctx.argument::<JsString>(1)?.value();
|
|
||||||
match jsonpath::delete(json, &path) {
|
|
||||||
Ok(value) => Ok(JsString::new(
|
|
||||||
&mut ctx,
|
|
||||||
match serde_json::to_string(&value) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.upcast()),
|
|
||||||
Err(e) => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn replace_with(mut ctx: FunctionContext) -> JsResult<JsValue> {
|
|
||||||
let json_val = ctx.argument::<JsString>(0)?.value();
|
|
||||||
let json: Value = match serde_json::from_str(&json_val) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
};
|
|
||||||
let path = ctx.argument::<JsString>(1)?.value();
|
|
||||||
let fun = ctx.argument::<JsFunction>(2)?;
|
|
||||||
match jsonpath::replace_with(json, &path, &mut |v| {
|
|
||||||
let json_str = JsString::new(
|
|
||||||
&mut ctx,
|
|
||||||
match serde_json::to_string(v) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
let null = ctx.null();
|
|
||||||
let args = vec![ctx.string(json_str.value())];
|
|
||||||
let result = match fun.call(&mut ctx, null, args) {
|
|
||||||
Ok(result) => result,
|
|
||||||
Err(e) => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
let json_str = match result.downcast::<JsString>() {
|
|
||||||
Ok(v) => v.value(),
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
};
|
|
||||||
match serde_json::from_str(&json_str) {
|
|
||||||
Ok(v) => v,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Ok(value) => Ok(JsString::new(
|
|
||||||
&mut ctx,
|
|
||||||
match serde_json::to_string(&value) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.upcast()),
|
|
||||||
Err(e) => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SelectorCls {
|
|
||||||
node: Option<Node>,
|
|
||||||
value: Option<Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SelectorCls {
|
|
||||||
fn path(&mut self, path: &str) {
|
|
||||||
let node = match Parser::compile(path) {
|
|
||||||
Ok(node) => node,
|
|
||||||
Err(e) => panic!("{:?}", e),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.node = Some(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn value(&mut self, json_str: &str) {
|
|
||||||
let value: Value = match serde_json::from_str(&json_str) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string())),
|
|
||||||
};
|
|
||||||
|
|
||||||
self.value = Some(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn select(&self) -> String {
|
|
||||||
let node = match &self.node {
|
|
||||||
Some(node) => node,
|
|
||||||
None => panic!("{:?}", JsonPathError::EmptyPath),
|
|
||||||
};
|
|
||||||
|
|
||||||
let value = match &self.value {
|
|
||||||
Some(value) => value,
|
|
||||||
None => panic!("{:?}", JsonPathError::EmptyValue),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut selector = Selector::new();
|
|
||||||
selector.compiled_path(node);
|
|
||||||
selector.value(&value);
|
|
||||||
match selector.select_as_str() {
|
|
||||||
Ok(ret) => ret,
|
|
||||||
Err(e) => panic!("{:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct SelectorMutCls {}
|
|
||||||
|
|
||||||
declare_types! {
|
|
||||||
pub class JsCompileFn for SelectorCls {
|
|
||||||
init(mut ctx) {
|
|
||||||
let path = ctx.argument::<JsString>(0)?.value();
|
|
||||||
let node = match Parser::compile(path.as_str()) {
|
|
||||||
Ok(node) => node,
|
|
||||||
Err(e) => panic!("{:?}", e)
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(SelectorCls { node: Some(node), value: None })
|
|
||||||
}
|
|
||||||
|
|
||||||
method template(mut ctx) {
|
|
||||||
let mut this = ctx.this();
|
|
||||||
|
|
||||||
let json_str = ctx.argument::<JsString>(0)?.value();
|
|
||||||
{
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let mut this = this.borrow_mut(&guard);
|
|
||||||
let value: Value = match serde_json::from_str(&json_str) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string()))
|
|
||||||
};
|
|
||||||
this.value = Some(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
let result_str = {
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let this = this.borrow(&guard);
|
|
||||||
this.select()
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(JsString::new(&mut ctx, &result_str).upcast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub class JsSelectorFn for SelectorCls {
|
|
||||||
init(mut ctx) {
|
|
||||||
let json_str = ctx.argument::<JsString>(0)?.value();
|
|
||||||
let value: Value = match serde_json::from_str(&json_str) {
|
|
||||||
Ok(value) => value,
|
|
||||||
Err(e) => panic!("{:?}", JsonPathError::Serde(e.to_string()))
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(SelectorCls { node: None, value: Some(value) })
|
|
||||||
}
|
|
||||||
|
|
||||||
method select(mut ctx) {
|
|
||||||
let mut this = ctx.this();
|
|
||||||
|
|
||||||
let path = ctx.argument::<JsString>(0)?.value();
|
|
||||||
{
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let mut this = this.borrow_mut(&guard);
|
|
||||||
this.path(&path);
|
|
||||||
}
|
|
||||||
|
|
||||||
let result_str = {
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let this = this.borrow(&guard);
|
|
||||||
this.select()
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(JsString::new(&mut ctx, &result_str).upcast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub class JsSelector for SelectorCls {
|
|
||||||
init(mut _ctx) {
|
|
||||||
Ok(SelectorCls { node: None, value: None })
|
|
||||||
}
|
|
||||||
|
|
||||||
method path(mut ctx) {
|
|
||||||
let mut this = ctx.this();
|
|
||||||
|
|
||||||
let path = ctx.argument::<JsString>(0)?.value();
|
|
||||||
{
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let mut this = this.borrow_mut(&guard);
|
|
||||||
this.path(&path);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(JsUndefined::new().upcast())
|
|
||||||
}
|
|
||||||
|
|
||||||
method value(mut ctx) {
|
|
||||||
let mut this = ctx.this();
|
|
||||||
|
|
||||||
let json_str = ctx.argument::<JsString>(0)?.value();
|
|
||||||
{
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let mut this = this.borrow_mut(&guard);
|
|
||||||
this.value(&json_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(JsUndefined::new().upcast())
|
|
||||||
}
|
|
||||||
|
|
||||||
method select(mut ctx) {
|
|
||||||
let this = ctx.this();
|
|
||||||
|
|
||||||
let result_str = {
|
|
||||||
let guard = ctx.lock();
|
|
||||||
let this = this.borrow(&guard);
|
|
||||||
this.select()
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(JsString::new(&mut ctx, &result_str).upcast())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub class JsSelectorMut for SelectorMutCls {
|
|
||||||
init(mut _ctx) {
|
|
||||||
Ok(SelectorMutCls {})
|
|
||||||
}
|
|
||||||
|
|
||||||
method emptyPathError(mut _ctx) {
|
|
||||||
panic!("{:?}", JsonPathError::EmptyPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
method emptyValueError(mut _ctx) {
|
|
||||||
panic!("{:?}", JsonPathError::EmptyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
register_module!(mut m, {
|
|
||||||
m.export_class::<JsCompileFn>("CompileFn")
|
|
||||||
.expect("CompileFn class error");
|
|
||||||
m.export_class::<JsSelectorFn>("SelectorFn")
|
|
||||||
.expect("SelectorFn class error");
|
|
||||||
m.export_class::<JsSelector>("Selector")
|
|
||||||
.expect("Selector class error");
|
|
||||||
m.export_class::<JsSelectorMut>("SelectorMut")
|
|
||||||
.expect("SelectorMut class error");
|
|
||||||
m.export_function("deleteValue", delete)?;
|
|
||||||
m.export_function("replaceWith", replace_with)?;
|
|
||||||
m.export_function("selectStr", select_str)?;
|
|
||||||
Ok(())
|
|
||||||
});
|
|
1484
nodejs/package-lock.json
generated
1484
nodejs/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,35 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "jsonpath-rs",
|
|
||||||
"version": "0.2.4",
|
|
||||||
"description": "It is JsonPath implementation. The core implementation is written in Rust",
|
|
||||||
"author": "Changseok Han <freestrings@gmail.com>",
|
|
||||||
"license": "MIT",
|
|
||||||
"keywords": [
|
|
||||||
"jsonpath",
|
|
||||||
"native-addon",
|
|
||||||
"rust-binding",
|
|
||||||
"rust",
|
|
||||||
"json",
|
|
||||||
"parsing"
|
|
||||||
],
|
|
||||||
"main": "lib/index.js",
|
|
||||||
"dependencies": {
|
|
||||||
"check-node-version": "*",
|
|
||||||
"neon-cli": "^0.2.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"install": "./build.sh",
|
|
||||||
"test": "mocha"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"mocha": "^6.1.4"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/freestrings/jsonpath.git"
|
|
||||||
},
|
|
||||||
"engineStrict": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">=8.0 <12.0"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,928 +0,0 @@
|
|||||||
const jsonpath = require('../lib/index.js');
|
|
||||||
|
|
||||||
let jsonObj = {
|
|
||||||
"store": {
|
|
||||||
"book": [
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"bicycle": {
|
|
||||||
"color": "red",
|
|
||||||
"price": 19.95
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"expensive": 10
|
|
||||||
};
|
|
||||||
|
|
||||||
let list = {
|
|
||||||
'$.store.book[*].author': [
|
|
||||||
"Nigel Rees",
|
|
||||||
"Evelyn Waugh",
|
|
||||||
"Herman Melville",
|
|
||||||
"J. R. R. Tolkien"
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..author':[
|
|
||||||
"Nigel Rees",
|
|
||||||
"Evelyn Waugh",
|
|
||||||
"Herman Melville",
|
|
||||||
"J. R. R. Tolkien"
|
|
||||||
],
|
|
||||||
|
|
||||||
'$.store.*': [
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
{
|
|
||||||
"color": "red",
|
|
||||||
"price": 19.95
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$.store..price':[
|
|
||||||
8.95,
|
|
||||||
12.99,
|
|
||||||
8.99,
|
|
||||||
22.99,
|
|
||||||
19.95
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[2]': [
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[-2]': [
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[0,1]': [
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[:2]': [
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[1:2]': [
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[-2:]': [
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[2:]': [
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[?(@.isbn)]': [
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$.store.book[?(@.price < 10)]': [
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..*': [
|
|
||||||
{
|
|
||||||
"book": [
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"bicycle": {
|
|
||||||
"color": "red",
|
|
||||||
"price": 19.95
|
|
||||||
}
|
|
||||||
},
|
|
||||||
10,
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
}
|
|
||||||
],
|
|
||||||
{
|
|
||||||
"color": "red",
|
|
||||||
"price": 19.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Evelyn Waugh",
|
|
||||||
"title": "Sword of Honour",
|
|
||||||
"price": 12.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "J. R. R. Tolkien",
|
|
||||||
"title": "The Lord of the Rings",
|
|
||||||
"isbn": "0-395-19395-8",
|
|
||||||
"price": 22.99
|
|
||||||
},
|
|
||||||
"reference",
|
|
||||||
"Nigel Rees",
|
|
||||||
"Sayings of the Century",
|
|
||||||
8.95,
|
|
||||||
"fiction",
|
|
||||||
"Evelyn Waugh",
|
|
||||||
"Sword of Honour",
|
|
||||||
12.99,
|
|
||||||
"fiction",
|
|
||||||
"Herman Melville",
|
|
||||||
"Moby Dick",
|
|
||||||
"0-553-21311-3",
|
|
||||||
8.99,
|
|
||||||
"fiction",
|
|
||||||
"J. R. R. Tolkien",
|
|
||||||
"The Lord of the Rings",
|
|
||||||
"0-395-19395-8",
|
|
||||||
22.99,
|
|
||||||
"red",
|
|
||||||
19.95
|
|
||||||
],
|
|
||||||
|
|
||||||
'$..book[ ?( (@.price < 13 || $.store.bicycle.price < @.price) && @.price <=10 ) ]': [
|
|
||||||
{
|
|
||||||
"category": "reference",
|
|
||||||
"author": "Nigel Rees",
|
|
||||||
"title": "Sayings of the Century",
|
|
||||||
"price": 8.95
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"category": "fiction",
|
|
||||||
"author": "Herman Melville",
|
|
||||||
"title": "Moby Dick",
|
|
||||||
"isbn": "0-553-21311-3",
|
|
||||||
"price": 8.99
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('compile test', () => {
|
|
||||||
it('basic', (done) => {
|
|
||||||
let template = jsonpath.compile('$.a');
|
|
||||||
let result = template({'a': 1});
|
|
||||||
if (result[0] === 1) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('selector test', () => {
|
|
||||||
it('basic', (done) => {
|
|
||||||
let selector = jsonpath.selector({'a': 1});
|
|
||||||
let result = selector('$.a');
|
|
||||||
if (result[0] === 1) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('select test', () => {
|
|
||||||
it('basic', (done) => {
|
|
||||||
let result = jsonpath.select({'a': 1}, '$.a');
|
|
||||||
if (result[0] === 1) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('filter test', () => {
|
|
||||||
|
|
||||||
function run(done, path, expected) {
|
|
||||||
let result = jsonpath.select(jsonObj, path);
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(expected)) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for( var i in list ) {
|
|
||||||
it(i, (done) => {
|
|
||||||
run (done, i, list[i]);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
it('object equal', (done) => {
|
|
||||||
let selector = new jsonpath.Selector();
|
|
||||||
selector.path('$..[?(@.a == 1)]');
|
|
||||||
selector.value({
|
|
||||||
'a': 1,
|
|
||||||
'b': {'a': 1},
|
|
||||||
'c': {'a': 1},
|
|
||||||
});
|
|
||||||
let result = selector.select();
|
|
||||||
if (JSON.stringify(result) === JSON.stringify([{'a': 1}, {'a': 1}])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('escaped single quote notation', (done) => {
|
|
||||||
let result = jsonpath.select({"single'quote":"value"}, "$['single\\'quote']");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["value"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('escaped double quote notation', (done) => {
|
|
||||||
let result = jsonpath.select({"single\"quote":"value"}, "$['single\"quote']");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["value"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[::]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[::]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["first", "second", "third", "forth", "fifth"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[::2]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[::2]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["first", "third", "fifth"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[1: :]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1: :]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["second", "third", "forth", "fifth"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[1:2:]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1:2:]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["second"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[1::2]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[1::2]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["second", "forth"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[0:3:1]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[0:3:1]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["first", "second", "third"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array range with step - $[0:3:2]', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second", "third", "forth", "fifth"], "$[0:3:2]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["first", "third"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('array keys', (done) => {
|
|
||||||
let result = jsonpath.select({
|
|
||||||
"key1": "value1",
|
|
||||||
"key2": 2
|
|
||||||
}, "$['key1', 'key2']");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["value1", 2])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('SelectorMut test', () => {
|
|
||||||
it('delete', (done) => {
|
|
||||||
let jsonObjNew = JSON.parse(JSON.stringify(jsonObj));
|
|
||||||
let result = jsonpath.deleteValue(jsonObjNew, '$.store.book');
|
|
||||||
if (JSON.stringify(result) === JSON.stringify({
|
|
||||||
'store': {
|
|
||||||
'book': null,
|
|
||||||
'bicycle': {
|
|
||||||
'color': 'red',
|
|
||||||
'price': 19.95,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'expensive': 10,
|
|
||||||
})) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('replaceWith', (done) => {
|
|
||||||
let jsonObjNew = JSON.parse(JSON.stringify(jsonObj));
|
|
||||||
let result = jsonpath.replaceWith(jsonObjNew, '$.store.book', (v) => {
|
|
||||||
let ret = v[0];
|
|
||||||
ret.price = 9;
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
if (JSON.stringify(result) === JSON.stringify({
|
|
||||||
'store': {
|
|
||||||
'book': {
|
|
||||||
'category': 'reference',
|
|
||||||
'author': 'Nigel Rees',
|
|
||||||
'title': 'Sayings of the Century',
|
|
||||||
'price': 9,
|
|
||||||
},
|
|
||||||
'bicycle': {
|
|
||||||
'color': 'red',
|
|
||||||
'price': 19.95,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'expensive': 10,
|
|
||||||
})) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('SeletorMut delete', (done) => {
|
|
||||||
let jsonObjNew = JSON.parse(JSON.stringify(jsonObj));
|
|
||||||
let selector = new jsonpath.SelectorMut();
|
|
||||||
selector.path('$.store.book').value(jsonObjNew).deleteValue();
|
|
||||||
|
|
||||||
let result = selector.take();
|
|
||||||
if (JSON.stringify(result) === JSON.stringify({
|
|
||||||
'store': {
|
|
||||||
'book': null,
|
|
||||||
'bicycle': {
|
|
||||||
'color': 'red',
|
|
||||||
'price': 19.95,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'expensive': 10,
|
|
||||||
})) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('SeletorMut replaceWith', (done) => {
|
|
||||||
let jsonObjNew = JSON.parse(JSON.stringify(jsonObj));
|
|
||||||
let selector = new jsonpath.SelectorMut();
|
|
||||||
selector.path('$.store.book').value(jsonObjNew).replaceWith((v) => {
|
|
||||||
let ret = v[0];
|
|
||||||
ret.price = 9;
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
|
|
||||||
let result = selector.take();
|
|
||||||
if (JSON.stringify(result) === JSON.stringify({
|
|
||||||
'store': {
|
|
||||||
'book': {
|
|
||||||
'category': 'reference',
|
|
||||||
'author': 'Nigel Rees',
|
|
||||||
'title': 'Sayings of the Century',
|
|
||||||
'price': 9,
|
|
||||||
},
|
|
||||||
'bicycle': {
|
|
||||||
'color': 'red',
|
|
||||||
'price': 19.95,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'expensive': 10,
|
|
||||||
})) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Selector test', () => {
|
|
||||||
it('select', (done) => {
|
|
||||||
let selector = new jsonpath.Selector().value(jsonObj);
|
|
||||||
for(var i in list) {
|
|
||||||
if(JSON.stringify(list[i]) !== JSON.stringify(selector.path(i).select())) {
|
|
||||||
throw `fail: ${i}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('README test', () => {
|
|
||||||
it('jsonpath.Selector', (done) => {
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let selector = new jsonpath.Selector().value(jsonObj);
|
|
||||||
|
|
||||||
{
|
|
||||||
let jsonObj = selector.path('$..[?(@.age >= 30)]').select();
|
|
||||||
let resultObj = [{"name": "친구3", "age": 30}];
|
|
||||||
if(JSON.stringify(jsonObj) !== JSON.stringify(resultObj)) {
|
|
||||||
throw 'jsonpath.Selector: $..[?(@.age >= 30)]';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let jsonObj = selector.path('$..[?(@.age == 20)]').select();
|
|
||||||
let resultObj = [{"name": "친구1", "age": 20}, {"name": "친구2", "age": 20}];
|
|
||||||
if(JSON.stringify(jsonObj) !== JSON.stringify(resultObj)) {
|
|
||||||
throw 'jsonpath.Selector: $..[?(@.age >= 20)]';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let jsonObj = selector.value({"friends": [ {"name": "친구5", "age": 20} ]}).select();
|
|
||||||
let resultObj = [{"name": "친구5", "age": 20}];
|
|
||||||
if(JSON.stringify(jsonObj) !== JSON.stringify(resultObj)) {
|
|
||||||
throw 'jsonpath.Selector: change value';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('jsonpath.SelectorMut', (done) => {
|
|
||||||
let jsonObj = {
|
|
||||||
'school': {
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구1', 'age': 20},
|
|
||||||
{'name': '친구2', 'age': 20},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구3', 'age': 30},
|
|
||||||
{'name': '친구4'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
let selector = new jsonpath.SelectorMut();
|
|
||||||
selector.path('$..[?(@.age == 20)]');
|
|
||||||
|
|
||||||
{
|
|
||||||
selector.value(jsonObj).deleteValue();
|
|
||||||
|
|
||||||
let resultObj = {
|
|
||||||
'school': {'friends': [null, null]},
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구3', 'age': 30},
|
|
||||||
{'name': '친구4'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
if (JSON.stringify(selector.take()) !== JSON.stringify(resultObj)) {
|
|
||||||
throw 'jsonpath.SelectorMut.deleteValue';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
selector.value(jsonObj).replaceWith((v) => {
|
|
||||||
v.age = v.age * 2;
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
|
|
||||||
let resultObj = {
|
|
||||||
'school': {
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구1', 'age': 40},
|
|
||||||
{'name': '친구2', 'age': 40},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'friends': [
|
|
||||||
{'name': '친구3', 'age': 30},
|
|
||||||
{'name': '친구4'},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
if (JSON.stringify(selector.take()) !== JSON.stringify(resultObj)) {
|
|
||||||
throw 'jsonpath.SelectorMut.replaceWith';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('jsonpath.select(json: string|object, jsonpath: string)', (done) => {
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
let selectAsString = jsonpath.select(JSON.stringify(jsonObj), '$..friends[0]');
|
|
||||||
let selectAsObj = jsonpath.select(jsonObj, '$..friends[0]');
|
|
||||||
|
|
||||||
if(
|
|
||||||
JSON.stringify(ret) !== JSON.stringify(selectAsString) ||
|
|
||||||
JSON.stringify(ret) !== JSON.stringify(selectAsObj)
|
|
||||||
) {
|
|
||||||
throw 'jsonpath.select(json: string|object, jsonpath: string)';
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('jsonpath.compile(jsonpath: string)', (done) => {
|
|
||||||
let template = jsonpath.compile('$..friends[0]');
|
|
||||||
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selectAsString = template(JSON.stringify(jsonObj));
|
|
||||||
let selectAsObj = template(jsonObj);
|
|
||||||
|
|
||||||
if(
|
|
||||||
JSON.stringify(ret) !== JSON.stringify(selectAsString) ||
|
|
||||||
JSON.stringify(ret) !== JSON.stringify(selectAsObj)
|
|
||||||
) {
|
|
||||||
throw 'jsonpath.compile(jsonpath: string) 1';
|
|
||||||
}
|
|
||||||
|
|
||||||
let jsonObj2 = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "Millicent Norman"},
|
|
||||||
{"name": "Vincent Cannon"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [ {"age": 30}, {"age": 40} ]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret2 = [
|
|
||||||
{"age": 30},
|
|
||||||
{"name": "Millicent Norman"}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selectAsString2 = template(JSON.stringify(jsonObj2));
|
|
||||||
let selectAsObj2 = template(jsonObj2);
|
|
||||||
|
|
||||||
if(
|
|
||||||
JSON.stringify(ret2) !== JSON.stringify(selectAsString2) ||
|
|
||||||
JSON.stringify(ret2) !== JSON.stringify(selectAsObj2)
|
|
||||||
) {
|
|
||||||
throw 'jsonpath.compile(jsonpath: string) 2';
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('jsonpath.selector(json: string|object)', (done) => {
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let ret1 = [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구1", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let ret2 = [
|
|
||||||
{"name": "친구4"},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
];
|
|
||||||
|
|
||||||
let selector = jsonpath.selector(jsonObj);
|
|
||||||
let select1 = selector('$..friends[0]');
|
|
||||||
let select2 = selector('$..friends[1]');
|
|
||||||
|
|
||||||
if(
|
|
||||||
JSON.stringify(ret1) !== JSON.stringify(select1) ||
|
|
||||||
JSON.stringify(ret2) !== JSON.stringify(select2)
|
|
||||||
) {
|
|
||||||
throw 'jsonpath.selector(json: string|object)';
|
|
||||||
}
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('jsonpath.deleteValue(json: string|object, path: string)', (done) => {
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let _1 = jsonpath.deleteValue(jsonObj, '$..friends[0]');
|
|
||||||
let result = jsonpath.deleteValue(_1, '$..friends[1]');
|
|
||||||
|
|
||||||
if(JSON.stringify(result) === JSON.stringify({
|
|
||||||
"school": { "friends": [null, null]},
|
|
||||||
"friends": [null, null]
|
|
||||||
})) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('jsonpath.replaceWith(json: string|object, path: string, fun: function(json: object) => json: object', (done) => {
|
|
||||||
let jsonObj = {
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 20},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 30},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = jsonpath.replaceWith(jsonObj, '$..friends[0]', (v) => {
|
|
||||||
v.age = v.age * 2;
|
|
||||||
return v;
|
|
||||||
});
|
|
||||||
|
|
||||||
if(JSON.stringify(result) === JSON.stringify({
|
|
||||||
"school": {
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구1", "age": 40},
|
|
||||||
{"name": "친구2", "age": 20}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"friends": [
|
|
||||||
{"name": "친구3", "age": 60},
|
|
||||||
{"name": "친구4"}
|
|
||||||
]
|
|
||||||
})) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('ISSUE test', () => {
|
|
||||||
it('Results do not match other implementations #6', (done) => {
|
|
||||||
let result = jsonpath.select(["first", "second"], "$[:]");
|
|
||||||
if (JSON.stringify(result) === JSON.stringify(["first", "second"])) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Invalid wildcard filter results #7', (done) => {
|
|
||||||
|
|
||||||
function select(json, expected, paths) {
|
|
||||||
for (var i = 0 ; i < paths.length ; i++) {
|
|
||||||
let result = jsonpath.select(json, paths[i]);
|
|
||||||
if (JSON.stringify(result) !== JSON.stringify(expected)) {
|
|
||||||
throw Error("Error: " + paths[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
select(
|
|
||||||
["string", 42, { "key": "value" }, [0, 1]],
|
|
||||||
["string", 42, { "key": "value" }, [0, 1]],
|
|
||||||
["$.*", "$[*]"]
|
|
||||||
);
|
|
||||||
|
|
||||||
select(
|
|
||||||
["string", 42, { "key": "value" }, [0, 1]],
|
|
||||||
[ "string", 42, { "key" : "value" }, [ 0, 1 ], "value", 0, 1 ],
|
|
||||||
["$..*", "$..[*]"]
|
|
||||||
);
|
|
||||||
|
|
||||||
select(
|
|
||||||
["string", 42, { "key": "value" }, [0, 1]],
|
|
||||||
["value", 0, 1],
|
|
||||||
["$.*.*", "$[*].*", "$.*[*]", "$[*][*]"]
|
|
||||||
);
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
@ -132,7 +132,7 @@ extern crate serde_json;
|
|||||||
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
pub use parser::Parser;
|
pub use parser::Parser; // TODO private
|
||||||
pub use select::JsonPathError;
|
pub use select::JsonPathError;
|
||||||
pub use select::{Selector, SelectorMut};
|
pub use select::{Selector, SelectorMut};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user