Download src/lib/format.ts from noodcon/PI: direct link, hf CLI and curl.
- Browser
- Download file 918 Bytes
-
https://huggingface.co/spaces/noodcon/PI/resolve/main/src/lib/format.ts
- Command line
-
hf download hf://spaces/noodcon/PI/src/lib/format.ts
-
curl -L -o format.ts https://huggingface.co/spaces/noodcon/PI/resolve/main/src/lib/format.ts
918 Bytes
| 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\//, ''); | |