{"_id":"svg-parser@2.1.0","bugs":{"url":"https://github.com/Rich-Harris/svg-parser/issues"},"dist":{"shasum":"f808c50953207b230fea6200d866697af61617a4","tarball":"http://registry-npm.ywwl.com/svg-parser/download/svg-parser-2.1.0.tgz","fileCount":6,"integrity":"sha512-bwLf38YmY+TDYHJw1Ex0Co8c4yeXuJAo8YnXGZrscxrvYoVVIvLeniEkV1Ks/54VteMnL4FtyN1+P+TZJdUPmQ==","signatures":[{"sig":"MEQCICF6il97mS8xZ+bcMhGMGnORHa5fsOt7mBBMFvJz/oVxAiBtUq2BslYOiyu5mOafXmIO0n7ZnyqF4XiMtR+PFYF7uw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD4fQXxwCYhcAOvRig9GHJdKwjM4jB7Xpzv6wvmbJM2SwIhANB7twsqItl4tGPNUYgcjvpaN5pp0PRso7RV9aFTNNv1"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/svg-parser@2.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":47859,"size":9487,"noattachment":false,"key":"/svg-parser/-/svg-parser-2.1.0.tgz"},"main":"dist/svg-parser.umd.js","name":"svg-parser","author":{"name":"Rich Harris"},"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":"4cdc36283a99f7b686bdf8fc56afa2561e49e6fc","license":"MIT","scripts":{"lint":"oxlint src && oxfmt --check .","test":"mocha","build":"tsdown","format":"oxfmt --write .","pretest":"npm run build","prepublishOnly":"npm run lint && npm test"},"version":"2.1.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:cd59258b-b3c6-4769-8b63-45b92049b345"}},"homepage":"https://github.com/Rich-Harris/svg-parser#README","keywords":["SVG","parser","JSON","object"],"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","maintainers":[{"name":"trysound","email":"opensource@trysound.io"},{"name":"rich_harris","email":"richard.a.harris@gmail.com"}],"_nodeVersion":"24.19.0","contributors":[{"name":"Bogdan Chadkin","email":"opensource@trysound.io"}],"_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":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/svg-parser_2.1.0_1787509967965_0.6525143914726368"},"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":1787509968040,"_cnpm_publish_time":1787509968040,"dist-tags":{"latest":"2.1.0"}}