# extract-svg-path

> extracts a string of subpaths from an svg file

Latest version **2.1.0** (published 2015-10-03) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2015-10-03 |
| First published | 2014-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 49 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | svg, extract, path, paths, vector, format, file, parse |

## Links

- npm: https://www.npmjs.com/package/extract-svg-path
- Repository: https://github.com/mattdesl/extract-svg-path
- Issues: https://github.com/mattdesl/extract-svg-path/issues
- npm.io page: https://npm.io/package/extract-svg-path

## Dependencies (6)

- [jsesc](https://npm.io/package/jsesc.md) ^0.5.0
- [cheerio](https://npm.io/package/cheerio.md) ^0.17.0
- [through2](https://npm.io/package/through2.md) ^2.0.0
- [object-assign](https://npm.io/package/object-assign.md) ^4.0.1
- [static-module](https://npm.io/package/static-module.md) ^1.1.3
- [xml-parse-from-string](https://npm.io/package/xml-parse-from-string.md) ^1.0.0

## 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

- 2.1.0 (latest) — 2015-10-03
- 2.0.0 — 2015-10-03
- 1.1.3 — 2014-11-19
- 1.1.2 — 2014-11-19
- 1.1.1 — 2014-11-19
- 1.1.0 — 2014-11-11
- 1.0.0 — 2014-11-05

## README

# extract-svg-path

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Grabs all the `<path>` data from an SVG file, concatenating them into a single string.

This is mostly useful for simple shapes and silhouettes. It works in Node/Browser and provides a transform for inlining paths into a bundle.

## Install

```sh
npm install extract-svg-path [-g|--save]
```

## Example

```js
var parse = require('parse-svg-path')
var extract = require('extract-svg-path')

var path = extract(__dirname + '/infinity.svg')
var svg = parse(path)
console.log(svg)
//=> [ [ 'M', 25, 15 ], ... ]
```

## Usage

#### `extractSvgPath(file[, opt])`

Extracts the SVG `<path>` contents of the given file path, using `fs.readFileSync` with utf8 by default. Any options will be passed along to [cheerio](https://github.com/cheeriojs/cheerio), but with `xmlMode` default to true. Additional options:

- `encoding` the file encoding, defaults to utf8

#### `extractSvgPath.parse(contents)`

Extracts the paths from the string contents of an SVG file.

## Browser Usage

Without a transform, only the `parse` method is supported. This can accept either a string (i.e. from [xhr](https://www.npmjs.org/package/xhr) response) or an SVG node (i.e. from [load-svg](https://github.com/substack/load-svg)).

```js
var parse = require('parse-svg-path')
var extract = require('extract-svg-path').parse
var load = require('load-svg')

load('svg/infinity.svg', function(err, svg) {
  var paths = parse(extract(svg))
})
```

With browserify, you can use the transform to inline files into your bundle. For example:

```js
var parse = require('parse-svg-path')
var svg = require('extract-svg-path')(__dirname + '/shape.svg')
var path = parse(svg)
```

Then:

```sh
browserify index.js -t extract-svg-path/transform
```

## Changes

- `2.1` - renamed `fromString` to `parse` in a backwards-compatible manner
- `2.0` - uses `xml-parse-from-string`, removed CLI to reduce dependency bloat, renamed `extract` method to `fromString`, merged transform into this module
  - a CLI might be re-done later in a separate module
- `1.0` - includes a CLI, `extract` method

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/extract-svg-path/blob/master/LICENSE.md) for details.

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