-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (38 loc) · 1014 Bytes
/
index.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
const fs = require("fs");
const cheerio = require("cheerio")
const fire_url = './symbol.svg'
fs.readFile(fire_url, 'utf8', function (err, res) {
if (err) {
return false
}
// console.log(res)
readSvg(res)
})
function readSvg (data) {
if (data === '') {
return false
}
var $ = cheerio.load(data);
let sum = 0
$("symbol").each(function (i, e) {
var item = $(e)
var str = '<svg xmlns="http://www.w3.org/2000/svg" '
str +='viewBox = "' + item.attr("viewBox") + '">'
str += item.html()
str += '</svg>'
writeSvg(str, item.attr("id"))
sum ++
})
console.log(`all item number is ${sum}`)
}
function writeSvg (data, name) {
if (data === '') return
var file_name = name + '.svg'
fs.mkdirSync('./svg-icon', { recursive: true });
fs.writeFile('./svg-icon/'+file_name, data, function (err) {
if (err) {
return
}
console.log( file_name + 'is saved')
})
}