Spaces:
Running
Running
| // frontend/lib/utils.ts | |
| import { type ClassValue, clsx } from 'clsx' | |
| import { twMerge } from 'tailwind-merge' | |
| export function cn(...inputs: ClassValue[]) { | |
| return twMerge(clsx(inputs)) | |
| } | |
| export function formatBytes(bytes: number): string { | |
| if (bytes === 0) return '0 B' | |
| const k = 1024 | |
| const sizes = ['B', 'KB', 'MB', 'GB'] | |
| 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 `${Math.round(ms)}ms` | |
| return `${(ms / 1000).toFixed(1)}s` | |
| } | |
| export function formatConfidence(confidence: number): string { | |
| return `${(confidence * 100).toFixed(1)}%` | |
| } | |
| export function clampConfidence(v: number): number { | |
| return Math.max(0, Math.min(1, v)) | |
| } | |