{"name":"svg-parser","version":"2.0.5","keywords":["SVG","parser","JSON","object"],"author":{"name":"Rich Harris"},"license":"MIT","_id":"svg-parser@2.0.5","maintainers":[{"name":"trysound","email":"opensource@trysound.io"},{"name":"rich_harris","email":"richard.a.harris@gmail.com"}],"contributors":[{"name":"Bogdan Chadkin","email":"opensource@trysound.io"}],"homepage":"https://github.com/Rich-Harris/svg-parser#README","bugs":{"url":"https://github.com/Rich-Harris/svg-parser/issues"},"dist":{"shasum":"8d159c6a927f9f712462505f6e796c551abe815a","tarball":"http://registry-npm.ywwl.com/svg-parser/download/svg-parser-2.0.5.tgz","fileCount":6,"integrity":"sha512-FuT74puvVMJQ8sgFxgOKPex5MbxPeltqCXJV3wR9Xq+vPHaF+tTdE1lhJcwspUxjtjvXy1NwqcSLZx9UNwHawg==","signatures":[{"sig":"MEYCIQCuMr1xdEp2WAjMUETCIQvzzP5rDWzO7/bk0Y4u1m5aigIhAKI/6Q6I8cRHqniNvOJl0psIbM/QRe1X6J40N1oLgmuG","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQDMMZ+EQr3WZiUB5rcCzne6vkUKJwimMWoUGdl70fYJxgIhAIxEVHOeeIjq+1JChzCY61MF5R9wE/IjMjDCUmCgFCrF","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/svg-parser@2.0.5","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":40255,"size":8234,"noattachment":false,"key":"/svg-parser/-/svg-parser-2.0.5.tgz"},"main":"dist/svg-parser.umd.js","module":"dist/svg-parser.esm.js","tsdown":{"deps":{"onlyBundle":["locate-character"]},"entry":{"svg-parser":"src/index.js"},"format":{"esm":{"outputOptions":{"entryFileNames":"[name].esm.js"}},"umd":{"globalName":"svgParser","outputOptions":{"entryFileNames":"[name].umd.js"}}},"target":"es2015","platform":"browser","sourcemap":true},"engines":{"node":">=8"},"gitHead":"10a502346358d8efc60a098d6e26866219858bd8","scripts":{"lint":"oxlint src && oxfmt --check .","test":"mocha","build":"tsdown","format":"oxfmt --write .","pretest":"npm run build","prepublishOnly":"npm run lint && npm test"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:cd59258b-b3c6-4769-8b63-45b92049b345"}},"overrides":{"diff":"3.5.1","debug":"3.2.7","js-yaml":"3.15.1","minimatch":"3.1.4"},"repository":{"url":"git+https://github.com/Rich-Harris/svg-parser.git","type":"git"},"_npmVersion":"11.17.0","description":"Create a JSON-friendly object from an SVG string","directories":{},"jsnext:main":"dist/svg-parser.esm.js","_nodeVersion":"24.19.0","_hasShrinkwrap":false,"devDependencies":{"mocha":"^7.2.0","oxfmt":"^0.64.0","oxlint":"^1.79.0","tsdown":"^0.22.14","locate-character":"^2.0.5","source-map-support":"^0.4.2"},"_npmOperationalInternal":{"tmp":"tmp/svg-parser_2.0.5_1787162724724_0.5788540203790817","host":"s3://npm-registry-packages-npm-production"},"readme":"# svg-parser\n\nA small, dependency-light SVG parser that turns an SVG string into a JSON-friendly [HAST](https://github.com/syntax-tree/hast) tree.\n\n## Features\n\n- Parses complete SVG documents and standalone SVG elements\n- Supports nested and self-closing elements\n- Supports quoted, unquoted, empty, and boolean attributes\n- Preserves text and CDATA content\n- Retains XML declarations, doctypes, and other content before the root `<svg>` element as metadata\n- Reports malformed input with line, column, and source context\n- Works with ES modules, CommonJS, and browser bundlers\n\n## Installation\n\n```sh\nnpm install svg-parser\n```\n\n## Usage\n\n```js\nimport { parse } from 'svg-parser';\n\nconst tree = parse(`\n  <svg viewBox=\"0 0 100 100\" aria-hidden=\"true\">\n    <circle cx=\"50\" cy=\"50\" r=\"40\" />\n  </svg>\n`);\n\nconsole.log(tree);\n```\n\nThe result is a HAST root node:\n\n```js\n{\n  type: 'root',\n  children: [\n    {\n      type: 'element',\n      tagName: 'svg',\n      metadata: '\\n  ',\n      properties: {\n        viewBox: '0 0 100 100',\n        'aria-hidden': 'true'\n      },\n      children: [\n        {\n          type: 'element',\n          tagName: 'circle',\n          properties: {\n            cx: 50,\n            cy: 50,\n            r: 40\n          },\n          children: []\n        }\n      ]\n    }\n  ]\n}\n```\n\nNumeric attribute values are converted to numbers. Other attribute values remain strings, and attributes without a value are represented by `true`.\n\n### CommonJS\n\n```js\nconst { parse } = require('svg-parser');\n\nconst tree = parse('<path d=\"M0 0h10v10z\" />');\n```\n\n## API\n\n### `parse(source)`\n\nParses an SVG string and returns a HAST root node whose `children` array contains the parsed top-level element.\n\n```js\nconst tree = parse('<text>Hello!</text>');\n```\n\nText content is represented by HAST text nodes:\n\n```js\n{\n  type: 'root',\n  children: [\n    {\n      type: 'element',\n      tagName: 'text',\n      properties: {},\n      children: [{ type: 'text', value: 'Hello!' }]\n    }\n  ]\n}\n```\n\n### Parsing behavior\n\n- Whitespace-only text between elements is omitted.\n- Comments are ignored.\n- CDATA content is added directly to the containing element's `children` array as a string.\n- Content before a root `<svg>` element, including an XML declaration or doctype, is available on that element's `metadata` property.\n- The parser is designed for input containing one top-level element.\n\nMalformed input throws an `Error` with its zero-based line and column location and a source snippet:\n\n```js\nparse('<svg><path></svg>');\n// Error: Expected closing tag </svg> to match opening tag <path> (0:16)\n//\n// <svg><path></svg>\n//                 ^\n```\n\nSource snippets include at most one surrounding line on each side and are cropped to 80 columns. Ellipses indicate omitted content. Empty or whitespace-only input throws `Error: SVG input is empty`.\n\n## Scope\n\n`svg-parser` is a lightweight, purpose-built parser rather than a validating XML parser or DOM implementation. It is useful when you need a serializable syntax tree for common SVG markup. If you need full XML validation or browser DOM behavior, use a dedicated XML parser instead.\n\n## Development\n\n```sh\nnpm install\nnpm test       # build and run the test suite\nnpm run lint   # check source and formatting\nnpm run build  # rebuild dist/\n```\n\n## Security\n\nSee [SECURITY.md](SECURITY.md) for vulnerability reporting instructions.\n\n## License\n\nMIT\n","publish_time":1787162724809,"_cnpm_publish_time":1787162724809,"dist-tags":{"latest":"2.1.0"}}