diff --git a/README.md b/README.md index 01608d4..2b0d1e7 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/benchmark/index.js b/benchmark/index.js index a2c2f6e..31ff30c 100644 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -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') @@ -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() diff --git a/package-lock.json b/package-lock.json index c6ace07..accfc7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "camaro", - "version": "2.1.0", + "version": "2.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 471d056..8aaee05 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/transform.cpp b/src/transform.cpp index dafba59..103b25e 100644 --- a/src/transform.cpp +++ b/src/transform.cpp @@ -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