webpack/lib/SizeFormatHelpers.js

11 lines
332 B
JavaScript
Raw Normal View History

var SizeFormatHelpers = exports;
SizeFormatHelpers.formatSize = function(size) {
if(size <= 0) return "0 bytes";
var abbreviations = ["bytes", "kB", "MB", "GB"];
var index = Math.floor(Math.log(size) / Math.log(1000));
return +(size / Math.pow(1000, index))
.toPrecision(3) + " " + abbreviations[index];
}