declare var module: any; /** * Format a number as a percentage * @param {Number} num Number to format as a percent * @param {Number} precision Precision of the decimal * @return {String} Formatted perentage */ var BytediffFormatter, FormatPercent; FormatPercent = function(num, precision) { return (num * 100).toFixed(precision); }; /** * Formatter for bytediff to display the size changes after processing * @param {Object} data - byte data * @return {String} Difference in bytes, formatted */ BytediffFormatter = function(data) { var difference; difference = data.savings > 0 ? ' smaller.' : ' larger.'; return data.fileName + ' went from ' + (data.startSize / 1000).toFixed(2) + ' kB to ' + (data.endSize / 1000).toFixed(2) + ' kB and is ' + FormatPercent(1 - data.percent, 2) + '%' + difference; }; module.exports = { bytediffFormatter: BytediffFormatter, formatPercent: FormatPercent };