MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / formatFileSize

Function formatFileSize

app/src/utils/utils.ts:5–18  ·  view source on GitHub ↗
(bytes: number, decimals = 2)

Source from the content-addressed store, hash-verified

3export const truthyFilter = <T>(x: T | null | undefined): x is T => Boolean(x);
4
5export const formatFileSize = (bytes: number, decimals = 2) => {
6 if (bytes === 0) return "0 Bytes";
7
8 const k = 1024;
9 const dm = decimals < 0 ? 0 : decimals;
10 const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
11
12 for (const size of sizes) {
13 if (bytes < k) return `${parseFloat(bytes.toFixed(dm))} ${size}`;
14 bytes /= k;
15 }
16
17 return "> 1024 TB";
18};
19
20export const ensureDefaultExport = <T>(module: T) => {
21 const defaultExport = module as unknown as { default: T };

Callers 2

FileUploadRowFunction · 0.90
UploadDataModalFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected