Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c58277

Browse files
committed
Merge pull request svg#258 from dfilatov/master
Add ability to enable multipass
2 parents 0fac67e + 943f5fa commit 0c58277

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

lib/svgo.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ SVGO.prototype.optimize = function(svgstr, callback) {
3333
return;
3434
}
3535

36-
svgjs = PLUGINS(svgjs, config.plugins);
37-
38-
callback(JS2SVG(svgjs, config.js2svg));
36+
var svg = { data : null },
37+
maxIterationCount = config.multipass ? 10 : 1,
38+
counter = 0,
39+
prevResult;
40+
41+
do {
42+
prevResult = svg;
43+
svgjs = PLUGINS(svgjs, config.plugins);
44+
svg = JS2SVG(svgjs, config.js2svg);
45+
} while(++counter < maxIterationCount && prevResult.data !== svg.data);
46+
47+
callback(svg);
3948

4049
});
4150

lib/svgo/coa.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ module.exports = require('coa').Cmd()
8585
return val || this.reject('Option --datauri must have one of the following values: base64, enc or unenc');
8686
})
8787
.end()
88+
.opt()
89+
.name('multipass').title('Enable multipass')
90+
.long('multipass')
91+
.flag()
92+
.end()
8893
.opt()
8994
.name('pretty').title('Make SVG pretty printed')
9095
.long('pretty')
@@ -136,6 +141,14 @@ module.exports = require('coa').Cmd()
136141
config = changePluginsState(opts.enable, true, config);
137142
}
138143

144+
// --multipass
145+
if (opts.multipass) {
146+
147+
config = config || {};
148+
config.multipass = true;
149+
150+
}
151+
139152
// --pretty
140153
if (opts.pretty) {
141154

lib/svgo/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module.exports = function(config) {
2525
defaults.plugins = optimizePluginsArray(defaults.plugins);
2626
}
2727

28+
defaults.multipass = config.multipass;
29+
2830
} else {
2931

3032
defaults = EXTEND({}, yaml.safeLoad(fs.readFileSync(__dirname + '/../../.svgo.yml', 'utf8')));
@@ -33,6 +35,7 @@ module.exports = function(config) {
3335

3436
if (config) {
3537
defaults = extendConfig(defaults, config);
38+
defaults.multipass = config.multipass;
3639
}
3740

3841
defaults.plugins = optimizePluginsArray(defaults.plugins);

0 commit comments

Comments
 (0)