| export function formatBytes(n: number): string { |
| if (n >= 1024 ** 3) return (n / 1024 ** 3).toFixed(2) + ' GB'; |
| if (n >= 1024 ** 2) return (n / 1024 ** 2).toFixed(0) + ' MB'; |
| if (n >= 1024) return (n / 1024).toFixed(0) + ' KB'; |
| return n + ' B'; |
| } |
|
|
| const ICONS: Record<string, string> = { |
| md: 'markdown', markdown: 'markdown', csv: 'csv', json: 'json', js: 'javascript', mjs: 'javascript', |
| ts: 'typescript', tsx: 'react', jsx: 'react', html: 'html', htm: 'html', css: 'css', sh: 'shell', |
| bash: 'shell', py: 'python', svg: 'svg', png: 'image', jpg: 'image', jpeg: 'image', gif: 'image', |
| pdf: 'pdf', zip: 'zip', yml: 'config', yaml: 'config', toml: 'config', ini: 'config', sql: 'db', |
| }; |
|
|
| export function iconFor(path: string): string { |
| const ext = path.split('.').pop()?.toLowerCase() ?? ''; |
| return ICONS[ext] ?? 'default'; |
| } |
|
|
| export const shortPath = (p: string) => p.replace(/^\/workspace\//, ''); |
|
|