svg-numbers

v0.0.2
Parse SVG coordinates.
svg numbers number list list-of-points parse

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 ]
}

Metadata

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

Downloads

Maintainers