Spaces:
Running
Running
File size: 927 Bytes
830f2f5 45fb44a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | export function formatBytes(n: number): string {
if (n >= 1e9) return `${(n / 1e9).toFixed(2)} GB`;
if (n >= 1e6) return `${Math.round(n / 1e6)} MB`;
if (n >= 1e3) return `${Math.round(n / 1e3)} KB`;
return `${n} B`;
}
export function formatDate(iso: string | null): string {
if (!iso) return "—";
return new Date(iso).toLocaleDateString(undefined, { day: "2-digit", month: "short", year: "numeric" });
}
/** Zero-padded two-digit number: 6 → "06". */
export const pad2 = (n: number) => String(n).padStart(2, "0");
/** FNV-1a string hash → uint32; seeds placeholder colours. */
export function hash(str: string): number {
let h = 0x811c9dc5;
for (let i = 0; i < str.length; i++) {
h ^= str.charCodeAt(i);
h = Math.imul(h, 0x01000193);
}
return h >>> 0;
}
/** Short tag for a base model folder: "MOSS-Image" → "MOSS", "Krea2" → "Krea2". */
export const modelLabel = (id: string) => id.split("-")[0];
|