forked from sindresorhus/broccoli-svgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (24 loc) · 764 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
'use strict';
var Filter = require('broccoli-filter');
var RSVP = require('rsvp');
var SVGO = require('svgo');
function SvgoFilter(inputTree, options) {
if (!(this instanceof SvgoFilter)) {
return new SvgoFilter(inputTree, options);
}
Filter.call(this, inputTree);
this.inputTree = inputTree;
this.svgo = new SVGO(options);
}
SvgoFilter.prototype = Object.create(Filter.prototype);
SvgoFilter.prototype.constructor = SvgoFilter;
SvgoFilter.prototype.extensions = ['svg'];
SvgoFilter.prototype.targetExtension = 'svg';
SvgoFilter.prototype.processString = function (str) {
return new RSVP.Promise(function(resolve, reject) {
this.svgo.optimize(str, function (result) {
resolve(result.data);
});
}.bind(this));
};
module.exports = SvgoFilter;