extract-svg-path
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
npm install extract-svg-path [-g|--save]
Example
var parse = var extract = var path = var svg = console//=> [ [ '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, 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 response) or an SVG node (i.e. from load-svg).
var parse = var extract = parsevar load =
With browserify, you can use the transform to inline files into your bundle. For example:
var parse = var svg = __dirname + '/shape.svg'var path =
Then:
browserify index.js -t extract-svg-path/transform
Changes
2.1
- renamedfromString
toparse
in a backwards-compatible manner2.0
- usesxml-parse-from-string
, removed CLI to reduce dependency bloat, renamedextract
method tofromString
, 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 for details.