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
99.4
Supply Chain
99.6
Quality
90.1
Maintenance
100
Vulnerability
100
License
TypeScript (99.65%)
JavaScript (0.35%)
Total Downloads
241,489,001
Last Day
112,731
Last Week
2,397,646
Last Month
10,238,735
Last Year
91,382,435
MIT License
196 Stars
253 Commits
20 Forks
8 Watchers
6 Branches
11 Contributors
Updated on Jun 16, 2025
Minified
Minified + Gzipped
Latest Version
7.2.0
Package Id
svg-pathdata@7.2.0
Unpacked Size
621.55 kB
Size
107.70 kB
File Count
160
NPM Version
10.7.0
Node Version
22.2.0
Published on
Mar 15, 2025
Cumulative downloads
Total Downloads
Last Day
-3.4%
112,731
Compared to previous day
Last Week
-7.3%
2,397,646
Compared to previous week
Last Month
6.9%
10,238,735
Compared to previous month
Last Year
50.9%
91,382,435
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
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
7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
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-06-16
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