JavaScript parser for SVG path's d attribute
npm install d-path-parserd-path-parser
=============
JavaScript parser for SVG 's d attribute.


d attribute is compact and expressive, but unfortunately it's also
d-path-parser is less than 1K), and 6x-10x slower depending on the input (the longer, the slower) and the environment.
d-path-parser also has 100%
npm/yarn:
bash
npm install d-path-parser
yarn add d-path-parser
`
Via bower;
`bash
bower install d-path-parser
`
Usage
As a CommonJS package:
`javascript
const parse = require("d-path-parser");
const path = "M0,0 l10,10 A14.142 14.142 0 1 1 10,-10 Z";
const commands = parse(path);
`
This will yield the following result:
`javascript
[{
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"
}]
`
The parser can also be loaded via AMD (define([ "d-path-parser", ... ], function(parse) { ... })) and, if no module loader is
detected, a global function dPathParse will be defined.
Gotchas
d-path-parser does not assume the given string is the full path string of a d attribute. In short, it won't throw if the
first command is not a moveTo.
Tests
Mocha and Chai are used for tests. Just run npm test (or mocha` if it's globally