{"name":"camaro","version":"6.5.0","keywords":["xpath","json","transform","pugixml","xml","parser","n-api","xml2json","webassembly","wasm"],"author":{"url":"https://tuananh.org","name":"Tuan Anh Tran","email":"me@tuananh.org"},"license":"MIT","_id":"camaro@6.5.0","maintainers":[{"name":"tuananh","email":"me@tuananh.org"}],"homepage":"https://github.com/tuananh/camaro","bugs":{"url":"https://github.com/tuananh/camaro/issues"},"dist":{"shasum":"59a1508cab2ace9d15c20dbd55639fa799499fce","tarball":"http://registry-npm.ywwl.com/camaro/download/camaro-6.5.0.tgz","fileCount":12,"integrity":"sha512-qfYDf+w5LBOVLPl6jECuhf5F1YgMDUh5AuVMsF0MAKQCqEW3wp4YLJpfY2P2/iLG+3GwoXzpyRjzYIcXx/eqfw==","signatures":[{"sig":"MEYCIQDePd6jGIOrx3CQ0JlzAJYV5a5e4QnwVk8G0EbbWh5ZxgIhALVLhh3IUTpsuxw3YQw9Dj9teluirDckQGY38j7pEVNI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/camaro@6.5.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":329603,"size":120617,"noattachment":false,"key":"/camaro/-/camaro-6.5.0.tgz"},"main":"index.js","napa":{"json":"nlohmann/json#v3.12.0","pugixml":"tuananh/pugixml#2e2283336364c2a55e07b6384334f64a09f3f8b0","fifo_map":"nlohmann/fifo_map#v1.0.1"},"engines":{"node":">= 20.x"},"exports":{".":{"types":"./index.d.ts","import":"./index.mjs","require":"./index.js"}},"gitHead":"ce562c9dee002577fdc94faefce11bf3ea53111f","scripts":{"test":"tape test/*.test.js","build":"docker run --rm -v $(pwd):/src emscripten/emsdk:6.0.0 ./build.sh","gen-esm":"gen-esm-wrapper . ./index.mjs","bench:all":"node benchmark/transform.js","install-deps":"napa","bench:to-json":"node benchmark/to-json.js","bench:baseline":"node benchmark/baseline.js"},"typings":"index.d.ts","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:9ec278d5-0438-416c-a453-968c1b0cd105"}},"repository":{"url":"git+https://github.com/tuananh/camaro.git","type":"git"},"_npmVersion":"11.13.0","description":"Transforming XML to JSON using Node.js binding to native pugixml parser library","directories":{},"napa-config":{"cache":false},"_nodeVersion":"24.16.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"napa":"^3.0.0","tape":"^5.4.0","txml":"^6.0.0","mitata":"^1.0.34","xml-js":"^1.6.11","xml2js":"^0.6.0","fast-xml-parser":"^5.2.5","gen-esm-wrapper":"^1.1.3"},"_npmOperationalInternal":{"tmp":"tmp/camaro_6.5.0_1782308623257_0.9661852799153556","host":"s3://npm-registry-packages-npm-production"},"readme":"# camaro\n\n> camaro is a Node.js library that transform XML to JSON, using Node.js bindings to a native XML parser [pugixml](http://pugixml.org/) - one of the fastest XML parsers around.\n\n[![npm](https://raster.shields.io/npm/v/camaro)](https://npm.im/camaro)\n![Build status](https://github.com/tuananh/camaro/actions/workflows/ci.yaml/badge.svg)\n[![npm](https://raster.shields.io/npm/dt/camaro)](https://npm.im/camaro)\n[![license](https://raster.shields.io/npm/l/camaro)](https://npm.im/camaro)\n\n## 🤘 Features\n\n* Transform XML to JSON: transform only properties you're interested in. Output is ready to use JS object.\n\n* Written in C++ and compiled down to WebAssembly, so no re-compilation needed.\n\n* Works on all major platforms (Linux, macOS, Windows).\n\n* It's pretty fast on large XML strings. We leverage [pugixml](http://pugixml.org) through our own fork.\n\n* Scale well with multi-core processors by the use of `worker_threads` pool.\n\n## 🔥 Benchmark\n\n```\nbenchmark                   avg (min … max) p75 / p99    (min … top 1%)\n------------------------------------------- -------------------------------\ncamaro v6                     98.94 µs/iter  97.94 µs █▆\n                     (93.24 µs … 358.99 µs) 140.47 µs ██\n                    (280.00  b … 537.55 kb)  11.69 kb ██▅▅▄▂▂▂▁▁▁▁▁▂▁▁▁▁▁▁\n\ntxml                         491.71 µs/iter 485.85 µs █\n                      (478.64 µs … 845.79 µs) 737.81 µs █▄\n                    ( 13.47 kb …   1.15 mb) 307.81 kb ██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁\n\nfast-xml-parser                2.63 ms/iter   2.59 ms  █\n                        (2.32 ms … 4.78 ms)   4.14 ms ▂█▇▂\n                    (101.15 kb …   4.24 mb)   2.44 mb ████▃▁▂▁▁▁▂▂▂▂▂▃▂▁▂▂▁\n\nxml2js                         3.58 ms/iter   3.51 ms █\n                        (3.45 ms … 5.20 ms)   4.56 ms █▇\n                    (193.28 kb …   3.18 mb)   1.74 mb ██▃▁▂▂▁▁▂▃▁▂▁▂▂▁▁▁▁▁\n\nxml-js                         2.49 ms/iter   2.47 ms  █\n                        (2.43 ms … 3.05 ms)   2.94 ms  █▃\n                    (422.69 kb …   1.87 mb)   1.26 mb ▂██▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁\n\nsummary\n  camaro v6\n   5.27x faster than txml\n   25.78x faster than xml-js\n   24.21x faster than fast-xml-parser\n   37.02x faster than xml2js\n```\n\nThe XML file is an actual XML response from the Expedia API. I just deleted some nodes to change its size for benchmarking.\n\nFor complete benchmark, see [benchmark](benchmark/).\n\n* Please note that **this is an unfair game for camaro** because it only transforms the fields specified in the template.\nThe whole reason for me creating this is because most of the time, I'm just interested in some of the data in the whole XML mess.\n* 🚧 Performance on small XML strings will probably be worse than pure JavaScript implementations. If your use cases consists of small XML strings only, you probably don't need this.\n\n![intro](intro.png)\n\n## Installation\n\n```sh\npnpm 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 starts 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`, `string-join` or `raw`. Eventually, I'm hoping to add all XPath 2.0 functions but these are all that I need for now. PRs are welcome.\n\nThe rest are pretty much vanilla XPath 1.0.\n\nFor complete API documentation, please see [API.md](API.md)\n\nAdditional examples can be found in the [examples](examples/) folder or this comprehensive [blog post](https://mdleom.com/blog/2020/01/20/how-to-use-camaro-xml/) by Ming Di Leom.\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    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## Similar projects\n\n- [cruftless](https://github.com/wspringer/cruftless): I personally find this project very fascinating. Its template engine is more powerful than camaro's XPath-based perhaps. You should check it out.\n\n## Used by\n\n- https://github.com/dsifford/academic-bloggers-toolkit\n- https://github.com/hexojs/hexo-generator-sitemap\n- https://github.com/hexojs/hexo-generator-feed\n- https://github.com/hexojs/hexo-migrator-wordpress\n- https://github.com/fengkx/NodeRSSBot\n\n...\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/tuananh/camaro.svg)](https://starchart.cc/tuananh/camaro)\n\n## Licence\n\n[The MIT License](LICENSE)\n","publish_time":1782308623491,"_cnpm_publish_time":1782308623491,"dist-tags":{"latest":"6.7.3","legacy-v3":"3.0.20","next":"6.5.0-rc4","oldv3":"3.0.19"}}