Skip to content

Commit

Permalink
Remove a few extra parens
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Feb 27, 2021
1 parent 6f72d04 commit 098f239
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 74 deletions.
16 changes: 8 additions & 8 deletions bin/svg-sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function addOption(name, option) {
const def = template ? path.resolve(path.dirname(__dirname), option.default) : option.default;
yargs = yargs.default(alias, def);

if ((option.default === true) || (option.default === false)) {
if (option.default === true || option.default === false) {
yargs = yargs.boolean(name);
}
} else if (option.required) {
Expand Down Expand Up @@ -180,7 +180,7 @@ if (argv.config) {
}

// Expand shorthand mode definitions
if (('mode' in externalConfig) && _.isObject(externalConfig.mode)) {
if ('mode' in externalConfig && _.isObject(externalConfig.mode)) {
for (const emode in externalConfig.mode) {
if (externalConfig.mode[emode] === true) {
externalConfig.mode[emode] = JSONConfig.mode[emode] = {
Expand All @@ -199,7 +199,7 @@ if (argv.config) {
}

// Refine particular config options
config.shape.spacing.padding = (String(config.shape.spacing.padding)).trim();
config.shape.spacing.padding = String(config.shape.spacing.padding).trim();
config.shape.spacing.padding = config.shape.spacing.padding.length ?
config.shape.spacing.padding.split(',').map(dim => parseFloat(dim || 0)) :
[];
Expand All @@ -216,7 +216,7 @@ if (config.svg.rootAttributes && typeof config.svg.rootAttributes === 'string')

// Expand transformation options
if (typeof config.shape.transform === 'string') {
const transform = (String(config.shape.transform)).trim();
const transform = String(config.shape.transform).trim();
config.shape.transform = [];
(transform.length ? transform.split(',').map(trans => String(trans).trim()) : [])
.forEach(function(transform) {
Expand Down Expand Up @@ -245,7 +245,7 @@ if (typeof config.shape.transform === 'string') {
// Remove excessive render types
['css', 'scss', 'less', 'styl'].forEach(function(render) {
const arg = mode + '-render-' + render;
if ((render in this) && !argv[arg] && (!(mode in JSONConfig.mode) || !('render' in JSONConfig.mode[mode]) || !(render in JSONConfig.mode[mode].render))) {
if (render in this && !argv[arg] && (!(mode in JSONConfig.mode) || !('render' in JSONConfig.mode[mode]) || !(render in JSONConfig.mode[mode].render))) {
delete this[render];
}
}, this[mode].render);
Expand All @@ -258,14 +258,14 @@ if (typeof config.shape.transform === 'string') {
// Remove excessive example options
for (const mode in config.mode) {
const example = mode + '-example';
if (!argv[example] && (!(mode in JSONConfig.mode) || !('example' in JSONConfig.mode[mode])) && ('example' in config.mode[mode])) {
if (!argv[example] && (!(mode in JSONConfig.mode) || !('example' in JSONConfig.mode[mode])) && 'example' in config.mode[mode]) {
delete config.mode[mode].example;
}
}

// Read & parse Mustache variable JSON file
if ('variables' in config) {
let variables = (String(config.variables)).trim();
let variables = String(config.variables).trim();
delete config.variables;
variables = variables.length ? path.resolve(variables) : null;
if (variables && fs.existsSync(variables)) {
Expand All @@ -289,7 +289,7 @@ _.reduce(argv._, (f, g) => [...f, ...glob.sync(g)], [])
basename = path.basename(file);
} else {
const basepos = basename.lastIndexOf('./');
basename = (basepos >= 0) ? basename.substr(basepos + 2) : path.basename(file);
basename = basepos >= 0 ? basename.substr(basepos + 2) : path.basename(file);
}

spriter.add(file, basename, fs.readFileSync(file));
Expand Down
8 changes: 4 additions & 4 deletions lib/svg-sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ SVGSpriter.prototype.add = function(file, name, svg) {
* @return {Boolean} Parameter is a vinyl file object
*/
SVGSpriter.prototype._isVinylFile = function(file) {
return _.isObject(file) && ((file instanceof File) || ((file.constructor.name === 'File') && (['path', 'contents', 'relative'].filter(function(property) {
return _.isObject(file) && (file instanceof File || file.constructor.name === 'File' && ['path', 'contents', 'relative'].filter(function(property) {
return property in this;
}, file).length === 3)));
}, file).length === 3);
};

/**
Expand All @@ -176,7 +176,7 @@ SVGSpriter.prototype._transformShape = function(shape, cb) {
}

// Else if it's a registered transformer
if ((transform[0] in this._shapeTransformers) && _.isObject(transform[1])) {
if (transform[0] in this._shapeTransformers && _.isObject(transform[1])) {
return (...args) => {
this._shapeTransformers[transform[0]](shape, transform[1], this, args[args.length - 1]);
};
Expand Down Expand Up @@ -245,7 +245,7 @@ SVGSpriter.prototype._compile = function() {
this.info('Compiling %d shapes ...', masterShapes);

// Initialize the namespace powers
while (!this._namespacePow.length || (Math.pow(26, this._namespacePow.length) < masterShapes)) {
while (!this._namespacePow.length || Math.pow(26, this._namespacePow.length) < masterShapes) {
this._namespacePow.unshift(Math.pow(26, this._namespacePow.length));
_.invoke(this._shapes, 'resetNamespace');
}
Expand Down
26 changes: 13 additions & 13 deletions lib/svg-sprite/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ function SVGSpriterConfig(config) {
// Logging
this.log = '';
if ('log' in config) {
if ((config.log instanceof winston.Logger) || (_.isObject(config.log) && config.log.level !== undefined && _.isObject(config.log.transports) && _.isFunction(config.log.log))) {
if (config.log instanceof winston.Logger || _.isObject(config.log) && config.log.level !== undefined && _.isObject(config.log.transports) && _.isFunction(config.log.log)) {
this.log = config.log;
} else {
this.log = (_.isString(config.log) && (['info', 'verbose', 'debug'].includes(config.log))) ? config.log : (config.log ? 'info' : '');
this.log = _.isString(config.log) && ['info', 'verbose', 'debug'].includes(config.log) ? config.log : config.log ? 'info' : '';
}
}

Expand All @@ -123,13 +123,13 @@ function SVGSpriterConfig(config) {

this.log.debug('Prepared general options');

this.shape = ('shape' in config) ? _.assign({}, config.shape || {}) : {};
this.shape = 'shape' in config ? _.assign({}, config.shape || {}) : {};

let stat;
let transforms = null;

// Parse meta data (if configured)
if (('meta' in this.shape) && !_.isPlainObject(this.shape.meta)) {
if ('meta' in this.shape && !_.isPlainObject(this.shape.meta)) {
let meta = _.isString(this.shape.meta) ? path.resolve(this.shape.meta) : null;
const metaFile = meta;
stat = meta ? fs.lstatSync(meta) : null;
Expand All @@ -155,7 +155,7 @@ function SVGSpriterConfig(config) {
}

// Parse alignment data (if configured)
if (('align' in this.shape) && !_.isPlainObject(this.shape.align)) {
if ('align' in this.shape && !_.isPlainObject(this.shape.align)) {
let align = _.isString(this.shape.align) ? path.resolve(this.shape.align) : null;
const alignFile = align;
stat = align ? fs.lstatSync(align) : null;
Expand Down Expand Up @@ -190,11 +190,11 @@ function SVGSpriterConfig(config) {
}

// Intermediate SVG destination
this.shape.dest = ('dest' in this.shape) ? (String(this.shape.dest)).trim() : '';
this.shape.dest = 'dest' in this.shape ? String(this.shape.dest).trim() : '';
this.shape.dest = this.shape.dest.length ? path.resolve(this.dest, this.shape.dest) : null;

// Expand spacing options to arrays
this.shape.spacing = ('spacing' in this.shape) ? (this.shape.spacing || {}) : {};
this.shape.spacing = 'spacing' in this.shape ? this.shape.spacing || {} : {};
['padding'].forEach(function(property) {
let spacing;

Expand Down Expand Up @@ -223,7 +223,7 @@ function SVGSpriterConfig(config) {
}, this.shape);

// Prepare shape transforms
if (('transform' in this.shape) && Array.isArray(this.shape.transform)) {
if ('transform' in this.shape && Array.isArray(this.shape.transform)) {
transforms = this.shape.transform;
}

Expand All @@ -232,7 +232,7 @@ function SVGSpriterConfig(config) {
if ('transform' in config) {
this.log.warn('The top-level `transform` option is deprecated and will be removed in a future version. Please use `shape.transform` instead.');

if ((transforms === null) && Array.isArray(config.transform)) {
if (transforms === null && Array.isArray(config.transform)) {
transforms = config.transform;
}
}
Expand All @@ -256,8 +256,8 @@ function SVGSpriterConfig(config) {
if (_.isObject(transforms[t])) {
for (const transformer in transforms[t]) {
const tconfig = transforms[t][transformer];
if ((tconfig === true) || _.isObject(tconfig) || _.isFunction(tconfig)) {
this.shape.transform.push([transformer, (tconfig === true) ? {} : tconfig]);
if (tconfig === true || _.isObject(tconfig) || _.isFunction(tconfig)) {
this.shape.transform.push([transformer, tconfig === true ? {} : tconfig]);
continue transformers;
}
}
Expand All @@ -268,7 +268,7 @@ function SVGSpriterConfig(config) {
this.log.debug('Prepared `shape` options');

this.svg = _.clone(defaultSVGConfig);
this.svg = ('svg' in config) ? _.assign(this.svg, config.svg || {}) : this.svg;
this.svg = 'svg' in config ? _.assign(this.svg, config.svg || {}) : this.svg;
this.svg.xmlDeclaration = this.svg.xmlDeclaration || false;
this.svg.doctypeDeclaration = this.svg.doctypeDeclaration || false;
this.svg.dimensionAttributes = this.svg.dimensionAttributes || false;
Expand Down Expand Up @@ -315,7 +315,7 @@ SVGSpriterConfig.prototype.filter = function(config) {
config = config || {};
for (const m in config) {
const modeConfig = _.isPlainObject(config[m]) ? config[m] : ((config[m] === true) ? {} : null);
if ((modeConfig !== null) && (spriteTypes.has(modeConfig.mode || m))) {
if (modeConfig !== null && spriteTypes.has(modeConfig.mode || m)) {
filtered[m] = modeConfig;
filtered[m].mode = modeConfig.mode || m;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/svg-sprite/layouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const defaultConfig = {
}
};
const defaultVariables = {
date: (new Date()).toGMTString(),
date: new Date().toGMTString(),
invert() {
return (num, render) => -parseFloat(render(num));
},
Expand Down Expand Up @@ -110,7 +110,7 @@ function SVGSpriteLayouter(spriter, config) {
outer: dimensions.height
},
first: !index,
last: (index === (this._spriter._shapes.length - 1))
last: index === this._spriter._shapes.length - 1
});
});

Expand Down
6 changes: 3 additions & 3 deletions lib/svg-sprite/mode/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function SVGSpriteBase(spriter, config, data, key) {
}

// Prepare the rendering configurations
if (('render' in this.config) && _.isObject(this.config.render)) {
if ('render' in this.config && _.isObject(this.config.render)) {
for (const extension in this.config.render) {
const renderConfig = {
template: path.resolve(path.dirname(path.dirname(path.dirname(__dirname))), path.join('tmpl', this.tmpl, 'sprite.' + extension)),
Expand All @@ -72,7 +72,7 @@ function SVGSpriteBase(spriter, config, data, key) {
this.config.render[extension] = renderConfig;
}

this._cssDest = ('css' in this.config.render) ? path.dirname(this.config.render.css.dest) : this.config.dest;
this._cssDest = 'css' in this.config.render ? path.dirname(this.config.render.css.dest) : this.config.dest;
} else {
this._cssDest = this.config.dest;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ SVGSpriteBase.prototype._buildHTMLExample = function(files, cb) {
* @return {String} Coordinate (number) with unit appended
*/
SVGSpriteBase.prototype._addUnit = function(number, unit) {
return number + ((number !== 0) ? (unit || 'px') : '');
return number + (number !== 0 ? unit || 'px' : '');
};

/**
Expand Down
34 changes: 18 additions & 16 deletions lib/svg-sprite/mode/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ SVGSpriteCss.prototype = _.create(SVGSpriteBase.prototype, {
*/
SVGSpriteCss.prototype._init = function() {
// Prepare the dimension suffix
if (this.config.dimensions && (this.config.dimensions !== true)) {
this.config.dimensions = /%s/g.test((this.config.dimensions || '').split('%%').join('')) ? format(this.config.dimensions, this.config.prefix) : (this.config.prefix + this.config.dimensions);
if (this.config.dimensions && this.config.dimensions !== true) {
this.config.dimensions = /%s/g.test((this.config.dimensions || '').split('%%').join('')) ?
format(this.config.dimensions, this.config.prefix) :
this.config.prefix + this.config.dimensions;
}

// Determine the mixin mode and name
Expand Down Expand Up @@ -85,9 +87,9 @@ SVGSpriteCss.prototype._init = function() {
});

// Determine if this sprite accepts displaced shape copies
this._displaceable = ([this.LAYOUT_VERTICAL, this.LAYOUT_HORIZONTAL].includes(this.config.layout));
this._displaceable = [this.LAYOUT_VERTICAL, this.LAYOUT_HORIZONTAL].includes(this.config.layout);

this._precision = (Number(this.config.svg.precision) >= 0) ? Math.pow(10, Number(this.config.svg.precision)) : null;
this._precision = Number(this.config.svg.precision) >= 0 ? Math.pow(10, Number(this.config.svg.precision)) : null;
};

/**
Expand Down Expand Up @@ -131,7 +133,7 @@ SVGSpriteCss.prototype._layout = function() {
}, this._spriter);

// Layout the sprite
this[(this.config.layout === this.LAYOUT_PACKED) ? '_layoutBinPacked' : '_layoutSimple'](pseudoShapeMap);
this[this.config.layout === this.LAYOUT_PACKED ? '_layoutBinPacked' : '_layoutSimple'](pseudoShapeMap);

// Refine the shape data
let xmlDeclaration = null;
Expand All @@ -152,7 +154,7 @@ SVGSpriteCss.prototype._layout = function() {

// Else: Determine the relative horizontal position
} else {
x = shape.position.absolute.x ? (100 * Math.abs(shape.position.absolute.x) / (this.data.spriteWidth - shape.width.outer)) : 0;
x = shape.position.absolute.x ? 100 * Math.abs(shape.position.absolute.x) / (this.data.spriteWidth - shape.width.outer) : 0;
}

// For horizontal layouts: Set the vertical alignment
Expand All @@ -162,7 +164,7 @@ SVGSpriteCss.prototype._layout = function() {

// Else: Determine the relative vertical position
} else {
y = shape.position.absolute.y ? (100 * Math.abs(shape.position.absolute.y) / (this.data.spriteHeight - shape.height.outer)) : 0;
y = shape.position.absolute.y ? 100 * Math.abs(shape.position.absolute.y) / (this.data.spriteHeight - shape.height.outer) : 0;
}

// Set the relative position
Expand All @@ -182,15 +184,15 @@ SVGSpriteCss.prototype._layout = function() {
// Replace zero-valued x-positions
const svgX = svg[0].split(' x="0"');
if (svgX.length > 1) {
x = shape.master ? (shape.position.absolute.x - positionMap[shape.master].x) : shape.position.absolute.x;
svg[0] = svgX.join(x ? (' x="' + (-x) + '"') : '');
x = shape.master ? shape.position.absolute.x - positionMap[shape.master].x : shape.position.absolute.x;
svg[0] = svgX.join(x ? ' x="' + -x + '"' : '');
}

// Replace zero-valued y-positions
const svgY = svg[0].split(' y="0"');
if (svgY.length > 1) {
y = shape.master ? (shape.position.absolute.y - positionMap[shape.master].y) : shape.position.absolute.y;
svg[0] = svgY.join(y ? (' y="' + (-y) + '"') : '');
y = shape.master ? shape.position.absolute.y - positionMap[shape.master].y : shape.position.absolute.y;
svg[0] = svgY.join(y ? ' y="' + -y + '"' : '');
}

shape.svg = svg.join('>');
Expand Down Expand Up @@ -328,9 +330,9 @@ SVGSpriteCss.prototype._refineRootAttributes = function(shape, index, rootAttrib
SVGSpriteCss.prototype._addShapeToCSSSprite = function(shape, needsRegular, index, position, rootAttributes, positionX, positionY) {
// Prepare the selectors
const selector = {
shape: (needsRegular || shape.state) ? [{
expression: format(this.config.prefix, shape.base + (shape.state ? (':' + shape.state) : '')),
raw: format(this.config.prefix, shape.base + (shape.state ? (':' + shape.state) : '')),
shape: needsRegular || shape.state ? [{
expression: format(this.config.prefix, shape.base + (shape.state ? ':' + shape.state : '')),
raw: format(this.config.prefix, shape.base + (shape.state ? ':' + shape.state : '')),
first: true,
last: false
}, {
Expand Down Expand Up @@ -379,7 +381,7 @@ SVGSpriteCss.prototype._addShapeToCSSSprite = function(shape, needsRegular, inde
},
selector,
dimensions: {
inline: (this.config.dimensions === true),
inline: this.config.dimensions === true,
extra: Boolean(_.isString(this.config.dimensions) && this.config.dimensions.length)
}
});
Expand Down Expand Up @@ -433,7 +435,7 @@ SVGSpriteCss.prototype._buildSVG = function(xmlDeclaration, doctypeDeclaration)
* @return {Number} Rounded number
*/
SVGSpriteCss.prototype._round = function(n) {
return this._precision ? (Math.round(n * this._precision) / this._precision) : n;
return this._precision ? Math.round(n * this._precision) / this._precision : n;
};

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/svg-sprite/mode/css/packer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ SVGSpriteCssPacker.prototype._findNode = function(root, width, height) {
return this._findNode(root.right, width, height) || this._findNode(root.down, width, height);
}

if ((width <= root.width) && (height <= root.height)) {
if (width <= root.width && height <= root.height) {
return root;
}

Expand Down Expand Up @@ -109,10 +109,10 @@ SVGSpriteCssPacker.prototype._splitNode = function(node, width, height) {
* @param {Number} height Height
*/
SVGSpriteCssPacker.prototype._growNode = function(width, height) {
const canGrowBottom = (width <= this.root.width);
const canGrowRight = (height <= this.root.height);
const shouldGrowRight = canGrowRight && (this.root.height >= (this.root.width + width));
const shouldGrowBottom = canGrowBottom && (this.root.width >= (this.root.height + height));
const canGrowBottom = width <= this.root.width;
const canGrowRight = height <= this.root.height;
const shouldGrowRight = canGrowRight && this.root.height >= this.root.width + width;
const shouldGrowBottom = canGrowBottom && this.root.width >= this.root.height + height;
return shouldGrowRight ? this._growRight(width, height) :
(shouldGrowBottom ? this._growBottom(width, height) :
(canGrowRight ? this._growRight(width, height) :
Expand Down
4 changes: 3 additions & 1 deletion lib/svg-sprite/mode/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ SVGSpriteStandalone.prototype._init = function() {
// Prepare the dimension suffix
this.config.dimensions = _.isString(this.config.dimensions) ? this.config.dimensions.trim() : '-dims';
if (this.config.dimensions) {
this.config.dimensions = /%s/g.test((this.config.dimensions || '').split('%%').join('')) ? format(this.config.dimensions, this.config.prefix) : (this.config.prefix + this.config.dimensions);
this.config.dimensions = /%s/g.test((this.config.dimensions || '').split('%%').join('')) ?
format(this.config.dimensions, this.config.prefix) :
this.config.prefix + this.config.dimensions;
}

this.data.inline = Boolean(this.config.inline);
Expand Down
2 changes: 1 addition & 1 deletion lib/svg-sprite/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ SVGSpriterQueue.prototype.add = function(file) {
* Try to process an item in the queue
*/
SVGSpriterQueue.prototype.process = function() {
if (this._files.length && (this.active < this._spriter._limit)) {
if (this._files.length && this.active < this._spriter._limit) {
++this.active;
const file = this._files.shift();
let shape;
Expand Down

0 comments on commit 098f239

Please sign in to comment.