-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-svg-path.js
48 lines (35 loc) · 917 Bytes
/
parse-svg-path.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict'
const glob = require('glob')
const fs = require('fs')
const xmlreader = require('xmlreader')
const _ = require('lodash')
const opts = {
encoding: 'UTF-8'
}
glob('*.svg', function (er, files) {
console.log(files)
const dVals = files.map((f) => {
console.log(f)
const xml = fs.readFileSync(f, opts)
var vals = []
xmlreader.read(xml, function (err, res) {
if (err) return console.log(err)
console.log(res.svg.count())
if (!res.svg.path && !res.svg.g) return
const path = res.svg.path || listify(res.svg.g.array)
console.log(path)
path.each((i, p) => {
// console.log(p.attributes().d)
vals.push(p.attributes().d)
})
})
return vals
})
const filePaths = _.zip(files, dVals)
console.log(filePaths)
})
function listify (objs) {
console.log(`listify ${objs}`)
objs.each = objs.forEach
return objs
}