
Security News
Insecure Agents Podcast: How to Keep AI Agents From Bypassing Security Controls
Socket CTO Ahmad Nassri discusses how to keep AI agents from bypassing package blocks, limit credential access, and monitor their actions.
parse-svg-path
Advanced tools
A minimal SVG path data parser. Returns a structured array of commands that's easy to iterate and transform.
For a more full-featured parser see hughsk/svg-path-parser, or for a streaming parser see nfroidure/SVGPathData.
npm install parse-svg-path
import parse from 'parse-svg-path'
const commands = parse('M10 20 L30 40 Z')
// [['M', 10, 20], ['L', 30, 40], ['Z']]
Each command is an array whose first element is the command letter (preserving its original case) followed by its numeric arguments.
Overloaded m/M commands — where more than 2 arguments are provided — are automatically split into an initial move followed by implicit l/L line commands:
parse('m 12.5,52 39,0 0,-40')
// [['m', 12.5, 52], ['l', 39, 0], ['l', 0, -40]]
parse(path: string): Command[]Parses an SVG path data string and returns an array of commands.
type Command = [string, ...number[]]
Throws an Error with the message "malformed path data" if a command has fewer arguments than required.
| Letter | Command | Arguments |
|---|---|---|
| M / m | Move to | x, y |
| L / l | Line to | x, y |
| H / h | Horizontal line to | x |
| V / v | Vertical line to | y |
| C / c | Cubic Bézier curve | x1, y1, x2, y2, x, y |
| S / s | Smooth cubic curve | x2, y2, x, y |
| Q / q | Quadratic Bézier | x1, y1, x, y |
| T / t | Smooth quadratic | x, y |
| A / a | Arc | rx, ry, x-rotation, large-arc, sweep, x, y |
| Z / z | Close path | — |
Uppercase letters use absolute coordinates; lowercase use relative coordinates.
npm test # run tests once
npm run test:watch # watch mode
npm run build # build dist/
Bump the version, then push — prepublishOnly runs the build automatically:
npm version patch # or minor / major
git push && git push --tags
npm publish
The svg-path-parser package provides similar functionality to parse-svg-path by converting SVG path data strings into a more structured format. It also offers additional features like converting the parsed data back into a string.
The svg-pathdata package offers a comprehensive set of tools for parsing, transforming, and encoding SVG path data. It provides more advanced manipulation capabilities compared to parse-svg-path.
The path-data-parser package is another alternative for parsing SVG path data. It focuses on providing a simple and lightweight solution for converting path data strings into a structured format.
FAQs
svg path parser
The npm package parse-svg-path receives a total of 7,081,061 weekly downloads. As such, parse-svg-path popularity was classified as popular.
We found that parse-svg-path demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Security News
Socket CTO Ahmad Nassri discusses how to keep AI agents from bypassing package blocks, limit credential access, and monitor their actions.

Security News
GPT-6 Astra tried to plant malicious code in simulated open source projects using fake GitHub accounts and deceptive PRs during an assigned CTF challenge.

Security News
upm uses Node.js to deliver fast npm installs in about 250 KB, with a JavaScript API and security defaults.