Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

svg-parser

Rich-Harris32.9mMIT2.0.4TypeScript support: definitely-typed

Create a JSON-friendly object from an SVG string

SVG, parser, JSON, object

readme

svg-parser

Take a string representing an SVG document or fragment, turn it into HAST JavaScript object.

Installation

npm install svg-parser, or grab it from npmcdn.com/svg-parser.

Usage

import { parse } from 'svg-parser';

const parsed = parse( `
    <svg viewBox='0 0 100 100'>
        <!-- stuff goes here... -->
    </svg>
` );
/*
{
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'svg',
      properties: {
        viewBox: '0 0 100 100'
      },
      children: [...]
    }
  ]
}
*/

License

MIT

changelog

svg-parser changelog

2.0.3

  • Fix reported error location (#9)

2.0.2

  • Allow underscores in attribute names (#4)

2.0.1

  • Fix empty/space attributes

2.0.0

  • Migrate to HAST

1.0.6

  • Remove unused dependency

1.0.5

  • Handle doctype and CDATA

1.0.4

  • Handle unexpected end of input

1.0.3

  • Prevent infinite loops on bad final closing tag

1.0.2

  • Prevent ""=true attributes

1.0.1

  • Allow attributes with numbers (e.g. x1)
  • Fix error messages

1.0.0

  • First release