forked from svg/svgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
64 lines (59 loc) · 1.47 KB
/
test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const FS = require('fs');
const PATH = require('path');
const { optimize } = require('../lib/svgo');
const filepath = PATH.resolve(__dirname, 'test.svg');
const config = {
plugins: [
'cleanupAttrs',
'removeDoctype',
'removeXMLProcInst',
'removeComments',
'removeMetadata',
'removeTitle',
'removeDesc',
'removeUselessDefs',
'removeEditorsNSData',
'removeEmptyAttrs',
'removeHiddenElems',
'removeEmptyText',
'removeEmptyContainers',
// 'removeViewBox',
'cleanupEnableBackground',
'convertStyleToAttrs',
'convertColors',
'convertPathData',
'convertTransform',
'removeUnknownsAndDefaults',
'removeNonInheritableGroupAttrs',
'removeUselessStrokeAndFill',
'removeUnusedNS',
'cleanupIDs',
'cleanupNumericValues',
'moveElemsAttrsToGroup',
'moveGroupAttrsToElems',
'collapseGroups',
// 'removeRasterImages',
'mergePaths',
'convertShapeToPath',
'sortAttrs',
'removeDimensions',
{ name: 'removeAttrs', params: { attrs: '(stroke|fill)' } },
],
};
FS.readFile(filepath, 'utf8', function (err, data) {
if (err) {
throw err;
}
const result = optimize(data, { path: filepath, ...config });
console.log(result);
// {
// // optimized SVG data string
// data: '<svg width="10" height="20">test</svg>'
// // additional info such as width/height
// info: {
// width: '10',
// height: '20'
// }
// }
});