svg-numbers

v0.1.1
Parse SVG coordinates.
svg number numbers points coordinates parser parse serializer serialize and 1 more...

svg-numbers

Parse a list of coordinates from an SVG document, such as the points attribute of a <polyline> element.

Usage

npm install svg-numbers
var parse = require('svg-numbers')
var numbers = parse('10, 15.20.8 -11,15-25+75 4.2e3')
console.log(numbers)
// [ 10, 15.2, .8, -11, 15, -25, 75, 4200 ]

Catching syntax errors

If a syntax error is found, an error is thrown. As per the W3C recommendation, the valid numbers up to and until the syntax error are available as error.partial:

try {
  var numbers = parse('10, 20, , 30, 40')
} catch (error) {
  console.log(error.partial)
  // [ 10, 20 ]
}
npm i svg-numbers

Metadata

  • MIT
  • Whatever
  • Peter-Paul van Gemerden
  • released 11/30/2013

Downloads

Maintainers