SVG Path D Attribute Parser

1.0.0 · abandoned · verified Tue Apr 21

d-path-parser is a JavaScript library designed to parse the 'd' attribute of SVG `<path>` elements. Its current and only stable version is 1.0.0, released in 2016. The package is lightweight (under 1KB minified and gzipped) and engineered for performance, distinguishing itself from alternatives like `svg-path-parser` by being significantly smaller and faster (6-10x faster depending on input length) while maintaining 100% test coverage. It provides a structured breakdown of SVG path commands, facilitating easier debugging, reading, and manipulation of complex path data. The library supports CommonJS, AMD, and exposes a global function if no module loader is detected. Due to its last update being in 2016, the project is considered abandoned.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import and use the `d-path-parser` library to parse an SVG path string, showing the resulting array of command objects.

const parse = require('d-path-parser');

const path1 = "M0,0 l10,10 A14.142 14.142 0 1 1 10,-10 Z";
const commands1 = parse(path1);
console.log('Parsed Path 1:', JSON.stringify(commands1, null, 2));

const path2 = "m10 10c10-10 20-10 30 0";
const commands2 = parse(path2);
console.log('\nParsed Path 2:', JSON.stringify(commands2, null, 2));

/* Example of output for path1:
[
  {
    "code": "M",
    "relative": false,
    "end": {
      "x": 0,
      "y": 0
    }
  },
  {
    "code": "l",
    "relative": true,
    "end": {
      "x": 10,
      "y": 10
    }
  },
  {
    "code": "A",
    "relative": false,
    "radii": {
      "x": 14.142,
      "y": 14.142
    },
    "rotation": 0,
    "large": true,
    "clockwise": true,
    "end": {
      "x": 10,
      "y": -10
    }
  },
  {
    "code": "Z"
  }
]*/

view raw JSON →