Registry / serialization / svg-path-parser

svg-path-parser

JSON →
library1.1.0jsnpmunverified

svg-path-parser is a JavaScript library designed for parsing SVG `d` attribute path strings into a structured array of command objects. It is currently at version 1.1.0, with its last major update in 2020, suggesting it is in a maintenance phase rather than active development. The library provides a programmatic way to interpret complex SVG path data, converting shorthand notations (e.g., multiple consecutive `L` commands) into individual, distinct command objects. A key differentiator is its ability to convert all path commands to their absolute coordinate equivalents using the `makeAbsolute` function, which is useful for simplifying subsequent geometric calculations or transformations. It leverages a PEG.js grammar for robust parsing and is primarily designed for Node.js environments, shipping as a CommonJS module.

npm install svg-path-parser
INSTALL
IMPORT
SIG · SVG-PATH-PARSER
S
svg-path-parser
serializationjavascriptv1.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseSVG (as default export prior to v1.1.0)
✓ const parseSVG = require('svg-path-parser');
✗ import parseSVG from 'svg-path-parser';
Prior to v1.1.0, the module primarily exported the parsing function directly. This package is CommonJS-only.
parseSVG (named export)
✓ const { parseSVG } = require('svg-path-parser');
✗ import { parseSVG } from 'svg-path-parser';
Since v1.1.0, parseSVG is available as a named export. This package is CommonJS-only.
makeAbsolute
✓ const { makeAbsolute } = require('svg-path-parser');
✗ import { makeAbsolute } from 'svg-path-parser';
The makeAbsolute function was introduced in v1.1.0 and is available as a named export. This package is CommonJS-only.

Parses a complex SVG path string and then converts all commands to their absolute coordinate equivalents, logging the modified command array.

const { parseSVG, makeAbsolute } = require('svg-path-parser'); const svgPathData = 'M3,7 5-6 L1,7 1e2-.4 m-10,10 l10,0 \n V27 89 H23 v10 h10 \n C33,43 38,47 43,47 c0,5 5,10 10,10 \n S63,67 63,67 s-10,10 10,10 \n Q50,50 73,57 q20,-5 0,-10 \n T70,40 t0,-15 \n A5,5 45 1,0 40,20 a5,5 20 0,1 -10-10 Z'; // Parse the SVG path string into an array of command objects const commands = parseSVG(svgPathData); // Convert relative commands to absolute coordinates (mutates in place) makeAbsolute(commands); console.log(commands);
Debug
Known issues
breakingThe return values for parsed path commands changed significantly in v1.0.0. Command arguments are no longer grouped in an `.args` array but are instead properties directly on the command object.
fix
Update code to access command parameters directly (e.g., `command.x` instead of `command.args[0]`). Review the output format for all command types.
affects: >=1.0.0
gotchaOlder versions (pre-v0.0.4) had a bug where parsing very large SVG paths could lead to a stack overflow due to recursive grammar descriptions.
fix
Upgrade to v0.0.4 or newer to benefit from the unrolled grammar descriptions that resolve this issue.
affects: <0.0.4
gotchaVersions prior to v1.0.1 had a bug that prevented more than two subpaths from being correctly returned, truncating complex SVG paths.
fix
Upgrade to v1.0.1 or newer to ensure all subpaths in an SVG 'd' attribute are correctly parsed and returned.
affects: <1.0.1
gotchaEarly versions (pre-v0.0.2) had issues parsing non-integer numbers and incorrectly treating additional coordinates after a `moveto` as absolute `lineto` instead of relative.
fix
Upgrade to v0.0.2 or newer to ensure correct parsing of floating-point numbers and proper handling of `moveto` command sequences.
affects: <0.0.2
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'args')
Attempting to access the `args` array on a parsed command object after upgrading to `svg-path-parser` v1.0.0 or later.
fix
After v1.0.0, command arguments are direct properties on the command object (e.g., `command.x`, `command.y`). Update your code to access these properties directly instead of `command.args[index]`.
RangeError: Maximum call stack size exceeded
Parsing an extremely long or complex SVG path string with versions of `svg-path-parser` prior to v0.0.4.
fix
Upgrade `svg-path-parser` to version 0.0.4 or later, which includes a fix for this issue by unrolling recursive grammar descriptions.
Only two subpaths were returned when my SVG path string clearly has more.
A bug in versions prior to v1.0.1 prevented the correct return of more than two subpaths from a parsed SVG 'd' attribute.
fix
Upgrade `svg-path-parser` to version 1.0.1 or newer to resolve the bug and correctly retrieve all subpaths.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
svg-path-parser — npm install svg-path-parser · libregistry