diff --git a/lib/svgo/jsAPI.js b/lib/svgo/jsAPI.js index 6355b9023..bbc99fb4b 100644 --- a/lib/svgo/jsAPI.js +++ b/lib/svgo/jsAPI.js @@ -22,7 +22,7 @@ JSAPI.prototype.clone = function() { var nodeData = {}; Object.keys(node).forEach(function(key) { - if (key != 'content') { + if (key !== 'content') { nodeData[key] = node[key]; } }); @@ -72,7 +72,7 @@ JSAPI.prototype.isElem = function(param) { */ JSAPI.prototype.renameElem = function(name) { - if (typeof name == 'string' && name != '') + if (name && typeof name === 'string') this.elem = this.local = name; return this; @@ -198,16 +198,16 @@ JSAPI.prototype.renameElem = function(name) { /** * Add attribute. * - * @param {Object} attr attribute object - * @return {Object} created attribute + * @param {Object} [attr={}] attribute object + * @return {Object|Boolean} created attribute or false if no attr was passed in */ JSAPI.prototype.addAttr = function(attr) { + attr = attr || {}; - if (!attr || - (attr && attr.name === undefined) || - (attr && attr.value === undefined) || - (attr && attr.prefix === undefined) || - (attr && attr.local === undefined) + if (attr.name === undefined || + attr.value === undefined || + attr.prefix === undefined || + attr.local === undefined ) return false; this.attrs = this.attrs || {};