mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-04-24 17:02:16 +00:00
update wasm README.md, nodejs README.md. restore nodejs build
This commit is contained in:
parent
ff52821323
commit
635b5b8d43
76
.travis.yml
76
.travis.yml
@ -36,41 +36,41 @@ matrix:
|
||||
script:
|
||||
- cargo build --verbose --all
|
||||
- cargo test --verbose --all
|
||||
# - language: node_js
|
||||
# os: linux
|
||||
# node_js:
|
||||
# - '11'
|
||||
# - '10'
|
||||
# - '9'
|
||||
# - '8'
|
||||
# before_install:
|
||||
# - curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
|
||||
# - sh /tmp/rustup.sh -y
|
||||
# - export PATH="$HOME/.cargo/bin:$PATH"
|
||||
# - source "$HOME/.cargo/env"
|
||||
# - npm install -g neon-cli
|
||||
# - cd nodejs
|
||||
# - node -v
|
||||
# - npm -v
|
||||
# - npm install
|
||||
# script:
|
||||
# - npm test
|
||||
# - language: node_js
|
||||
# os: osx
|
||||
# node_js:
|
||||
# - '11'
|
||||
# - '10'
|
||||
# - '9'
|
||||
# - '8'
|
||||
# before_install:
|
||||
# - curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
|
||||
# - sh /tmp/rustup.sh -y
|
||||
# - export PATH="$HOME/.cargo/bin:$PATH"
|
||||
# - source "$HOME/.cargo/env"
|
||||
# - npm install -g neon-cli
|
||||
# - cd nodejs
|
||||
# - node -v
|
||||
# - npm -v
|
||||
# - npm install
|
||||
# script:
|
||||
# - npm test
|
||||
- language: node_js
|
||||
os: linux
|
||||
node_js:
|
||||
- '11'
|
||||
- '10'
|
||||
- '9'
|
||||
- '8'
|
||||
before_install:
|
||||
- curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
|
||||
- sh /tmp/rustup.sh -y
|
||||
- export PATH="$HOME/.cargo/bin:$PATH"
|
||||
- source "$HOME/.cargo/env"
|
||||
- npm install -g neon-cli
|
||||
- cd nodejs
|
||||
- node -v
|
||||
- npm -v
|
||||
- npm install
|
||||
script:
|
||||
- npm test
|
||||
- language: node_js
|
||||
os: osx
|
||||
node_js:
|
||||
- '11'
|
||||
- '10'
|
||||
- '9'
|
||||
- '8'
|
||||
before_install:
|
||||
- curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
|
||||
- sh /tmp/rustup.sh -y
|
||||
- export PATH="$HOME/.cargo/bin:$PATH"
|
||||
- source "$HOME/.cargo/env"
|
||||
- npm install -g neon-cli
|
||||
- cd nodejs
|
||||
- node -v
|
||||
- npm -v
|
||||
- npm install
|
||||
script:
|
||||
- npm test
|
@ -470,8 +470,6 @@ console.log(JSON.stringify(ret) == JSON.stringify(retObj));
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.SelectorMut class</b></summary>
|
||||
|
||||
`since 0.2.0`
|
||||
|
||||
빌더 패턴 제약은 `Selector class`와 동일하다.
|
||||
|
||||
```javascript
|
||||
@ -675,8 +673,6 @@ console.log(
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.deleteValue(json: string|object, path: string)</b></summary>
|
||||
|
||||
`since 0.2.0`
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
"school": {
|
||||
@ -707,8 +703,6 @@ console.log(JSON.stringify(result) !== JSON.stringify({
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.replaceWith(json: string|object, path: string, fun: function(json: object) => json: object</b></summary>
|
||||
|
||||
`since 0.2.0`
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
"school": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "bench_bin"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
|
||||
[dependencies]
|
||||
jsonpath_lib = {path = "../../"}
|
||||
|
197
nodejs/README.md
197
nodejs/README.md
@ -16,13 +16,15 @@ Build from source instead of using pre-built binary, and if Rust is not installe
|
||||
|
||||
## APIs
|
||||
|
||||
* [jsonpath.Selector](#jsonpathselector)
|
||||
* [jsonpath.select(json: string|object, jsonpath: string)](#jsonpathselectjson-stringobject-jsonpath-string)
|
||||
* [jsonpath.compile(jsonpath: string)](#jsonpathcompilejsonpath-string)
|
||||
* [jsonpath.selector(json: string|object)](#jsonpathselectorjson-stringobject)
|
||||
* [Other Examples](https://github.com/freestrings/jsonpath/wiki/Javascript-examples)
|
||||
<details><summary><b>npm package</b></summary>
|
||||
|
||||
### jsonpath.Selector
|
||||
```javascript
|
||||
const jsonpath = require('jsonpath-rs');
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.Selector class</b></summary>
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
@ -38,44 +40,89 @@ let jsonObj = {
|
||||
]
|
||||
};
|
||||
|
||||
let selector = new jsonpath.Selector().value(jsonObj);
|
||||
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)]');
|
||||
|
||||
{
|
||||
let jsonObj = selector.path('$..[?(@.age >= 30)]').selectAs();
|
||||
let resultObj = [{"name": "친구3", "age": 30}];
|
||||
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
|
||||
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
|
||||
}
|
||||
|
||||
{
|
||||
let jsonObj = selector.path('$..[?(@.age == 20)]').selectAs();
|
||||
let resultObj = [{"name": "친구1", "age": 20}, {"name": "친구2", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
|
||||
}
|
||||
|
||||
{
|
||||
let jsonObj = selector.value({"friends": [ {"name": "친구5", "age": 20} ]}).selectAs();
|
||||
let resultObj = [{"name": "친구5", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
|
||||
}
|
||||
|
||||
{
|
||||
let jsonObj1 = selector.value(jsonObj).map(function(v) {
|
||||
let f1 = v[0];
|
||||
f1.age = 30;
|
||||
selector.value(jsonObj);
|
||||
selector.replaceWith((v) => {
|
||||
v.age = v.age * 2;
|
||||
return v;
|
||||
}).get();
|
||||
});
|
||||
|
||||
let resultObj1 = [{"name": "친구1", "age": 30}, {"name": "친구2", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj1) === JSON.stringify(resultObj1));
|
||||
|
||||
selector.path('$..[?(@.age == 20)]');
|
||||
let jsonObj2 = selector.selectAs();
|
||||
let resultObj2 = [{"name": "친구2", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj2) === JSON.stringify(resultObj2));
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
### jsonpath.select(json: string|object, jsonpath: string)
|
||||
</details>
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.select(json: string|object, jsonpath: string)</b></summary>
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
@ -108,7 +155,9 @@ console.log(
|
||||
// => true, true
|
||||
```
|
||||
|
||||
### jsonpath.compile(jsonpath: string)
|
||||
</details>
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.compile(jsonpath: string)</b></summary>
|
||||
|
||||
```javascript
|
||||
let template = jsonpath.compile('$..friends[0]');
|
||||
@ -166,8 +215,10 @@ console.log(
|
||||
|
||||
// => true, true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### jsonpath.selector(json: string|object)
|
||||
<details><summary><b>Javascript - jsonpath.selector(json: string|object)</b></summary>
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
@ -207,3 +258,77 @@ console.log(
|
||||
|
||||
// => 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,6 +1,6 @@
|
||||
{
|
||||
"name": "jsonpath-rs",
|
||||
"version": "0.1.11",
|
||||
"version": "0.2.0",
|
||||
"description": "It is JsonPath implementation. The core implementation is written in Rust",
|
||||
"author": "Changseok Han <freestrings@gmail.com>",
|
||||
"license": "MIT",
|
||||
|
200
wasm/README.md
200
wasm/README.md
@ -6,19 +6,24 @@ It is Webassembly version of [jsonpath_lib](https://github.com/freestrings/jsonp
|
||||
|
||||
## APIs
|
||||
|
||||
* [jsonpath.Selector](#jsonpathselector)
|
||||
* [jsonpath.select(json: string|object, jsonpath: string)](#jsonpathselectjson-stringobject-jsonpath-string)
|
||||
* [jsonpath.compile(jsonpath: string)](#jsonpathcompilejsonpath-string)
|
||||
* [jsonpath.selector(json: string|object)](#jsonpathselectorjson-stringobject)
|
||||
* [Other Examples](https://github.com/freestrings/jsonpath/wiki/Javascript-examples)
|
||||
|
||||
### jsonpath.Selector
|
||||
|
||||
> The selectTo function is deprecated since 0.1.3. please use the selectAs function instead.
|
||||
<details><summary><b>npm package</b></summary>
|
||||
|
||||
```javascript
|
||||
let jsonpath = require('jsonpath-wasm');
|
||||
// browser
|
||||
import * as jsonpath from "jsonpath-wasm";
|
||||
// NodeJs
|
||||
const jsonpath = require('jsonpath-wasm');
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.Selector class</b></summary>
|
||||
|
||||
`wasm-bindgen` 리턴 타입 제약 때문에 빌더 패턴은 지원하지 않는다.
|
||||
|
||||
It does not support `builder-pattern` due to the `return type` restriction of `wasm-bindgen`.
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
"school": {
|
||||
"friends": [
|
||||
@ -32,48 +37,89 @@ let jsonObj = {
|
||||
]
|
||||
};
|
||||
|
||||
let ret = [
|
||||
{"name": "친구3", "age": 30},
|
||||
{"name": "친구1", "age": 20}
|
||||
];
|
||||
|
||||
let selector = new jsonpath.Selector();
|
||||
selector.path('$..friends[0]');
|
||||
selector.value(jsonObj);
|
||||
|
||||
{
|
||||
selector.path('$..[?(@.age >= 30)]');
|
||||
let jsonObj = selector.selectAs();
|
||||
let resultObj = [{"name": "친구3", "age": 30}];
|
||||
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
|
||||
}
|
||||
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.path('$..[?(@.age == 20)]');
|
||||
let jsonObj = selector.selectAs();
|
||||
let resultObj = [{"name": "친구1", "age": 20}, {"name": "친구2", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
|
||||
}
|
||||
selector.value(jsonObj);
|
||||
selector.deleteValue();
|
||||
|
||||
{
|
||||
selector.value({"friends": [ {"name": "친구5", "age": 20} ]});
|
||||
let jsonObj = selector.selectAs();
|
||||
let resultObj = [{"name": "친구5", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
|
||||
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.map(function(v) {
|
||||
let f1 = v[0];
|
||||
f1.age = 30;
|
||||
selector.replaceWith((v) => {
|
||||
v.age = v.age * 2;
|
||||
return v;
|
||||
});
|
||||
let resultObj1 = [{"name": "친구1", "age": 30}, {"name": "친구2", "age": 20}];
|
||||
console.log(JSON.stringify(selector.get()) === JSON.stringify(resultObj1));
|
||||
|
||||
selector.path('$..[?(@.age == 20)]');
|
||||
let jsonObj1 = selector.selectAs();
|
||||
let resultObj2 = [{"name": "친구2", "age": 20}];
|
||||
console.log(JSON.stringify(jsonObj1) === JSON.stringify(resultObj2));
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
### jsonpath.select(json: string|object, jsonpath: string)
|
||||
</details>
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.select(json: string|object, jsonpath: string)</b></summary>
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
@ -106,7 +152,9 @@ console.log(
|
||||
// => true, true
|
||||
```
|
||||
|
||||
### jsonpath.compile(jsonpath: string)
|
||||
</details>
|
||||
|
||||
<details><summary><b>Javascript - jsonpath.compile(jsonpath: string)</b></summary>
|
||||
|
||||
```javascript
|
||||
let template = jsonpath.compile('$..friends[0]');
|
||||
@ -164,8 +212,10 @@ console.log(
|
||||
|
||||
// => true, true
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### jsonpath.selector(json: string|object)
|
||||
<details><summary><b>Javascript - jsonpath.selector(json: string|object)</b></summary>
|
||||
|
||||
```javascript
|
||||
let jsonObj = {
|
||||
@ -205,3 +255,77 @@ console.log(
|
||||
|
||||
// => 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,6 +1,6 @@
|
||||
{
|
||||
"name": "jsonpath-wasm-evaluator",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jsonpath-wasm-bench",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
|
Loading…
x
Reference in New Issue
Block a user