Skip to content

Commit 4e532f5

Browse files
committed
refactor(ui): wrapped formatter
Signed-off-by: Neko Ayaka <[email protected]>
1 parent cb5104b commit 4e532f5

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

app/composables/intlNumberFormat.ts

+14
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,17 @@ export function useKiloBytesNumberFormat(
3434
unit: 'kilobyte',
3535
})
3636
}
37+
38+
export function useKiloBytesPerSecondNumberFormat(
39+
value: MaybeRef<number | string> | ComputedRef<number | string>,
40+
options?: {
41+
locales?: Intl.LocalesArgument
42+
} & Intl.NumberFormatOptions,
43+
) {
44+
return useNumberFormat(value, {
45+
...options,
46+
style: 'unit',
47+
unit: 'kilobyte-per-second',
48+
unitDisplay: 'short',
49+
})
50+
}

app/composables/timeseries.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { ComputedRef, Ref } from 'vue'
22
import { computed, ref } from 'vue'
33

4+
import { useKiloBytesPerSecondNumberFormat } from './intlNumberFormat'
5+
46
interface TimeSeriesOptions {
57
type: 'counter' | 'gauge'
68
interval: number
@@ -126,16 +128,10 @@ export function useBytesRate(
126128
lastUpdateTime.value = now
127129
})
128130

129-
const kiloBytesFormatter = new Intl.NumberFormat('en-US', {
130-
style: 'unit',
131-
unit: 'kilobyte-per-second',
132-
unitDisplay: 'short',
133-
})
134-
135-
const formatted = computed(() => {
131+
const formatted = useKiloBytesPerSecondNumberFormat(computed(() => {
136132
const kiloBytesPerSecond = bytesRate.value / 1024
137-
return kiloBytesFormatter.format(Number.parseFloat(kiloBytesPerSecond.toFixed(2)))
138-
})
133+
return Number.parseFloat(kiloBytesPerSecond.toFixed(2))
134+
}))
139135

140136
return {
141137
bytesRate,

0 commit comments

Comments
 (0)