export function formatBytes(bytes: number): string { if (bytes === 0) return '0 B'; const units = ['B', 'KB', 'MB', 'GB', 'TB']; const i = Math.floor(Math.log(bytes) / Math.log(1024)); const val = bytes / Math.pow(1024, i); return `${val.toFixed(i === 0 ? 0 : 1)} ${units[i]}`; } export function formatNumber(n: number): string { return n.toLocaleString(); } export function timeAgo(dateStr: string): string { const seconds = Math.floor((Date.now() - new Date(dateStr).getTime()) / 1000); if (seconds < 60) return `${seconds}s ago`; const minutes = Math.floor(seconds / 60); if (minutes < 60) return `${minutes}m ago`; const hours = Math.floor(minutes / 60); if (hours < 24) return `${hours}h ago`; const days = Math.floor(hours / 24); return `${days}d ago`; } export function truncateHash(hash: string, len = 12): string { if (hash.startsWith('sha256:')) { return hash.slice(0, 7 + len); } return hash.slice(0, len); }