Skip to content

Commit

Permalink
Accept number as a value in hasAttrLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
GreLI committed Mar 20, 2016
1 parent 0f599b6 commit a7624a0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/svgo/jsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ JSAPI.prototype.renameElem = function(name) {
* Determine if element has an attribute by local name
* (any, or by name or by name + value).
*
* @param {String} [name] attribute name
* @param {String} [val] attribute value (will be toString()'ed)
* @param {String} [localName] local attribute name
* @param {Number|String|RegExp|Function} [val] attribute value (will be toString()'ed or executed, otherwise ignored)
* @return {Boolean}
*/
JSAPI.prototype.hasAttrLocal = function(localName, val) {
Expand All @@ -149,9 +149,10 @@ JSAPI.prototype.renameElem = function(name) {
var callback;

switch (val != null && val.constructor && val.constructor.name) {
case 'Function': callback = funcValueTest; break;
case 'RegExp': callback = regexpValueTest; break;
case 'Number': // same as String
case 'String': callback = stringValueTest; break;
case 'RegExp': callback = regexpValueTest; break;
case 'Function': callback = funcValueTest; break;
default: callback = nameTest;
}
return this.someAttr(callback);
Expand All @@ -160,16 +161,16 @@ JSAPI.prototype.renameElem = function(name) {
return attr.local === localName;
}

function funcValueTest(attr) {
return attr.local === localName && val(attr.value);
function stringValueTest(attr) {
return attr.local === localName && val == attr.value;
}

function regexpValueTest(attr) {
return attr.local === localName && val.test(attr.value);
}

function stringValueTest(attr) {
return attr.local === localName && val == attr.value;
function funcValueTest(attr) {
return attr.local === localName && val(attr.value);
}

};
Expand Down

0 comments on commit a7624a0

Please sign in to comment.