-
Notifications
You must be signed in to change notification settings - Fork 53
/
formatJS.js
50 lines (45 loc) · 1.42 KB
/
formatJS.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
49
50
/**
* formatJS(rawJSON)
* Formats JSON and returns JSON string
* @param rawJSON: requires return result from getJSON()
*/
const formatJS = (rawJSON, options = {}) => {
this.options = Object.assign(
{
json: true,
},
options
);
// iconMeta - returns new JSON Array of icon Objects
const iconMeta = rawJSON.map(symbol => {
// For each "symbol.svg.symbol", create new Objects with these keys/values
const data = {
id: symbol.$.id,
name: symbol.$.id,
tags: symbol.$.id,
styles: symbol.style ? symbol.style : '',
viewBox: symbol.$.viewBox || '',
width: symbol.$.viewBox.split(' ')[2] || '',
height: symbol.$.viewBox.split(' ')[3] || '',
svgData: {
circles: symbol.circle
? symbol.circle.map(attrValue => attrValue.$)
: '',
ellipses: symbol.ellipse
? symbol.ellipse.map(attrValue => attrValue.$)
: '',
paths: symbol.path ? symbol.path.map(attrValue => attrValue.$) : '',
polygons: symbol.polygon
? symbol.polygon.map(attrValue => attrValue.$)
: '',
polylines: symbol.polyline
? symbol.polyline.map(attrValue => attrValue.$)
: '',
rects: symbol.rect ? symbol.rect.map(attrValue => attrValue.$) : '',
},
};
return data;
});
return this.options.json ? JSON.stringify(iconMeta, null, 2) : iconMeta;
};
module.exports = formatJS;