MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / formatBytes

Function formatBytes

app/utilities/formatter.ts:146–156  ·  view source on GitHub ↗
(bytes: number, decimals = 2)

Source from the content-addressed store, hash-verified

144}
145
146export function formatBytes(bytes: number, decimals = 2): string {
147 if (bytes === 0) return "0 Bytes";
148
149 const k = 1024;
150 const dm = decimals < 0 ? 0 : decimals;
151 const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
152
153 const i = Math.floor(Math.log(bytes) / Math.log(k));
154
155 return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
156}

Callers 1

PreviewImageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected