(x: number, locale: Intl.LocalesArgument = "en-US")
| 15 | } |
| 16 | |
| 17 | export function formatByteSize(x: number, locale: Intl.LocalesArgument = "en-US"): string { |
| 18 | const formatOptions = {maximumSignificantDigits: 3, maximumFractionDigits: 2}; |
| 19 | for (const [k, suffix] of [ |
| 20 | [1e9, " GB"], |
| 21 | [1e6, " MB"], |
| 22 | [1e3, " kB"] |
| 23 | ] as const) { |
| 24 | if (Math.round((x / k) * 1e3) >= 1e3) { |
| 25 | return (x / k).toLocaleString(locale, formatOptions) + suffix; |
| 26 | } |
| 27 | } |
| 28 | return x.toLocaleString(locale, formatOptions) + " B"; |
| 29 | } |
no outgoing calls
no test coverage detected