Gathering detailed insights and metrics for svg-pathdata
Gathering detailed insights and metrics for svg-pathdata
Gathering detailed insights and metrics for svg-pathdata
Gathering detailed insights and metrics for svg-pathdata
npm install svg-pathdata
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.65%)
JavaScript (0.35%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
196 Stars
253 Commits
21 Forks
8 Watchers
6 Branches
11 Contributors
Updated on Jun 16, 2025
Latest Version
8.0.0
Package Id
svg-pathdata@8.0.0
Unpacked Size
670.24 kB
Size
117.93 kB
File Count
176
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jun 16, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Manipulate SVG path data (path[d] attribute content) simply and efficiently.
Install the module:
1npm install --save svg-pathdata
Then in your JavaScript files:
1import { 2 SVGPathData, 3 SVGPathDataTransformer, 4 SVGPathDataEncoder, 5 SVGPathDataParser, 6} from 'svg-pathdata';
1const pathData = new SVGPathData(` 2 M 10 10 3 H 60 4 V 60 5 L 10 60 6 Z`); 7 8console.log(pathData.commands); 9 10// [ {type: SVGPathData.MOVE_TO, relative: false, x: 10, y: 10}, 11// {type: SVGPathData.HORIZ_LINE_TO, relative: false, x: 60}, 12// {type: SVGPathData.VERT_LINE_TO, relative: false, y: 60}, 13// {type: SVGPathData.LINE_TO, relative: false, x: 10, y: 60}, 14// {type: SVGPathData.CLOSE_PATH}]
1const parser = new SVGPathDataParser(); 2 3parser.parse(' '); // returns [] 4parser.parse('M 10'); // returns [] 5parser.parse(' 10'); // returns [{type: SVGPathData.MOVE_TO, relative: false, x: 10, y: 10 }] 6 7parser.write('H 60'); // returns [{type: SVGPathData.HORIZ_LINE_TO, relative: false, x: 60 }] 8 9parser.write('V'); // returns [] 10parser.write('60'); // returns [{type: SVGPathData.VERT_LINE_TO, relative: false, y: 60 }] 11 12parser.write('L 10 60 \n Z'); 13// returns [ 14// {type: SVGPathData.LINE_TO, relative: false, x: 10, y: 60 }, 15// {type: SVGPathData.CLOSE_PATH }] 16 17parser.finish(); // tell parser there is no more data: will throw if there are unfinished commands.
1const pathData = new SVGPathData(` 2 M 10 10 3 H 60 4 V 60 5 L 10 60 6 Z`); 7// returns "M10 10H60V60L10 60Z" 8 9encodeSVGPath({ type: SVGPathData.MOVE_TO, relative: false, x: 10, y: 10 }); 10// returns "M10 10" 11 12encodeSVGPath({ type: SVGPathData.HORIZ_LINE_TO, relative: false, x: 60 }); 13// returns "H60" 14 15encodeSVGPath([ 16 { type: SVGPathData.VERT_LINE_TO, relative: false, y: 60 }, 17 { type: SVGPathData.LINE_TO, relative: false, x: 10, y: 60 }, 18 { type: SVGPathData.CLOSE_PATH }, 19]); 20// returns "V60L10 60Z"
This library can perform transformations on SVG paths. Here is an example of that kind of use.
1new SVGPathData(`
2 m 10,10
3 h 60
4 v 60
5 l 10,60
6 z`)
7 .toAbs()
8 .encode();
9// return s"M10,10 H70 V70 L80,130 Z"
Here, we take SVGPathData from stdin and output it transformed to stdout.
1const transformingParser = new SVGPathDataParser().toAbs().scale(2, 2); 2transformingParser.parse('m 0 0'); // returns [{ type: SVGPathData.MOVE_TO, relative: false, x: 0, y: 0 }] 3transformingParser.parse('l 2 3'); // returns [{ type: SVGPathData.LINE_TO, relative: false, x: 4, y: 6 }]
You can find all supported transformations in src/SVGPathDataTransformer.ts. Additionally, you can create your own by writing a function with the following signature:
1type TransformFunction = (command: SVGCommand) => SVGCommand | SVGCommand[]; 2 3function SET_X_TO(xValue = 10) { 4 return function(command) { 5 command.x = xValue; // transform command objects and return them 6 return command; 7 }; 8}; 9 10// Synchronous usage 11new SVGPathData('...') 12 .transform(SET_X_TO(25)) 13 .encode(); 14 15// Chunk usage 16new SVGPathDataParser().transform(SET_X_TO(25));
Clone this project, run:
1npm install; npm test
https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes Fixes rX and rY. Ensures lArcFlag and sweepFlag are 0 or 1 Adds center coordinates: command.cX, command.cY (relative or absolute, depending on command.relative) Adds start and end arc parameters (in degrees): command.phi1, command.phi2; phi1 < phi2 iff. c.sweepFlag == true
Solves a quadratic system of equations of the form a * x + b * y = c x² + y² = 1 This can be understood as the intersection of the unit circle with a line. => y = (c - a x) / b => x² + (c - a x)² / b² = 1 => x² b² + c² - 2 c a x + a² x² = b² => (a² + b²) x² - 2 a c x + (c² - b²) = 0
Determines if three points are collinear (lie on the same straight line) and the middle point is on the line segment between the first and third points
Creates an ellipse path centered at (cx,cy) with radii rx and ry
Creates a rectangle path with optional rounded corners
Creates a polyline from an array of coordinates [x1,y1,x2,y2,...]
Creates a closed polygon from an array of coordinates
Process a path and remove collinear points
Reverses the order of path commands to go from end to start IMPORTANT: This function expects absolute commands as input. It doesn't convert relative to absolute - use SVGPathDataTransformer.TO_ABS() first if needed.
https://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes Fixes rX and rY. Ensures lArcFlag and sweepFlag are 0 or 1 Adds center coordinates: command.cX, command.cY (relative or absolute, depending on command.relative) Adds start and end arc parameters (in degrees): command.phi1, command.phi2; phi1 < phi2 iff. c.sweepFlag == true
Solves a quadratic system of equations of the form a * x + b * y = c x² + y² = 1 This can be understood as the intersection of the unit circle with a line. => y = (c - a x) / b => x² + (c - a x)² / b² = 1 => x² b² + c² - 2 c a x + a² x² = b² => (a² + b²) x² - 2 a c x + (c² - b²) = 0
Determines if three points are collinear (lie on the same straight line) and the middle point is on the line segment between the first and third points
Kind: global function
Returns: true if the points are collinear and p2 is on the segment p1-p3
Param | Description |
---|---|
p1 | First point [x, y] |
p2 | Middle point that might be removed |
p3 | Last point [x, y] |
Creates an ellipse path centered at (cx,cy) with radii rx and ry
Creates a rectangle path with optional rounded corners
Creates a polyline from an array of coordinates [x1,y1,x2,y2,...]
Creates a closed polygon from an array of coordinates
Process a path and remove collinear points
Kind: global function
Returns: New array with collinear points removed
Param | Description |
---|---|
commands | Array of SVG path commands to process (must be absolute) |
Reverses the order of path commands to go from end to start IMPORTANT: This function expects absolute commands as input. It doesn't convert relative to absolute - use SVGPathDataTransformer.TO_ABS() first if needed.
Kind: global function
Returns: New SVG commands in reverse order with absolute coordinates
Param | Description |
---|---|
commands | SVG path commands in absolute form to reverse |
preserveSubpathOrder | If true, keeps subpaths in their original order |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 13/17 approved changesets -- score normalized to 7
Reason
5 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More