A collection of minimalistic SVG path manipulation utilities, mostly made by other people
Installations
npm install svg-path-mini-tools
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.16.0
NPM Version
10.8.1
Score
72.7
Supply Chain
89.1
Quality
81.8
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (91.48%)
JavaScript (8.52%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
tombigel
Download Statistics
Total Downloads
813
Last Day
1
Last Week
3
Last Month
41
Last Year
813
GitHub Statistics
MIT License
39 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Dec 01, 2024
Package Meta Information
Latest Version
0.2.8
Package Id
svg-path-mini-tools@0.2.8
Unpacked Size
51.97 kB
Size
13.85 kB
File Count
23
NPM Version
10.8.1
Node Version
20.16.0
Published on
Dec 01, 2024
Total Downloads
Cumulative downloads
Total Downloads
813
Last Day
0%
1
Compared to previous day
Last Week
-70%
3
Compared to previous week
Last Month
46.4%
41
Compared to previous month
Last Year
0%
813
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
SVG Path Mini Tools
A collection of minimalistic SVG path manipulation utilities
Rationale
For a work project, I needed to scale paths without using on-the-fly transforms. I discovered that almost all SVG manipulation resources are either outdated (8-10 years old) or resemble feature-packed Swiss Army knives.
So, I began exploring the smallest solutions I could find. This exploration led me to create this compact package. It allows you to parse a path string, convert it to relative or absolute, and scale it.
It's less than 2K when minified, and it's fully tested and typed.
I'm confident that I'll discover more use cases in the future, leading to additional functionality. However, I'm committed to preventing this from becoming another bloated SVG library.
Usage
1import {scalePath} from 'svg-path-mini-tools' 2const scaled = scalePath('M20, 20 L40, 40 Z', 2, 2) // 'M20,20L40,40Z'
Methods
parse(path: string): array[]
Parses an SVG path data string.
Generates an array of commands where each command is an array of the form [command, arg1, arg2, ...]
.
serialize(segments: array[]): string
Converts parsed path data back into a string.
relative(path: array[]): array[]
Defines a path using relative points.
The input is an array of path commands, and the output is a similar array but with all points defined relative to the previous point.
absolute(path: array[]): array[]
Redefines a path with absolute coordinates.
The input is an array of path commands, and the output is a similar array but with all points defined in absolute terms.
scaleSegments(segments: array[], sx: number, sy: number): array[]
Scales the parsed path data by the given sx
and sy
factors.
scalePath(path: string, sx: number, sy: number): string
Scales an SVG path by the given sx
and sy
factors.
The input is a path string, and the output is a similar string but with all points scaled by the given factors.
License
Credits
Based on the work of @jkroso and @michaelrhodes
https://github.com/jkroso/serialize-svg-path
https://github.com/jkroso/parse-svg-path
https://github.com/jkroso/abs-svg-path
https://github.com/jkroso/rel-svg-path
and
https://github.com/michaelrhodes/scale-svg-path
Types Based on work from the DefinitelyTyped project
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/abs-svg-path

No vulnerabilities found.

No security vulnerabilities found.