update wasm README.md, nodejs README.md. restore nodejs build

This commit is contained in:
freestrings 2019-06-11 22:16:37 +09:00
parent ff52821323
commit 635b5b8d43
8 changed files with 365 additions and 122 deletions

View File

@ -36,41 +36,41 @@ matrix:
script: script:
- cargo build --verbose --all - cargo build --verbose --all
- cargo test --verbose --all - cargo test --verbose --all
# - language: node_js - language: node_js
# os: linux os: linux
# node_js: node_js:
# - '11' - '11'
# - '10' - '10'
# - '9' - '9'
# - '8' - '8'
# before_install: before_install:
# - curl https://sh.rustup.rs -sSf > /tmp/rustup.sh - curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
# - sh /tmp/rustup.sh -y - sh /tmp/rustup.sh -y
# - export PATH="$HOME/.cargo/bin:$PATH" - export PATH="$HOME/.cargo/bin:$PATH"
# - source "$HOME/.cargo/env" - source "$HOME/.cargo/env"
# - npm install -g neon-cli - npm install -g neon-cli
# - cd nodejs - cd nodejs
# - node -v - node -v
# - npm -v - npm -v
# - npm install - npm install
# script: script:
# - npm test - npm test
# - language: node_js - language: node_js
# os: osx os: osx
# node_js: node_js:
# - '11' - '11'
# - '10' - '10'
# - '9' - '9'
# - '8' - '8'
# before_install: before_install:
# - curl https://sh.rustup.rs -sSf > /tmp/rustup.sh - curl https://sh.rustup.rs -sSf > /tmp/rustup.sh
# - sh /tmp/rustup.sh -y - sh /tmp/rustup.sh -y
# - export PATH="$HOME/.cargo/bin:$PATH" - export PATH="$HOME/.cargo/bin:$PATH"
# - source "$HOME/.cargo/env" - source "$HOME/.cargo/env"
# - npm install -g neon-cli - npm install -g neon-cli
# - cd nodejs - cd nodejs
# - node -v - node -v
# - npm -v - npm -v
# - npm install - npm install
# script: script:
# - npm test - npm test

View File

