Skip to content

Commit

Permalink
update wasm README.md, nodejs README.md. restore nodejs build
Browse files Browse the repository at this point in the history
  • Loading branch information
freestrings committed Jun 11, 2019
1 parent ff52821 commit 635b5b8
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 120 deletions.
76 changes: 38 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion benches/bench_bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bench_bin"
version = "0.1.1"
version = "0.2.0"

[dependencies]
jsonpath_lib = {path = "../../"}
Expand Down
195 changes: 160 additions & 35 deletions nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -38,44 +40,89 @@ let jsonObj = {
]
};

let selector = new jsonpath.Selector().value(jsonObj);
let ret = [
{"name": "친구3", "age": 30},
{"name": "친구1", "age": 20}
];

{
let jsonObj = selector.path('$..[?(@.age >= 30)]').selectAs();
let resultObj = [{"name": "친구3", "age": 30}];
console.log(JSON.stringify(jsonObj) === JSON.stringify(resultObj));
}
let selector = new jsonpath.Selector()
.path('$..friends[0]')
.value(jsonObj);

{
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 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.value({"friends": [ {"name": "친구5", "age": 20} ]}).selectAs();
let resultObj = [{"name": "친구5", "age": 20}];
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 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 = {
Expand Down Expand Up @@ -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]');
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT",
Expand Down
Loading

0 comments on commit 635b5b8

Please sign in to comment.