svg-pathstring-parser
Parse SVG pathstrings in an efficient manner.
Installation
npm install --save svg-pathstring-parser
Motivation
There are already many SVG pathstring parsers. However, most simply return the different segments without normalize data, which quickly becomes annoying when you want to perform complex actions on a list of points.
The principle of this tool is to parse the pathstring and return an array of normalized objects.
Each point has a code (the SVG command), coordinates that represent the position, and an object parameters in which there are data describing the anchors of Bezier curves or data describing arcs.
The computed coordinates are always absolute, even for relative points. This way you always know very precisely where is the current point without having to do additional calculations and add exceptions in your code.
Usage
The parsePathstring
function take a string as parameter and returns an array of objects. Each object represents a point with a code, coordinates and parameters.
Example
import parsePathstring from "svg-pathstring-parser"
const path = parsePathstring("M0 0l50,50 H100 v-50 Q150 150 200,200 t1.005e-15 2 A 50 50 0 1 0 300 300z")
License
MIT