@ -470,8 +470,6 @@ console.log(JSON.stringify(ret) == JSON.stringify(retObj));
<details><summary><b>Javascript - jsonpath.SelectorMut class</b></summary> <details><summary><b>Javascript - jsonpath.SelectorMut class</b></summary>
`since 0.2.0`
빌더 패턴 제약은 `Selector class`와 동일하다. 빌더 패턴 제약은 `Selector class`와 동일하다.
```javascript ```javascript
@ -675,8 +673,6 @@ console.log(
<details><summary><b>Javascript - jsonpath.deleteValue(json: string|object, path: string)</b></summary> <details><summary><b>Javascript - jsonpath.deleteValue(json: string|object, path: string)</b></summary>
`since 0.2.0`
```javascript ```javascript
let jsonObj = { let jsonObj = {
"school": { "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> <details><summary><b>Javascript - jsonpath.replaceWith(json: string|object, path: string, fun: function(json: object) => json: object</b></summary>
`since 0.2.0`
```javascript ```javascript
let jsonObj = { let jsonObj = {
"school": { "school": {

View File

@ -1,6 +1,6 @@
[package] [package]
name = "bench_bin" name = "bench_bin"
version = "0.1.1" version = "0.2.0"
[dependencies] [dependencies]
jsonpath_lib = {path = "../../"} jsonpath_lib = {path = "../../"}

View File

@ -16,13 +16,15 @@ Build from source instead of using pre-built binary, and if Rust is not installe
## APIs ## APIs
* [jsonpath.Selector](#jsonpathselector) <details><summary><b>npm package</b></summary>
* [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 ```javascript
const jsonpath = require('jsonpath-rs');
```
</details>
<details><summary><b>Javascript - jsonpath.Selector class</b></summary>
```javascript ```javascript
let jsonObj = { 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()
let jsonObj = selector.path('$..[?(@.age >= 30)]').selectAs(); .path('$..friends[0]')
let resultObj = [{"name": "친구3", "age": 30}]; .value(jsonObj);
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
}
{ let retObj = selector.select();
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));
}
{ console.log(JSON.stringify(ret) == JSON.stringify(retObj));
let jsonObj = selector.value({"friends": [ {"name": "친구5", "age": 20} ]}).selectAs();
let resultObj = [{"name": "친구5", "age": 20}];
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
}
{ // => true
let jsonObj1 = selector.value(jsonObj).map(function(v) { ```
let f1 = v[0];
f1.age = 30;
return v;
}).get();
let resultObj1 = [{"name": "친구1", "age": 30}, {"name": "친구2", "age": 20}]; </details>
console.log(JSON.stringify(jsonObj1) === JSON.stringify(resultObj1));
<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 jsonObj2 = selector.selectAs();
let resultObj2 = [{"name": "친구2", "age": 20}]; {
console.log(JSON.stringify(jsonObj2) === JSON.stringify(resultObj2)); 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
} }
``` ```
### jsonpath.select(json: string|object, jsonpath: string) </details>
<details><summary><b>Javascript - jsonpath.select(json: string|object, jsonpath: string)</b></summary>
```javascript ```javascript
let jsonObj = { let jsonObj = {
@ -108,7 +155,9 @@ console.log(
// => true, true // => true, true
``` ```
### jsonpath.compile(jsonpath: string) </details>
<details><summary><b>Javascript - jsonpath.compile(jsonpath: string)</b></summary>
```javascript ```javascript
let template = jsonpath.compile('$..friends[0]'); let template = jsonpath.compile('$..friends[0]');
@ -167,7 +216,9 @@ console.log(
// => true, true // => true, true
``` ```
### jsonpath.selector(json: string|object) </details>
<details><summary><b>Javascript - jsonpath.selector(json: string|object)</b></summary>
```javascript ```javascript
let jsonObj = { let jsonObj = {
@ -207,3 +258,77 @@ console.log(
// => true, true // => 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)

View File

@ -1,6 +1,6 @@
{ {
"name": "jsonpath-rs", "name": "jsonpath-rs",
"version": "0.1.11", "version": "0.2.0",
"description": "It is JsonPath implementation. The core implementation is written in Rust", "description": "It is JsonPath implementation. The core implementation is written in Rust",
"author": "Changseok Han <freestrings@gmail.com>", "author": "Changseok Han <freestrings@gmail.com>",
"license": "MIT", "license": "MIT",

View File

@ -6,19 +6,24 @@ It is Webassembly version of [jsonpath_lib](https://github.com/freestrings/jsonp
## APIs ## APIs
* [jsonpath.Selector](#jsonpathselector) <details><summary><b>npm package</b></summary>
* [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.
```javascript ```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 = { let jsonObj = {
"school": { "school": {
"friends": [ "friends": [
@ -32,48 +37,89 @@ let jsonObj = {
] ]
}; };
let ret = [
{"name": "친구3", "age": 30},
{"name": "친구1", "age": 20}
];
let selector = new jsonpath.Selector(); let selector = new jsonpath.Selector();
selector.path('$..friends[0]');
selector.value(jsonObj); selector.value(jsonObj);
{ let retObj = selector.select();
selector.path('$..[?(@.age >= 30)]');
let jsonObj = selector.selectAs();
let resultObj = [{"name": "친구3", "age": 30}];
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
}
{ 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({"friends": [ {"name": "친구5", "age": 20} ]}); selector.value(jsonObj);
let jsonObj = selector.selectAs(); selector.deleteValue();
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.value(jsonObj);
selector.map(function(v) { selector.replaceWith((v) => {
let f1 = v[0]; v.age = v.age * 2;
f1.age = 30;
return v; 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 resultObj = {
let jsonObj1 = selector.selectAs(); 'school': {
let resultObj2 = [{"name": "친구2", "age": 20}]; 'friends': [
console.log(JSON.stringify(jsonObj1) === JSON.stringify(resultObj2)); {'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 ```javascript
let jsonObj = { let jsonObj = {
@ -106,7 +152,9 @@ console.log(
// => true, true // => true, true
``` ```
### jsonpath.compile(jsonpath: string) </details>
<details><summary><b>Javascript - jsonpath.compile(jsonpath: string)</b></summary>
```javascript ```javascript
let template = jsonpath.compile('$..friends[0]'); let template = jsonpath.compile('$..friends[0]');
@ -165,7 +213,9 @@ console.log(
// => true, true // => true, true
``` ```
### jsonpath.selector(json: string|object) </details>
<details><summary><b>Javascript - jsonpath.selector(json: string|object)</b></summary>
```javascript ```javascript
let jsonObj = { let jsonObj = {
@ -205,3 +255,77 @@ console.log(
// => true, true // => 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)

View File

@ -1,6 +1,6 @@
{ {
"name": "jsonpath-wasm-evaluator", "name": "jsonpath-wasm-evaluator",
"version": "0.1.0", "version": "0.2.0",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "webpack --config webpack.config.js", "build": "webpack --config webpack.config.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "jsonpath-wasm-bench", "name": "jsonpath-wasm-bench",
"version": "0.1.0", "version": "0.2.0",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "webpack --config webpack.config.js", "build": "webpack --config webpack.config.js",