Download desktop/src/lib/formatBytes.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 488 Bytes
-
https://huggingface.co/chenbhao/codev/resolve/e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/lib/formatBytes.ts
- Command line
-
hf download hf://chenbhao/codev@e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/lib/formatBytes.ts
-
curl -L -o formatBytes.ts https://huggingface.co/chenbhao/codev/resolve/e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/lib/formatBytes.ts
488 Bytes
| export function formatBytes(bytes: number): string { | |
| if (!Number.isFinite(bytes) || bytes <= 0) return '0 B' | |
| const units = ['B', 'KB', 'MB', 'GB', 'TB'] | |
| let value = bytes | |
| let unitIndex = 0 | |
| while (value >= 1024 && unitIndex < units.length - 1) { | |
| value /= 1024 | |
| unitIndex += 1 | |
| } | |
| const maximumFractionDigits = value >= 10 || unitIndex === 0 ? 0 : 1 | |
| return `${new Intl.NumberFormat(undefined, { | |
| maximumFractionDigits, | |
| }).format(value)} ${units[unitIndex]}` | |
| } | |