Skip to content

ppvg/svg-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svg-path

Parse and manipulate SVG <path>s.

NPM version Build status

Usage example

Parsing

var svgPath = require('svg-path')

var pathData = 'm100,1e2C125,100 130,110 150,150l-25-75z'

var path = svgPath(pathData) // creates a new svgPath.Path
console.log(path.content)
/*
    [
       { type: 'M', relative: false, x: 100, y: 100 },
       { type: 'C', relative: false,
         x1: 125, y1: 100, x2: 130, y2: 110, x: 150, y: 150 },
       { type: 'L', relative: true,  x: -25, y: -75 },
       { type: 'Z' }
    ]
*/

Applying transformations

var path = svgPath(pathData)
path.abs()
path.matrix(1, 0, 0, 1, 100, 50) // same as translate(100, 50)

Transformations are applied in-place. To retain the original, create a copy first:

var newPath = path.copy()

Available transformations are abs, translate, scale, rotate, skewX and skewY and convertArcs. The latter converts all A (arc) commands to C (curveto) commands. All transformations expect #abs() start by calling #convertArcs.

Running the tests

$ git clone https://github.com/PPvG/svg-path
$ cd svg-path
$ npm install
$ npm test

Code coverage report

$ npm run cover

Then open ./cov/report.html in your browser.

License

MIT

About

Manipulate SVG <path> data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published