MCPcopy Create free account
hub / github.com/protomaps/PMTiles / formatBytes

Function formatBytes

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

Source from the content-addressed store, hash-verified

51}
52
53export function formatBytes(bytes: number, decimals = 2) {
54 if (!+bytes) return "0 Bytes";
55 const k = 1024;
56 const dm = decimals < 0 ? 0 : decimals;
57 const sizes = [
58 "Bytes",
59 "KiB",
60 "MiB",
61 "GiB",
62 "TiB",
63 "PiB",
64 "EiB",
65 "ZiB",
66 "YiB",
67 ];
68 const i = Math.floor(Math.log(bytes) / Math.log(k));
69 return `${Number.parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
70}

Callers 1

ArchiveViewFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…