# parse-svg-path

> svg path parser

Latest version **0.2.0** (published 2026-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install parse-svg-path
pnpm add parse-svg-path
yarn add parse-svg-path
bun add parse-svg-path
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2026-06-02 |
| First published | 2013-11-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 96 |
| Author | Jake Rosoman |
| Maintainers | jkroso |
| Keywords | svg, path, parse, parser |

## Links

- npm: https://www.npmjs.com/package/parse-svg-path
- Repository: https://github.com/jkroso/parse-svg-path
- Homepage: https://github.com/jkroso/parse-svg-path#readme
- Issues: https://github.com/jkroso/parse-svg-path/issues
- npm.io page: https://npm.io/package/parse-svg-path

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 0.2.0 (latest) — 2026-06-02
- 0.1.2 — 2016-09-03
- 0.1.1 — 2013-12-01
- 0.1.0 — 2013-11-23

## README

# parse-svg-path

A minimal SVG path data parser. Returns a structured array of commands that's easy to iterate and transform.

For a more full-featured parser see [hughsk/svg-path-parser](//github.com/hughsk/svg-path-parser), or for a streaming parser see [nfroidure/SVGPathData](//github.com/nfroidure/SVGPathData).

## Installation

```sh
npm install parse-svg-path
```

## Usage

```ts
import parse from 'parse-svg-path'

const commands = parse('M10 20 L30 40 Z')
// [['M', 10, 20], ['L', 30, 40], ['Z']]
```

Each command is an array whose first element is the command letter (preserving its original case) followed by its numeric arguments.

Overloaded `m`/`M` commands — where more than 2 arguments are provided — are automatically split into an initial move followed by implicit `l`/`L` line commands:

```ts
parse('m 12.5,52 39,0 0,-40')
// [['m', 12.5, 52], ['l', 39, 0], ['l', 0, -40]]
```

## API

### `parse(path: string): Command[]`

Parses an SVG path data string and returns an array of commands.

```ts
type Command = [string, ...number[]]
```

Throws an `Error` with the message `"malformed path data"` if a command has fewer arguments than required.

### Supported commands

| Letter | Command              | Arguments |
| ------ | -------------------- | --------- |
| M / m  | Move to              | x, y      |
| L / l  | Line to              | x, y      |
| H / h  | Horizontal line to   | x         |
| V / v  | Vertical line to     | y         |
| C / c  | Cubic Bézier curve   | x1, y1, x2, y2, x, y |
| S / s  | Smooth cubic curve   | x2, y2, x, y |
| Q / q  | Quadratic Bézier     | x1, y1, x, y |
| T / t  | Smooth quadratic     | x, y      |
| A / a  | Arc                  | rx, ry, x-rotation, large-arc, sweep, x, y |
| Z / z  | Close path           | —         |

Uppercase letters use absolute coordinates; lowercase use relative coordinates.

## Development

```sh
npm test          # run tests once
npm run test:watch  # watch mode
npm run build     # build dist/
```

## Publishing

Bump the version, then push — `prepublishOnly` runs the build automatically:

```sh
npm version patch  # or minor / major
git push && git push --tags
npm publish
```

---
_Source: https://npm.io/package/parse-svg-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
