MCPcopy Create free account
hub / github.com/botbotrobotics/BotBrain / formatBytes

Function formatBytes

frontend/src/utils/format-utils.tsx:6–16  ·  view source on GitHub ↗
(bytes: number, decimals: number = 1)

Source from the content-addressed store, hash-verified

4 * @returns Formatted string with appropriate units (B, KB, MB, GB)
5 */
6export function formatBytes(bytes: number, decimals: number = 1): string {
7 if (bytes === 0) return '0 B';
8
9 const k = 1024;
10 const sizes = ['B', 'KB', 'MB', 'GB'];
11
12 const i = Math.floor(Math.log(bytes) / Math.log(k));
13 const value = bytes / Math.pow(k, i);
14
15 return `${value.toFixed(decimals)} ${sizes[i]}`;
16}
17
18/**
19 * Format latency to human-readable format with appropriate units

Callers 1

formatDataRateFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected