Skip to content

Commit

Permalink
Merge branch 'release/4.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuananh committed Aug 13, 2019
2 parents 2298490 + 331c995 commit acd9ef0
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 130 deletions.
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,32 @@

* [Issues](#issues)
* [Pull Requests](#pull-requests)
* [Setup development environmment](#setup-development-environment)

## Issues

* State version of node/camaro/OS.
* Include the script which can reproduce the issue.
* Include a minimal script which can reproduce the issue.

## Pull Requests

* Make sure all tests pass.
* If new feature(s) is included, write test(s) for them as well.
* Check the benchmark script to see if there's any performance regression.

## Setup development environment

It's easier to have Docker installed for development.

```sh
npm install

# for fetching c++ dependencies using napa
npm run install-deps

# use docker to build. if you don't have Docker installed, you can use build.sh script
npm run build

# tests
npm run test
```
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
## 🔥 Benchmark

```
camaro x 287 ops/sec ±0.74% (79 runs sampled)
rapidx2j x 233 ops/sec ±0.49% (87 runs sampled)
xml2json x 50.36 ops/sec ±1.08% (65 runs sampled)
xml2js x 40.71 ops/sec ±8.94% (56 runs sampled)
fast-xml-parser x 227 ops/sec ±1.07% (88 runs sampled)
xml-js x 38.52 ops/sec ±7.82% (53 runs sampled)
camaro x 362 ops/sec ±0.31% (87 runs sampled)
rapidx2j x 226 ops/sec ±0.27% (88 runs sampled)
xml2json x 46.32 ops/sec ±1.39% (61 runs sampled)
xml2js x 50.51 ops/sec ±7.22% (68 runs sampled)
fast-xml-parser x 256 ops/sec ±0.63% (86 runs sampled)
xml-js x 45.05 ops/sec ±6.19% (61 runs sampled)
```

* Please note that **this is an unfair game for camaro** because it only transform those fields specified in template.
Expand Down
22 changes: 13 additions & 9 deletions benchmark/index.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
# Benchmark

Never mind about the actual number. You can check the percentage differences between package for reference.

Benchmark ran on AMZ Ryzen 3800X.

## transform()

`node benchmark/transform`

```
camaro x 287 ops/sec ±0.74% (79 runs sampled)
rapidx2j x 233 ops/sec ±0.49% (87 runs sampled)
xml2json x 50.36 ops/sec ±1.08% (65 runs sampled)
xml2js x 40.71 ops/sec ±8.94% (56 runs sampled)
fast-xml-parser x 227 ops/sec ±1.07% (88 runs sampled)
xml-js x 38.52 ops/sec ±7.82% (53 runs sampled)
camaro x 362 ops/sec ±0.31% (87 runs sampled)
rapidx2j x 226 ops/sec ±0.27% (88 runs sampled)
xml2json x 46.32 ops/sec ±1.39% (61 runs sampled)
xml2js x 50.51 ops/sec ±7.22% (68 runs sampled)
fast-xml-parser x 256 ops/sec ±0.63% (86 runs sampled)
xml-js x 45.05 ops/sec ±6.19% (61 runs sampled)
```

## prettyPrint()

`node benchmark/pretty-print`

```
camaro x 201,493 ops/sec ±1.25% (77 runs sampled)
pretty-data x 132,456 ops/sec ±3.72% (85 runs sampled)
prettify-xml x 199,420 ops/sec ±1.45% (91 runs sampled)
camaro x 274,438 ops/sec ±0.56% (87 runs sampled)
pretty-data x 155,168 ops/sec ±0.82% (94 runs sampled)
prettify-xml x 244,450 ops/sec ±0.28% (94 runs sampled)
```
8 changes: 4 additions & 4 deletions dist/camaro.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/camaro.wasm
Binary file not shown.
96 changes: 96 additions & 0 deletions examples/array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
## Transform to array

```xml
<root>
<items>
<item>
<name>item 1</name>
<value>value 1</value>
</item>
<item>
<name>item 2</name>
<value>value 2</value>
</item>
<item>
<name>item 3</name>
<value>value 3</value>
</item>
<item>
<name>item 4</name>
<value>value 4</value>
</item>
</items>
</root>
```

### Example 1

```js
const { transform } = require('camaro')

;(async function() {
const template = {
items: ['/root/items/item', {
name: 'name',
value: 'value'
}]
}

const result = await transform(xml, template)
console.log(JSON.stringify(result, null, 2))
})()
```

Output:
```
{
"items": [
{
"name": "item 1",
"value": "value 1"
},
{
"name": "item 2",
"value": "value 2"
},
{
"name": "item 3",
"value": "value 3"
},
{
"name": "item 4",
"value": "value 4"
}
]
}
```


### Example 2

Getting just names only as array of name string

```js
const { transform } = require('camaro')

;(async function() {
const template = {
names: ['/root/items/item', 'name']
}

const result = await transform(xml, template)
console.log(JSON.stringify(result, null, 2))
})()
```

Output:
```
{
"names": [
"item 1",
"item 2",
"item 3",
"item 4"
]
}
```
43 changes: 43 additions & 0 deletions examples/default-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Default value if a path value is empty

Related issue: [#78](https://github.com/tuananh/camaro/issues/78)

```js
const { transform } = require('camaro')

const xml = `
<items>
<item>hello</item>
<item />
<item>world</item>
</items>
`
const textOrDefault = (defaultValue) => `concat(
text(),
substring(
"${defaultValue}",
1,
number(not(text())) * string-length("${defaultValue}")
)
)`
const template = {
items: ['//items/item', textOrDefault('my default val')]
}

;(async function main() {
const output = await transform(xml, template)
console.log(JSON.stringify(output, null, 4))
})();
```

Output

```json
{
"items": [
"hello",
"my default val",
"world"
]
}
```
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type transform = <T = any>(xml: string, template: object) => T;
type toJson = <T = any>(xml: string) => T;
type prettyPrint = <T = any>(xml: string) => T;
declare const camaro: { transform, toJson, prettyPrint };
export = camaro;
declare const camaro: { transform: transform, toJson: toJson, prettyPrint: prettyPrint };
export = camaro;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "camaro",
"version": "4.0.5",
"version": "4.0.6",
"description": "Transforming XML to JSON using Node.js binding to native pugixml parser library",
"homepage": "https://github.com/tuananh/camaro",
"bugs": "https://github.com/tuananh/camaro/issues",
Expand Down
Loading

0 comments on commit acd9ef0

Please sign in to comment.