JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1678
  • Score
    100M100P100Q111899F
  • License MIT

extracts a string of subpaths from an svg file

Package Exports

  • extract-svg-path

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (extract-svg-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

extract-svg-path

unstable

Extracts a string of subpaths from an svg file as a single path. Concats the <path> elements' data together to produce the output. This is mostly useful for SVG files of a single monotone shape or glyph (as opposed to, say, SVG font libraries or a complex SVG scene composed of several shapes).

npm install -g extract-svg-path

extract-svg-path foo.svg > foo.txt

Now you can use the path alongside parse-svg-path and similar modules.

Use -q or --quote to escape the string for JSON:

extract-svg-path foo.svg --quote > foo.json

API

NPM

The API is intentionally dumbed down to make it easier for static analysis (i.e. bundler transforms).

var contents = require('extract-svg-path')(__dirname + '/file.svg')

extractSvgPath(file[, opt])

Extracts the SVG contents of the given file path, using fs.readFileSync with utf8 by default. Any options will be passed along to cheerio, but with xmlMode default to true. Additional options:

  • encoding the file encoding, defaults to utf8

extractSvgPath.extract(contents)

Performs the cheerio extraction on a string.

Browser API

Only require('extract-svg-path').extract will run by default in the browser. This can accept either a string (i.e. from xhr response) or an SVG node (i.e. from load-svg).

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

You can, however, use extractify-svg-path, a browserify transform to inline calls to SVG files. Example:

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

commonjs

Using the command-line tool, you can pipe module-exports to produce a CommonJS file:

extract-svg-path foo.svg -q | module-exports > foo.js

Will produce:

module.exports = "M50,1.42C23.213,1.42,1.........";

License

MIT, see LICENSE.md for details.