Skip to content

Commit

Permalink
Merge branch 'release/2.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
tuananh committed Oct 28, 2017
2 parents bd564c7 + 6d80f7b commit 2425fc4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ xml2js x 32.90 ops/sec ±8.11% (59 runs sampled)
fast-xml-parser x 154 ops/sec ±4.06% (64 runs sampled)
nkit4nodejs x 80.14 ops/sec ±2.99% (68 runs sampled)
xml-js x 28.51 ops/sec ±8.18% (53 runs sampled)
libxmljs x 107 ops/sec ±18.57% (48 runs sampled)
```

* Please note that this is an unfair game for camaro because it only transform what it needs.
Expand Down Expand Up @@ -88,6 +89,12 @@ By default, a path `'//HotelSummary'` will transform all `HotelSummary` elements

'//HotelSummary[namespace-uri() = "http://v3.hotel.wsapi.ean.com"]'

## Using camaro on AWS Lambda

In order to use `camaro` on AWS Lambda, you should download a copy of prebuilt camaro from [Releases](https://github.com/tuananh/camaro/releases) and put to this folder path `node_modules/camaro/lib/binding/camaro.node`.

As of currently, AWS Lambda only supports node 6 on Linux so you're looking for `camaro-v2.1.0-node-v48-linux-x64.tar.gz`.

## Licence

The MIT License
Expand Down
5 changes: 5 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const xml2js = require('xml2js').parseString
const fastXmlParser = require('fast-xml-parser')
const nkit = require('nkit4nodejs')
const xmljs = require('xml-js')
const libxmljs = require("libxmljs")

const suite = new benchmark.Suite()
const xml = fs.readFileSync('examples/ean.xml', 'utf-8')
Expand Down Expand Up @@ -74,6 +75,10 @@ suite.add('xml-js', function() {
const result = xmljs.xml2json(xml, {compact: true, spaces: 2})
})

suite.add('libxmljs', function() {
const xmlDoc = libxmljs.parseXml(xml)
})

suite.on('cycle', cycle)
suite.run()

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

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": "2.1.0",
"version": "2.1.2",
"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
29 changes: 10 additions & 19 deletions src/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,44 @@ inline char charAt(string& str, size_t pos) {

ReturnType get_return_type(string& path) {
const char ch = charAt(path, 0);
ReturnType t = T_STRING;
switch (ch) {
case 'b':
if (string_contains(path, "boolean(")) {
return T_BOOLEAN;
} else {
return T_STRING;
t = T_BOOLEAN;
}
break;
case 'c':
if (string_contains(path, "count(") || string_contains(path, "ceiling(")) {
return T_NUMBER;
} else {
return T_STRING;
t = T_NUMBER;
}
break;
case 'f':
if (string_contains(path, "floor(")) {
return T_NUMBER;
} else {
return T_STRING;
t = T_NUMBER;
}
break;
case 'n':
if (string_contains(path, "number(")) {
return T_NUMBER;
} else {
return T_STRING;
t = T_NUMBER;
}
break;
case 'r':
if (string_contains(path, "round(")) {
return T_NUMBER;
} else {
return T_STRING;
t = T_NUMBER;
}
break;
case 's':
if (string_contains(path, "sum(")) {
return T_NUMBER;
} else {
return T_STRING;
t = T_NUMBER;
}
break;
default:
return T_STRING;
t = T_STRING;
break;
}

return t;
}

template <typename T>
Expand Down

0 comments on commit 2425fc4

Please sign in to comment.