()
| 12 | }) |
| 13 | |
| 14 | export const useBytesFormatter = () => { |
| 15 | const { t } = useI18n() |
| 16 | const decimalNumberFormatter = useNumberFormatter({ |
| 17 | maximumFractionDigits: 1, |
| 18 | }) |
| 19 | const KB = 1000 |
| 20 | const MB = 1000 * 1000 |
| 21 | |
| 22 | return { |
| 23 | format: (bytes: number) => { |
| 24 | if (bytes < KB) |
| 25 | return t('package.size.b', { |
| 26 | size: decimalNumberFormatter.value.format(bytes), |
| 27 | }) |
| 28 | if (bytes < MB) |
| 29 | return t('package.size.kb', { |
| 30 | size: decimalNumberFormatter.value.format(bytes / KB), |
| 31 | }) |
| 32 | return t('package.size.mb', { |
| 33 | size: decimalNumberFormatter.value.format(bytes / MB), |
| 34 | }) |
| 35 | }, |
| 36 | } |
| 37 | } |
no test coverage detected