MCPcopy
hub / github.com/webpack/webpack / formatSize

Function formatSize

lib/util/formatSize.js:13–26  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

11 * @returns {string} the formatted size
12 */
13const formatSize = (size) => {
14 if (typeof size !== "number" || Number.isNaN(size) === true) {
15 return "unknown size";
16 }
17
18 if (size <= 0) {
19 return "0 bytes";
20 }
21
22 const abbreviations = ["bytes", "KiB", "MiB", "GiB"];
23 const index = Math.floor(Math.log(size) / Math.log(1024));
24
25 return `${Number((size / 1024 ** index).toPrecision(3))} ${abbreviations[index]}`;
26};
27
28module.exports = formatSize;

Callers 9

getMethod · 0.85
unpackMethod · 0.85
writeLazyMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
constructorMethod · 0.85
printSizesFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected