{"name":"camaro","version":"6.0.0-alpha.0","description":"Transforming XML to JSON using Node.js binding to native pugixml parser library","homepage":"https://github.com/tuananh/camaro","bugs":{"url":"https://github.com/tuananh/camaro/issues"},"main":"index.js","typings":"index.d.ts","scripts":{"test":"tape test/*.test.js","bench":"node benchmark/transform.js","install-deps":"napa","build":"docker run --rm -v $(pwd):/src trzeci/emscripten ./build.sh","gen-esm":"gen-esm-wrapper . ./index.mjs"},"exports":{".":{"require":"./index.js","import":"./index.mjs"},"./":"./"},"repository":{"type":"git","url":"git+https://github.com/tuananh/camaro.git"},"keywords":["xpath","json","transform","pugixml","xml","parser","n-api","xml2json","webassembly","wasm"],"author":{"name":"Tuan Anh Tran","email":"me@tuananh.org","url":"https://tuananh.org"},"license":"MIT","napa":{"pugixml":"tuananh/pugixml#develop","json":"nlohmann/json#develop","fifo_map":"nlohmann/fifo_map#master"},"napa-config":{"cache":false},"devDependencies":{"gen-esm-wrapper":"^1.0.4","napa":"^3.0.0","tape":"^5.0.0"},"dependencies":{"piscina":"^1.4.0"},"readme":"# camaro\n\n> camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser [pugixml](http://pugixml.org/), one of the fastest XML parser around.\n\n[![npm](https://badgen.net/npm/v/camaro)](https://npm.im/camaro)\n![npm bundle size](https://badgen.net/packagephobia/publish/camaro)\n[![Build Status](https://dev.azure.com/me0499/camaro/_apis/build/status/tuananh.camaro?branchName=develop)](https://dev.azure.com/me0499/camaro/_build/latest?definitionId=1&branchName=develop)\n[![Travis](https://badgen.net/travis/tuananh/camaro/master)](https://travis-ci.org/tuananh/camaro)\n[![AppVeyor](https://badgen.net/appveyor/ci/tuananh/camaro/master)](https://ci.appveyor.com/project/tuananh/camaro)\n[![TypeScript definitions on DefinitelyTyped](https://badgen.net/badge/DefinitelyTyped/.d.ts)](http://definitelytyped.org)\n[![npm](https://badgen.net/npm/dt/camaro)](https://npm.im/camaro)\n\n[Demo on CodeSandbox.io](https://codesandbox.io/s/static-deg9w?fontsize=14)\n\n## 🤘 Features\n\n* Transform XML to JSON. Only take properties that you're interested in.\n* Output is a ready to use JS object.\n* Written in C++ and compiled down to WebAssembly so no compilation needed.\n* Work on all major platforms (OS X, Linux and Windows and the web). See Travis CI and AppVeyor build status for details.\n* No need to build binary whenever a new Node version released.\n* 🚀 Scale well with multi-core processor by use of `worker_threads` pool (Node >= 12).\n* AWS Lambda friendly (or serverless in general).\n* SUPER FAST!! We're using [pugixml](http://pugixml.org/) underneath. It's one of the fastest XML parser around.\n* Small footprint (Zero dependencies).\n* Pretty print XML.\n\n## 🔥 Benchmark\n\n```\ncamaro v6: 1,395.6 ops/sec\nfast-xml-parser: 153 ops/sec\nxml2js: 47.6 ops/sec\nxml-js: 51 ops/sec\n```\n\n* Please note that **this is an unfair game for camaro** because it only transform those fields specified in template.\nThe whole reason of me creating this is because most of the time, I'm just interested in some of the data in the whole XML mess.\n\n* Benchmark run on MacBookPro14,1 - Intel Core i5 CPU @ 2.30GHz using Node v8.10.0.\n\n* I may expose another method to transform the whole XML tree so that the benchmark will better reflect the real performance.\n\nFor complete benchmark, see [benchmark/index.md](benchmark/index.md).\n\n![intro](intro.png)\n\n## Installation\n\n```sh\nyarn add camaro\n# npm install camaro\n```\n\n## Usage\n\nYou can use our custom template format powered by [XPath](https://developer.mozilla.org/en-US/docs/Web/XPath).\n\nWe also introduce some custom syntax such as:\n\n* if a path start with `#`, that means it's a constant. E.g: `#1234` will return `1234`\n* if a path is empty, return blank\n* Some string manipulation functions which are not availble in XPath 1.0 such as `lower-case`, `upper-case`, `title-case`, `camel-case`, `snake-case` and `string-join`. Eventually, I'm hoping to add all XPath 2.0 functions but these are all that I need for now. PRs welcome.\n\nThe rest are pretty much vanilla XPath 1.0.\n\nFor complete API documentation, please see [API.md](API.md)\n\n```js\nconst { transform, prettyPrint } = require('camaro')\n\nconst xml = `\n    <players>\n        <player jerseyNumber=\"10\">\n            <name>wayne rooney</name>\n            <isRetired>false</isRetired>\n            <yearOfBirth>1985</yearOfBirth>\n        </player>\n        <player jerseyNumber=\"7\">\n            <name>cristiano ronaldo</name>\n            <isRetired>false</isRetired>\n            <yearOfBirth>1985</yearOfBirth>\n        </player>\n        <player jerseyNumber=\"7\">\n            <name>eric cantona</name>\n            <isRetired>true</isRetired>\n            <yearOfBirth>1966</yearOfBirth>\n        </player>\n    </players>\n`\n\n/**\n * the template can be an object or an array depends on what output you want the XML to be transformed to.\n * \n * ['players/player', {name, ...}] means that: Get all the nodes with this XPath expression `players/player`.\n *      - the first param is the XPath path to get all the XML nodes.\n *      - the second param is a string or an object that describe the shape of the array element and how to get it.\n * \n * For each of those XML node\n *      - call the XPath function `title-case` on field `name` and assign it to `name` field of the output.\n *      - get the attribute `jerseyNumber` from XML node player\n *      - get the `yearOfBirth` attribute from `yearOfBirth` and cast it to number.\n *      - cast `isRetired` to true if its string value equals to \"true\", and false otherwise.\n */\n\nconst template = ['players/player', {\n    name: 'title-case(name)',\n    jerseyNumber: '@jerseyNumber',\n    yearOfBirth: 'number(yearOfBirth)',\n    isRetired: 'boolean(isRetired = \"true\")'\n}]\n\n;(async function () {\n    await ready()\n    const result = await transform(xml, template)\n    console.log(result)\n\n    const prettyStr = await prettyPrint(xml, { indentSize: 4})\n    console.log(prettyStr)\n})()\n```\n\nOutput of `transform()`\n\n```\n[\n    {\n        name: 'Wayne Rooney',\n        jerseyNumber: 10,\n        yearOfBirth: 1985,\n        isRetired: false,\n    },\n    {\n        name: 'Cristiano Ronaldo',\n        jerseyNumber: 7,\n        yearOfBirth: 1985,\n        isRetired: false,\n    },\n    {\n        name: 'Eric Cantona',\n        jerseyNumber: 7,\n        yearOfBirth: 1966,\n        isRetired: true,\n    }\n]\n```\n\nAnd output of `prettyPrint()`\n\n```\n<players>\n    <player jerseyNumber=\"10\">\n        <name>Wayne Rooney</name>\n        <isRetired>false</isRetired>\n        <yearOfBirth>1985</yearOfBirth>\n    </player>\n    <player jerseyNumber=\"7\">\n        <name>Cristiano Ronaldo</name>\n        <isRetired>false</isRetired>\n        <yearOfBirth>1985</yearOfBirth>\n    </player>\n    <player jerseyNumber=\"7\">\n        <name>Eric Cantona</name>\n        <isRetired>true</isRetired>\n        <yearOfBirth>1966</yearOfBirth>\n    </player>\n</players>\n```\n\n## Licence\n\n[The MIT License](LICENSE)\n","readmeFilename":"README.md","gitHead":"152c5a9f6b8d321a5f6d0e35226366891ae02c15","_id":"camaro@6.0.0-alpha.0","_nodeVersion":"14.3.0","_npmVersion":"6.14.5","dist":{"integrity":"sha512-uoqK6fFyAE46m1p/SaJeD0RWpL8Niw6mVzvoPGkFf8Zs8n0dfqY2QTg2PwdvSzpXVcq2KWArTRGdPJpF8wuxGQ==","shasum":"9ec81d2a8e37b80218e9e47518d33734845635df","tarball":"http://registry-npm.ywwl.com/camaro/download/camaro-6.0.0-alpha.0.tgz","fileCount":8,"unpackedSize":213176,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJexJ3pCRA9TVsSAnZWagAASW0P/3KO26tAQo3D9A9PCpyq\nbRSI4dVpdBsOuz0kmJX1HPTLKTfvivu25x4CN1k5NapJZoxAdV11t1GlkokA\nmKAlNSZKfjRgX60HiLJypRk86sjJfTdtoCUFc52L7wCan5Km5zKWwbxBeKnO\nO78vHgRZXBLvjPRHV7AZAyN+pNEi942LXDbQQ4xu3660lRU+8Pqh6Tf/zQrP\nOpWt4n7Kt9H1qr/uyPP5xzHjPcJomB8OCwoV7EEqWHowTURdvyvmA8u3y077\nBcoUI4cnT7Ywl4fNM7KbfbXLARok+vfvc+/3drJJsQsb390ki2bryKBjACH2\nOGFaRHwtVqp3yWWdz/cqzT+6e+3s+xPo4BmQb1LKKdNZ08EN5JSp1rrvkyqr\nqukdsduKp/4Mta/tYB+JLjb6RHqh2VS5NTIVDUmGDjb/Xyd0vcKg75SguzCA\nmw1bdA1Cp832a7LPIqAXrECGZhpACNXqyMUw3193yhgVs6S8XjJ7Otj7q/Yw\n3cXIlaX0U/mTdbJtjL3ieQhxw+l88+TM2F1Z4Gq5EVN8H3nQUuK52bgYnF3w\nZiDe3O76jm0fYwDNi0R5GvruY7qdnOYb7NoyYgRU7yAfQPqh5pqr4+l2b6S6\nxktV/n+l51CzRG+BIArAmr3YvOg101bfH5G5QgC0ygc3D2PiBoLr/o2w8QPC\nTcoz\r\n=X4j9\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDbGh3JTehb1z/G+QP5/AWmspmTpf+Qz3/ndGnVRUZ/1gIhAOtwr1wcA0y7g6awT/iiOfVtGhAzhLDgj3z9M1rsQdKh"}],"size":74220,"noattachment":false,"key":"/camaro/-/camaro-6.0.0-alpha.0.tgz"},"maintainers":[{"name":"tuananh","email":"me@tuananh.org"}],"_npmUser":{"name":"tuananh","email":"me@tuananh.org"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/camaro_6.0.0-alpha.0_1589943785330_0.020196074303415523"},"_hasShrinkwrap":false,"publish_time":1589943785514,"_cnpm_publish_time":1589943785514,"dist-tags":{"latest":"6.7.3","legacy-v3":"3.0.20","next":"6.5.0-rc4","oldv3":"3.0.19"}}