formatPath
Writes path commands back as SVG path data: letters and numbers separated by single spaces,
numbers rounded to precision decimals with the trailing zeros dropped (-0 is written 0).
Available since v3.1.10
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
commands | readonly PathCommand[] | The commands, as parsePath returns them |
precision | number | Decimals kept per number. Defaults to `6` |
Returns
Section titled “Returns”string — The path data
Examples
Section titled “Examples”Write commands back
Section titled “Write commands back”Numbers are rounded and written with single spaces.
Related Types
Section titled “Related Types”PathCommand
Section titled “PathCommand”One command of SVG path data: its letter (uppercase is absolute, lowercase relative to the
current point) and its numbers, as written in the d attribute.
| Letter | Command | Numbers |
|---|---|---|
M L T | move, line, smooth quadratic | x y |
H V | horizontal, vertical line | x or y |
C | cubic Bézier | x1 y1 x2 y2 x y |
S Q | smooth cubic, quadratic | x2 y2 x y or x1 y1 x y |
A | elliptical arc | rx ry rotation large-arc sweep x y |
Z | close the subpath | none |
