Something went wrong. Try again.
Large file storage for AT Protocol: an IPFS server & gateway with XRPC upload & admin. atfs.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132/** Human byte sizes, in the decimal units file managers and `ls -h` show. */export function formatBytes(bytes: number | null | undefined): string { if (typeof bytes !== "number" || !Number.isFinite(bytes) || bytes < 0) return "—"; if (bytes < 1000) return `${bytes} B`;
const units = ["kB", "MB", "GB", "TB", "PB"]; let value = bytes / 1000; let unit = 0; while (value >= 1000 && unit < units.length - 1) { value /= 1000; unit += 1; } return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;}
/** * A listing timestamp as a plain calendar date in the reader's own locale * and zone. * * Null — an instance that took the upload before its clock was set — and an * unparseable string are the same em dash: both mean "this instance can't * tell you", and distinguishing them would only expose a wire detail. */export function formatDate(iso: string | null | undefined): string { if (typeof iso !== "string") return "—";
const at = new Date(iso); if (Number.isNaN(at.getTime())) return "—";
return at.toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });}