Created
February 21, 2019 01:10
-
-
Save DexterShepherd/8ba4dcd9fb1f5cc49c8acfe8e71f0876 to your computer and use it in GitHub Desktop.
svg-json-thing.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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