Skip to content

Instantly share code, notes, and snippets.

@DexterShepherd
Created February 21, 2019 01:10
Show Gist options
  • Select an option

  • Save DexterShepherd/8ba4dcd9fb1f5cc49c8acfe8e71f0876 to your computer and use it in GitHub Desktop.

Select an option

Save DexterShepherd/8ba4dcd9fb1f5cc49c8acfe8e71f0876 to your computer and use it in GitHub Desktop.
svg-json-thing.js
const svgson = require('svgson');
const fs = require('fs');
const svg = fs.readFileSync('./coordinates.svg').toString();
const ms = []
const ls = []
const json = {}
svgson.parse(svg).then(data => {
const children = data.children[0].children
for ( const child of children ) {
const start = child.attributes.class.split(' ')[0]
json[start] = {
m: child.attributes.d.split(' ')[1].split(','),
l: child.attributes.d.split(' ')[3].split(',')
}
}
// console.log(json)
fs.writeFile('output.json', JSON.stringify(json), (err) => {
if ( err ) {
return console.log(err)
}
console.log(' wrote file ')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment