
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
d-path-parser
Advanced tools
JavaScript parser for SVG <path>'s d attribute.
The syntax for the d attribute is compact and expressive, but unfortunately it's also
dramatic to debug/maintain/read. This parser gives you a breakdown of the commands in the string, ready for you to read and
manipulate.
There's another library with the same purpose around, maintained by Hugh Kennedy.
Its main feature is that's generated from a formal grammar, so that's actually pretty neat. On the down size, there's its...
size, and the fact that it's quite slow compared to this one. We're talking about 11x the size minified, 3.5 the size minified
and gzipped (d-path-parser is less than 1K), and 6x-10x slower depending on the input (the longer, the slower) and the environment.
One may argue that size and speed aren't usually important features, and they might be right. d-path-parser also has 100%
test coverage, by the way.
Via npm/yarn:
npm install d-path-parser
yarn add d-path-parser
Via bower;
bower install d-path-parser
As a CommonJS package:
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:
[{
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.
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.
Mocha and Chai are used for tests. Just run npm test (or mocha if it's globally
installed).
MIT @ Massimo Artizzu 2016. See LICENSE.
FAQs
JavaScript parser for SVG path's d attribute
The npm package d-path-parser receives a total of 951 weekly downloads. As such, d-path-parser popularity was classified as not popular.
We found that d-path-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.