Spaces:
Running
Running
Download apps/admin/src/lib/utils.ts from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/admin/src/lib/utils.ts
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/admin/src/lib/utils.ts
-
curl -L -o utils.ts https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/admin/src/lib/utils.ts
1.16 kB
| import { type ClassValue, clsx } from "clsx"; | |
| export function cn(...inputs: ClassValue[]) { | |
| return clsx(inputs); | |
| } | |
| export function formatBytes(bytes: number): string { | |
| if (bytes === 0) return "0 B"; | |
| const k = 1024; | |
| const sizes = ["B", "KB", "MB", "GB", "TB"]; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`; | |
| } | |
| export function formatMs(ms: number): string { | |
| if (ms < 1000) return `${ms}ms`; | |
| return `${(ms / 1000).toFixed(1)}s`; | |
| } | |
| export function formatUptime(seconds: number): string { | |
| const d = Math.floor(seconds / 86400); | |
| const h = Math.floor((seconds % 86400) / 3600); | |
| const m = Math.floor((seconds % 3600) / 60); | |
| if (d > 0) return `${d}d ${h}h`; | |
| if (h > 0) return `${h}h ${m}m`; | |
| return `${m}m`; | |
| } | |
| export function ago(dateStr: string): string { | |
| const diff = Date.now() - new Date(dateStr).getTime(); | |
| const s = Math.floor(diff / 1000); | |
| if (s < 60) return `${s}s ago`; | |
| const m = Math.floor(s / 60); | |
| if (m < 60) return `${m}m ago`; | |
| const h = Math.floor(m / 60); | |
| if (h < 24) return `${h}h ago`; | |
| return `${Math.floor(h / 24)}d ago`; | |
| } | |