Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg-path-parser

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-path-parser

A parser for SVG's path syntax

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
62K
decreased by-0.62%
Maintainers
1
Weekly downloads
 
Created
Source

svg-path-parser stable

An SVG path parser, built from the PEG.js grammar specified here, published as an NPM module.

Originally written by Gavin Kistner.

svg-path-parser

Usage

require('svg-path-parser')(d)

Takes an SVG path string. The following:

var parse = require('svg-path-parser')
var path = [
  'M-150,150'
, 'L200,100'
, 'H250 V170'
, 'Q350,90 375,150'
, 'T400,150'
, 'C500,100 575,300 560,150'
, 'S650,160 550,300'
, 'Z M500,200'
, 'A25,35 -80 1,1 450,220 Z'
].join(' ')

console.log(parse(path))

Should yield an array of commands that define the path, like so:

[
  {
    "command": "moveto",
    "relative": false,
    "args": [
      {
        "x": -150,
        "y": 150
      }
    ]
  },
  {
    "command": "lineto",
    "relative": false,
    "args": [
      {
        "x": 200,
        "y": 100
      }
    ]
  },
  {
    "command": "horizontal lineto",
    "relative": false,
    "args": [
      250
    ]
  },
  {
    "command": "vertical lineto",
    "relative": false,
    "args": [
      170
    ]
  },
  {
    "command": "quadratic curveto",
    "relative": false,
    "args": [
      {
        "x1": 350,
        "y1": 90,
        "x": 375,
        "y": 150
      }
    ]
  },
  {
    "command": "smooth quadratic curveto",
    "relative": false,
    "args": [
      {
        "x": 400,
        "y": 150
      }
    ]
  },
  {
    "command": "curveto",
    "relative": false,
    "args": [
      {
        "x1": 500,
        "y1": 100,
        "x2": 575,
        "y2": 300,
        "x": 560,
        "y": 150
      }
    ]
  },
  {
    "command": "smooth curveto",
    "relative": false,
    "args": [
      {
        "x2": 650,
        "y2": 160,
        "x": 550,
        "y": 300
      }
    ]
  },
  {
    "command": "closepath"
  },
  {
    "command": "moveto",
    "relative": false,
    "args": [
      {
        "x": 500,
        "y": 200
      }
    ]
  },
  {
    "command": "elliptical arc",
    "relative": false,
    "args": [
      {
        "rx": 25,
        "ry": 35,
        "xAxisRotation": -80,
        "largeArc": true,
        "sweep": true,
        "x": 450,
        "y": 220
      }
    ]
  },
  {
    "command": "closepath"
  }
]

Keywords

FAQs

Package last updated on 25 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc