{"id":14083,"library":"svg-path-parser","title":"SVG Path Parser","description":"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.","status":"maintenance","version":"1.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/hughsk/svg-path-parser","tags":["javascript","svg","path","d","attribute","parser","lines","drawing"],"install":[{"cmd":"npm install svg-path-parser","lang":"bash","label":"npm"},{"cmd":"yarn add svg-path-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add svg-path-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Prior to v1.1.0, the module primarily exported the parsing function directly. This package is CommonJS-only.","wrong":"import parseSVG from 'svg-path-parser';","symbol":"parseSVG (as default export prior to v1.1.0)","correct":"const parseSVG = require('svg-path-parser');"},{"note":"Since v1.1.0, parseSVG is available as a named export. This package is CommonJS-only.","wrong":"import { parseSVG } from 'svg-path-parser';","symbol":"parseSVG (named export)","correct":"const { parseSVG } = require('svg-path-parser');"},{"note":"The makeAbsolute function was introduced in v1.1.0 and is available as a named export. This package is CommonJS-only.","wrong":"import { makeAbsolute } from 'svg-path-parser';","symbol":"makeAbsolute","correct":"const { makeAbsolute } = require('svg-path-parser');"}],"quickstart":{"code":"const { parseSVG, makeAbsolute } = require('svg-path-parser');\n\nconst 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';\n\n// Parse the SVG path string into an array of command objects\nconst commands = parseSVG(svgPathData);\n\n// Convert relative commands to absolute coordinates (mutates in place)\nmakeAbsolute(commands);\n\nconsole.log(commands);","lang":"javascript","description":"Parses a complex SVG path string and then converts all commands to their absolute coordinate equivalents, logging the modified command array."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Upgrade to v0.0.4 or newer to benefit from the unrolled grammar descriptions that resolve this issue.","message":"Older 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.","severity":"gotcha","affected_versions":"<0.0.4"},{"fix":"Upgrade to v1.0.1 or newer to ensure all subpaths in an SVG 'd' attribute are correctly parsed and returned.","message":"Versions prior to v1.0.1 had a bug that prevented more than two subpaths from being correctly returned, truncating complex SVG paths.","severity":"gotcha","affected_versions":"<1.0.1"},{"fix":"Upgrade to v0.0.2 or newer to ensure correct parsing of floating-point numbers and proper handling of `moveto` command sequences.","message":"Early 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.","severity":"gotcha","affected_versions":"<0.0.2"}],"env_vars":null,"search_vec":"'1.1.0':32 '2020':39 'abil':81 'absolut':89 'activ':49 'array':23 'attribut':17,130 'calcul':103 'command':25,70,74,86 'commonj':124 'complex':59 'consecut':68 'convert':63,83 'coordin':90 'current':29 'd':16,129 'data':62 'design':12,117 'develop':50 'differenti':78 'distinct':73 'draw':133 'e.g':66 'environ':120 'equival':91 'function':95 'geometr':102 'grammar':110 'individu':72 'interpret':58 'javascript':10,126 'key':77 'l':69 'last':35 'leverag':107 'librari':11,52 'line':132 'mainten':45 'major':36 'makeabsolut':94 'modul':125 'multipl':67 'node.js':119 'notat':65 'object':26,75 'pars':14,113 'parser':3,7,131 'path':2,6,18,61,85,128 'peg.js':109 'phase':46 'primarili':116 'programmat':55 'provid':53 'rather':47 'robust':112 'ship':121 'shorthand':64 'simplifi':100 'string':19 'structur':22 'subsequ':101 'suggest':40 'svg':1,5,15,60,127 'svg-path-pars':4 'transform':105 'updat':37 'use':92,98 'version':31 'way':56","created_at":"2026-04-20T01:57:51.002206+00:00","updated_at":"2026-04-20T01:57:51.002206+00:00","problems":[{"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]`.","cause":"Attempting to access the `args` array on a parsed command object after upgrading to `svg-path-parser` v1.0.0 or later.","error":"TypeError: Cannot read properties of undefined (reading 'args')"},{"fix":"Upgrade `svg-path-parser` to version 0.0.4 or later, which includes a fix for this issue by unrolling recursive grammar descriptions.","cause":"Parsing an extremely long or complex SVG path string with versions of `svg-path-parser` prior to v0.0.4.","error":"RangeError: Maximum call stack size exceeded"},{"fix":"Upgrade `svg-path-parser` to version 1.0.1 or newer to resolve the bug and correctly retrieve all subpaths.","cause":"A bug in versions prior to v1.0.1 prevented the correct return of more than two subpaths from a parsed SVG 'd' attribute.","error":"Only two subpaths were returned when my SVG path string clearly has more."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/hughsk/svg-path-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/svg-path-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}