{"name":"xmlbuilder2","version":"0.0.7","keywords":["xml","xmlbuilder"],"author":{"name":"Ozgur Ozcitak","email":"oozcitak@gmail.com"},"license":"MIT","_id":"xmlbuilder2@0.0.7","maintainers":[{"name":"oozcitak","email":"oozcitak@gmail.com"}],"contributors":[],"homepage":"http://github.com/oozcitak/xmlbuilder2","bugs":{"url":"http://github.com/oozcitak/xmlbuilder2/issues"},"dist":{"shasum":"30eea05a38b488d09a320489f7fa0d2683cde2fd","tarball":"http://registry-npm.ywwl.com/xmlbuilder2/download/xmlbuilder2-0.0.7.tgz","fileCount":45,"integrity":"sha512-cHM+FlLzMx0whNRGYRIHWHOnb21dkst0Sx8Ok+CC3iCnrBF4WgOU2x53tQNZJOz32WVjYsi1Ryp54iI02xkRqg==","signatures":[{"sig":"MEYCIQDW0m9ra3Mujr8R5oiD8/TIT4hjKgEZa8GF0V3JW55ovgIhAPf+pOz/29qtB0pBcr45b+QHw4VpCaepq6VBkIx9N35M","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":180468,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeHbpICRA9TVsSAnZWagAA3SYP+gOBpj5CapAx95xzwJbY\n85ojFCDM0oD4VxWarTQO8b5eYyN8lIXi4cnRqleTaV6vGlCDQ6N+7R40I9MF\nk5FDp4qvBggsT6+Y194kZV0YK0iGsjeJ9KipnQjIzk3ar8wsgKsEotH+cooz\nlYEM4jEduPncwIovnAuKHwFksjO8IHSZ/NHUT9SnYTlOrJUxlLnnZXzHvWTl\nBiGxQlHkXBbhY8Tja7jyNVarvkC91tL/sVK+3DEPivWB4HeJlfD24pyzC22s\nL2HEIYkOvMblOBu0ETAKKVnVGl54PNvnWJugrB/nabQcOYLNGHitXi8m1kZH\nk51zGyrnSKx1VbVU8wYEaLODGMim8eBvWyT0/gzEV/SRA9Oou+dvsxUERCxI\n0boDm2mZFKb8CMa6zRePIjai0OBcvyU3UqPGezp44SdDAKlWphlseTD0A7Ac\nZ1K01nopPvkw2w02aMIEZXctNtbIvwp51rI/oX2iwZGeKoms8lvAV3U6HokV\nuT2Kary8o/Qp2H1n3lONAwYL7Jis+VN9yfdRs0Q9QE9cgQivkgSZ51pWA2f5\nU+ZSNZXDaM8KylPQJK2WzvyXFtuhoWaGl4XGZdsYVT1Y7CfnCxIpAg5eOmfs\nxR9CgxIYrHyrPet3RNaZPtsQgD63bJpxO6MwdsposqRKW3furYHHG/hWt6qK\nw2O4\r\n=S2Vf\r\n-----END PGP SIGNATURE-----\r\n","size":31410,"noattachment":false,"key":"/xmlbuilder2/-/xmlbuilder2-0.0.7.tgz"},"jest":{"testRegex":"/test/.*\\.test\\.tsx?$","transform":{"^.+\\.tsx?$":"ts-jest"},"testEnvironment":"node","collectCoverageFrom":["src/**/*.{ts,tsx}"]},"main":"./lib/index","engines":{"node":">=6.0"},"gitHead":"f224bad8fb954c9fe3b83578c27e8fe60902324b","scripts":{"perf":"npm run compile && ts-node ./perf/perf.ts","test":"npm run compile && jest --coverage","compile":"rm -rf ./lib && tsc --version && tsc","publish-public":"npm run test && npm publish"},"_npmUser":{"name":"oozcitak","email":"oozcitak@gmail.com"},"repository":{"url":"git://github.com/oozcitak/xmlbuilder2.git","type":"git"},"_npmVersion":"6.8.0","description":"An XML builder for node.js","directories":{},"_nodeVersion":"12.13.1","dependencies":{"@oozcitak/dom":"1.7.1","@oozcitak/util":"4.0.0","@oozcitak/infra":"1.0.4"},"_hasShrinkwrap":false,"devDependencies":{"glob":"*","jest":"*","chalk":"*","xpath":"*","dedent":"*","ts-jest":"*","ts-node":"*","benchmark":"*","typescript":"*","xmlbuilder":"*","@types/jest":"*","@types/node":"*","@types/chalk":"*","@types/dedent":"*","@types/benchmark":"*"},"_npmOperationalInternal":{"tmp":"tmp/xmlbuilder2_0.0.7_1579006536151_0.08197523411465912","host":"s3://npm-registry-packages"},"readme":"# xmlbuilder2\n\nAn XML builder for [node.js](https://nodejs.org/).\n\n![GitHub License](https://img.shields.io/github/license/oozcitak/xmlbuilder2)\n![NPM Version](https://img.shields.io/npm/v/xmlbuilder2)\n![NPM Downloads](https://img.shields.io/npm/dm/xmlbuilder2)\n![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/xmlbuilder2)\n\n[![Node.js CI](https://github.com/oozcitak/xmlbuilder2/workflows/build/badge.svg)](https://github.com/oozcitak/xmlbuilder2/actions)\n[![Code Coverage](https://codecov.io/gh/oozcitak/xmlbuilder2/branch/master/graph/badge.svg)](https://codecov.io/gh/oozcitak/xmlbuilder2)\n\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/oozcitak)](https://github.com/sponsors/oozcitak)\n\n### Installation:\n\n``` sh\nnpm install xmlbuilder2\n```\n\n### Documentation:\n\nSee: https://oozcitak.github.io/xmlbuilder2/\n\n\n### Usage:\n\n`xmlbuilder2` is a wrapper around DOM nodes which adds chainable functions to make it easier to create and work with XML documents. For example the following XML document:\n\n``` xml\n<?xml version=\"1.0\"?>\n<root att=\"val\">\n  <foo>\n    <bar>foobar</bar>\n  </foo>\n  <baz/>\n</root>\n```\n\ncan be created with the following function chain:\n\n``` js\nconst { create } = require('xmlbuilder2');\n\nconst root = create({ version: '1.0' })\n  .ele('root', { att: 'val' })\n    .ele('foo')\n      .ele('bar').txt('foobar').up()\n    .up()\n    .ele('baz').up()\n  .up();\n\n// convert the XML tree to string\nconst xml = root.end({ prettyPrint: true });\nconsole.log(xml);\n```\n\n___\n\nThe same XML document can be created by converting a JS object into XML nodes:\n\n``` js\nconst { create } = require('xmlbuilder2');\n\nconst obj = {\n  root: {\n    '@att': 'val',\n    foo: {\n      bar: 'foobar'\n    },\n    baz: {}\n  }\n};\n\nconst doc = create(obj);\nconst xml = doc.end({ prettyPrint: true });\nconsole.log(xml);\n```\n___\n\n`xmlbuilder2` can also parse and serialize XML documents from different formats:\n```js\nconst { create } = require('xmlbuilder2');\n\nconst xmlStr = '<root att=\"val\"><foo><bar>foobar</bar></foo></root>';\nconst doc = create(xmlStr);\n\n// append a 'baz' element to the root node of the document\ndoc.root().ele('baz');\n\nconst xml = doc.end({ prettyPrint: true });\nconsole.log(xml);\n```\nwhich would output the same document string at the top of this page.\n\nOr you could return a JS object by changing the `format` argument to `'object'`:\n```js\nconst obj = doc.end({ format: 'object' });\nconsole.log(obj);\n```\n```js\n{\n  root: {\n    '@att': 'val',\n    foo: {\n      bar: 'foobar'\n    },\n    baz: {}\n  }\n}\n```\n\n___\n\nYou can convert between formats in one go with the `convert` function:\n\n```js\nconst { convert } = require('xmlbuilder2');\n\nconst xmlStr = '<root att=\"val\"><foo><bar>foobar</bar></foo></root>';\nconst obj = convert(xmlStr, { format: \"object\" });\n\nconsole.log(obj);\n```\n```js\n{\n  root: {\n    '@att': 'val',\n    foo: {\n      bar: 'foobar'\n    }\n  }\n}\n```\n\n___\n\nIf you need to do some processing:\n\n``` js\nconst { create } = require('xmlbuilder2');\n\nconst root = create().ele('squares');\nroot.com('f(x) = x^2');\nfor(let i = 1; i <= 5; i++)\n{\n  const item = root.ele('data');\n  item.att('x', i);\n  item.att('y', i * i);\n}\n\nconst xml = root.end({ prettyPrint: true });\nconsole.log(xml);\n```\n\nThis will result in:\n\n``` xml\n<?xml version=\"1.0\"?>\n<squares>\n  <!-- f(x) = x^2 -->\n  <data x=\"1\" y=\"1\"/>\n  <data x=\"2\" y=\"4\"/>\n  <data x=\"3\" y=\"9\"/>\n  <data x=\"4\" y=\"16\"/>\n  <data x=\"5\" y=\"25\"/>\n</squares>\n```\n\n### Usage in the browser:\n\nYou can build the minified production bundle (`lib/xmlbuilder2.min.js`) after cloning the repository and issuing `npx webpack` in your terminal. The bundle is also in the npm package, so you can also use a public npm CDN like [jsDelivr](https://www.jsdelivr.com/) or [unpkg](https://unpkg.com/):\n\n```html\n<!-- latest version from jsDelivr -->\n<script src=\"https://cdn.jsdelivr.net/npm/xmlbuilder2/lib/xmlbuilder2.min.js\"></script>\n<!-- latest version from unpkg -->\n<script src=\"https://unpkg.com/xmlbuilder2/lib/xmlbuilder2.min.js\"></script>\n```\n\n### Donations:\nPlease consider becoming a sponsor to help support development.\n\n[:heart: Github Sponsors](https://github.com/sponsors/oozcitak)\n","publish_time":1579006536285,"_cnpm_publish_time":1579006536285,"dist-tags":{"latest":"4.0.3"}}