MCPcopy Create free account
hub / github.com/343dev/optimizt / formatBytes

Function formatBytes

lib/format-bytes.js:6–15  ·  view source on GitHub ↗
(bytes)

Source from the content-addressed store, hash-verified

4const LOG_K = Math.log(K);
5
6export function formatBytes(bytes) {
7 if (bytes === 0) {
8 return '0 Bytes';
9 }
10
11 const index = Math.floor(Math.log(bytes) / LOG_K);
12 const value = Number((bytes / (K ** index)).toFixed(DECIMALS)); // Use Number to show "1 KB" instead of "1.000 KB"
13
14 return `${value} ${SIZES[index]}`;
15}

Callers 4

processFileFunction · 0.90
processFileFunction · 0.90
showTotalFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected