1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Allow element seperator to be changed in config

This resolves #557 as you can pass in a different character for element seperation (e.g. `^`
This commit is contained in:
Mike Street
2017-04-03 11:48:56 +01:00
committed by GreLI
parent 91d98106d4
commit 645908923b

View File

@ -1,6 +1,6 @@
'use strict';
var ELEM_SEP = ':';
var DEFAULT_SEPARATOR = ':';
exports.type = 'perItem';
@ -9,12 +9,16 @@ exports.active = false;
exports.description = 'removes specified attributes';
exports.params = {
elemSeparator: DEFAULT_SEPARATOR,
attrs: []
};
/**
* Remove attributes
*
* @param elemSeparator
* format: string
*
* @param attrs:
*
* format: [ element* : attribute* ]
@ -72,17 +76,18 @@ exports.fn = function(item, params) {
}
if (item.isElem()) {
var elemSeparator = typeof params.elemSeparator == 'string' ? params.elemSeparator : DEFAULT_SEPARATOR;
// prepare patterns
var patterns = params.attrs.map(function(pattern) {
// apply to all elements if specifc element is omitted
if (pattern.indexOf(ELEM_SEP) === -1) {
pattern = ['.*', ELEM_SEP, pattern].join('');
if (pattern.indexOf(elemSeparator) === -1) {
pattern = ['.*', elemSeparator, pattern].join('');
}
// create regexps for element and attribute name
return pattern.split(ELEM_SEP)
return pattern.split(elemSeparator)
.map(function(value) {
// adjust single * to match anything