MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / formatBytes

Function formatBytes

apps/site/scripts/compare-size/index.mjs:8–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6 * @returns {string} Formatted string (e.g., "1.5 KB")
7 */
8const formatBytes = bytes => {
9 if (bytes === 0) {
10 return '0 B';
11 }
12 const units = ['B', 'KB', 'MB', 'GB'];
13 const index = Math.floor(Math.log(Math.abs(bytes)) / Math.log(1024));
14 return (bytes / Math.pow(1024, index)).toFixed(2) + ' ' + units[index];
15};
16
17/**
18 * Calculates percentage change

Callers 1

reportDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected