svgo
Version:
Nodejs-based tool for optimizing SVG vector graphics files
52 lines (44 loc) • 1.27 kB
JavaScript
var regViewBox = /^0\s0\s(\d+)\s(\d+)$/;
/**
* Remove some useless svg element attributes.
*
* @see http://www.w3.org/TR/SVG/struct.html#SVGElement
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
* @return {Boolean} if false, item will be filtered out
*
* @author Kir Belevich
*/
exports.cleanupSVGElem = function(item, params) {
if (item.isElem('svg') && item.hasAttr()) {
/**
* Remove id attribute.
*
* @see http://www.w3.org/TR/SVG/struct.html#IDAttribute
*
* @example
* <svg id="svg49">
*/
if (params.id) item.removeAttr('id');
/**
* Remove version attribute.
*
* @see http://www.w3.org/TR/SVG/struct.html#SVGElementVersionAttribute
*
* @example
* <svg version="1.1">
*/
if (params.version) item.removeAttr('version');
/**
* Remove xnl:space attribute.
*
* @see http://www.w3.org/TR/SVG/struct.html#XMLSpaceAttribute
*
* @example
* <svg xml:space="preserve">
*/
// TODO: remove as a default value
if (params.xmlspace) item.removeAttr('xml:space');
}
};