diff --git a/lib/svgo/coa.js b/lib/svgo/coa.js index 52d640c4a..c7f2c827e 100644 --- a/lib/svgo/coa.js +++ b/lib/svgo/coa.js @@ -12,6 +12,7 @@ const regSVGFile = /\.svg$/i; /** * Synchronously check if path is a directory. Tolerant to errors like ENOENT. + * * @param {string} path */ function checkIsDir(path) { @@ -276,6 +277,7 @@ async function action(args, opts, command) { /** * Optimize SVG files in a directory. + * * @param {Object} config options * @param {string} dir input directory * @param {string} output output directory @@ -292,6 +294,7 @@ function optimizeFolder(config, dir, output) { /** * Process given files, take only SVG. + * * @param {Object} config options * @param {string} dir input directory * @param {Array} files list of file names in the directory @@ -318,7 +321,8 @@ function processDirectory(config, dir, files, output) { } /** - * Get svg files descriptions + * Get SVG files descriptions. + * * @param {Object} config options * @param {string} dir input directory * @param {Array} files list of file names in the directory @@ -360,6 +364,7 @@ function getFilesDescriptions(config, dir, files, output) { /** * Read SVG file and pass to processing. + * * @param {Object} config options * @param {string} file * @param {string} output @@ -375,6 +380,7 @@ function optimizeFile(config, file, output) { /** * Optimize SVG data. + * * @param {Object} config options * @param {string} data SVG content to optimize * @param {string} output where to write optimized file @@ -425,6 +431,7 @@ function processSVGData(config, info, data, output, input) { /** * Write result of an optimization. + * * @param {string} input * @param {string} output output file name. '-' for stdout * @param {string} data data to write @@ -444,7 +451,8 @@ function writeOutput(input, output, data) { } /** - * Write a time taken by optimization. + * Write time taken to optimize. + * * @param {number} time time in milliseconds. */ function printTimeInfo(time) { @@ -452,26 +460,28 @@ function printTimeInfo(time) { } /** - * Write optimizing information in human readable format. + * Write optimizing stats in a human-readable format. + * * @param {number} inBytes size before optimization. * @param {number} outBytes size after optimization. */ function printProfitInfo(inBytes, outBytes) { - var profitPercents = 100 - (outBytes * 100) / inBytes; + const profitPercent = 100 - (outBytes * 100) / inBytes; + /** @type {[string, Function]} */ + const ui = profitPercent < 0 ? ['+', colors.red] : ['-', colors.green]; console.log( - Math.round((inBytes / 1024) * 1000) / 1000 + - ' KiB' + - (profitPercents < 0 ? ' + ' : ' - ') + - colors.green(Math.abs(Math.round(profitPercents * 10) / 10) + '%') + - ' = ' + - Math.round((outBytes / 1024) * 1000) / 1000 + - ' KiB' + Math.round((inBytes / 1024) * 1000) / 1000 + ' KiB', + ui[0], + ui[1](Math.abs(Math.round(profitPercent * 10) / 10) + '%'), + '=', + Math.round((outBytes / 1024) * 1000) / 1000 + ' KiB' ); } /** * Check for errors, if it's a dir optimize the dir. + * * @param {Object} config * @param {string} input * @param {string} output @@ -491,6 +501,7 @@ function checkOptimizeFileError(config, input, output, error) { /** * Check for saving file error. If the output is a dir, then write file there. + * * @param {string} input * @param {string} output * @param {string} data @@ -509,9 +520,7 @@ function checkWriteFileError(input, output, data, error) { } } -/** - * Show list of available plugins with short description. - */ +/** Show list of available plugins with short description. */ function showAvailablePlugins() { const list = builtin .sort((a, b) => a.name.localeCompare(b.name))