Download next.js/turbopack/packages/devlow-bench/src/units.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 557 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/packages/devlow-bench/src/units.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/packages/devlow-bench/src/units.ts
-
curl -L -o units.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/packages/devlow-bench/src/units.ts
557 Bytes
| const UNITS: Record<string, Record<string, number>> = { | |
| ms: { | |
| ' s': 1000, | |
| }, | |
| bytes: { | |
| ' GB': 1024 * 1024 * 1024, | |
| ' MB': 1024 * 1024, | |
| ' KB': 1024, | |
| }, | |
| requests: { | |
| 'K requests': 1000, | |
| }, | |
| } | |
| export function formatUnit(value: number, unit: string) { | |
| const conversion = UNITS[unit] | |
| if (conversion) { | |
| for (const [name, factor] of Object.entries(conversion)) { | |
| if (value >= factor) { | |
| return `${(value / factor).toFixed(2)}${name}` | |
| } | |
| } | |
| } | |
| return `${value.toFixed(2).replace(/\.00$/, '')} ${unit}` | |
| } | |