Spaces:
Running
Running
Download src/lib/format.ts from Orion-zhen/tokenize-it: direct link, hf CLI and curl.
- Browser
- Download file 680 Bytes
-
https://huggingface.co/spaces/Orion-zhen/tokenize-it/resolve/main/src/lib/format.ts
- Command line
-
hf download hf://spaces/Orion-zhen/tokenize-it/src/lib/format.ts
-
curl -L -o format.ts https://huggingface.co/spaces/Orion-zhen/tokenize-it/resolve/main/src/lib/format.ts
680 Bytes
| export function formatBytes(bytes: number): string { | |
| if (bytes < 1024) return `${bytes} B`; | |
| const units = ["KB", "MB", "GB"]; | |
| let value = bytes / 1024; | |
| let unit = units[0]; | |
| for (let index = 1; index < units.length && value >= 1024; index += 1) { | |
| value /= 1024; | |
| unit = units[index]; | |
| } | |
| return `${value >= 10 ? value.toFixed(1) : value.toFixed(2)} ${unit}`; | |
| } | |
| export function formatDuration(milliseconds: number): string { | |
| if (milliseconds < 1) return "< 1 ms"; | |
| if (milliseconds < 1000) return `${milliseconds.toFixed(1)} ms`; | |
| return `${(milliseconds / 1000).toFixed(2)} s`; | |
| } | |
| export function shortSha(sha: string): string { | |
| return sha.slice(0, 8); | |
| } | |