imagemin-svgo
Advanced tools
Comparing version 2.0.0 to 2.1.0
73
index.js
@@ -10,3 +10,41 @@ 'use strict'; | ||
* | ||
* @param {Object} file | ||
* @param {String} enc | ||
* @param {Object} opts | ||
* @param {Function} cb | ||
* @api private | ||
*/ | ||
function plugin(file, enc, opts, cb) { | ||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
if (file.isStream()) { | ||
cb(new Error('Streaming is not supported')); | ||
return; | ||
} | ||
if (!isSvg(file.contents)) { | ||
cb(null, file); | ||
return; | ||
} | ||
var svgo = new SVGO({ plugins: opts.plugins || [] }); | ||
try { | ||
svgo.optimize(file.contents.toString('utf8'), function (res) { | ||
file.contents = new Buffer(res.data); | ||
cb(null, file); | ||
}); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
} | ||
/** | ||
* Module exports | ||
* | ||
* @param {Object} opts | ||
* @api public | ||
@@ -19,28 +57,19 @@ */ | ||
return through.obj(function (file, enc, cb) { | ||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
plugin(file, enc, opts, cb); | ||
}); | ||
}; | ||
if (file.isStream()) { | ||
cb(new Error('Streaming is not supported')); | ||
return; | ||
} | ||
/** | ||
* Module exports constructor | ||
* | ||
* @param {Object} opts | ||
* @api public | ||
*/ | ||
if (!isSvg(file.contents)) { | ||
cb(null, file); | ||
return; | ||
} | ||
module.exports.ctor = function (opts) { | ||
opts = opts || {}; | ||
var svgo = new SVGO({ plugins: opts.plugins || [] }); | ||
try { | ||
svgo.optimize(file.contents.toString('utf8'), function (res) { | ||
file.contents = new Buffer(res.data); | ||
cb(null, file); | ||
}); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
return through.ctor({ objectMode: true }, function (file, enc, cb) { | ||
plugin(file, enc, opts, cb); | ||
}); | ||
}; |
{ | ||
"name": "imagemin-svgo", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "svgo imagemin plugin", | ||
@@ -23,2 +23,3 @@ "license": "MIT", | ||
"compress", | ||
"gulpplugin", | ||
"image", | ||
@@ -29,3 +30,4 @@ "imageminplugin", | ||
"optimize", | ||
"svg" | ||
"svg", | ||
"svgo" | ||
], | ||
@@ -39,4 +41,4 @@ "dependencies": { | ||
"ava": "0.0.4", | ||
"vinyl": "^0.4.3" | ||
"vinyl-file": "^1.1.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3199
60