Something went wrong. Try again.
Getǣl — Read-only macOS home directory disk usage cartography & APFS telemetry service
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import type { FileCategory } from '../api/types.ts';
export const CATEGORY_META: Record<FileCategory, { label: string; color: string }> = { code_builds: { label: 'Code & Builds', color: '#5A82A6' }, media_video: { label: 'Media & Video', color: '#B86552' }, models_data: { label: 'Models & Data', color: '#C98A3A' }, archives_images: { label: 'Archives & Images', color: '#7A7399' }, caches_logs: { label: 'Caches & Logs', color: '#4F8F7D' }, apps_binaries: { label: 'Apps & Binaries', color: '#548A94' }, documents: { label: 'Documents', color: '#9A9080' }, other: { label: 'Other', color: '#636A78' },};
export function formatBytes(bytes: number): string { if (!Number.isFinite(bytes) || bytes <= 0) return '0 B'; const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; const exp = Math.min(Math.floor(Math.log(bytes) / Math.log(1000)), units.length - 1); const val = bytes / 1000 ** exp; const unit = units[exp] ?? 'B'; if (exp === 0) return `${String(Math.round(val))} B`; return `${val >= 100 ? val.toFixed(0) : val >= 10 ? val.toFixed(1) : val.toFixed(2)} ${unit}`;}
export function formatSignedBytes(delta: number): string { const sign = delta >= 0 ? '+' : '-'; return `${sign}${formatBytes(Math.abs(delta))}`;}
export function formatPercent(part: number, total: number): string { if (total <= 0) return '0.0%'; const pct = (part / total) * 100; if (pct < 0.1 && pct > 0) return '<0.1%'; return `${pct.toFixed(1)}%`;}
export function formatRelativeNs(mtimeNs: number, nowMs = Date.now()): string { if (!mtimeNs) return '—'; const mtimeMs = mtimeNs / 1_000_000; const diffSecs = Math.max(0, Math.floor((nowMs - mtimeMs) / 1000)); if (diffSecs < 60) return `${String(diffSecs)}s ago`; const mins = Math.floor(diffSecs / 60); if (mins < 60) return `${String(mins)}m ago`; const hours = Math.floor(mins / 60); if (hours < 24) return `${String(hours)}h ago`; const days = Math.floor(hours / 24); if (days < 30) return `${String(days)}d ago`; const months = Math.floor(days / 30); if (months < 12) return `${String(months)}mo ago`; const years = (days / 365).toFixed(1); return `${years}y ago`;}
export function formatDisplayPath( relPath: string, homeDisplay = '~', isWindows = false,): string { if (relPath === '') return homeDisplay; const sep = isWindows ? '\\' : '/'; const base = homeDisplay.length > 1 ? homeDisplay.replace(/[\\/]+$/, '') : homeDisplay; const normalizedRel = isWindows ? relPath.replaceAll('/', '\\') : relPath; return base.endsWith(sep) ? `${base}${normalizedRel}` : `${base}${sep}${normalizedRel}`;}