manage model

This commit is contained in:
n4ze3m
2024-02-18 13:23:47 +05:30
parent d763c286c1
commit ecbff6093b
10 changed files with 392 additions and 40 deletions

23
src/libs/byte-formater.ts Normal file
View File

@@ -0,0 +1,23 @@
const UNITS = [
"byte",
"kilobyte",
"megabyte",
"gigabyte",
"terabyte",
"petabyte"
]
const getValueAndUnit = (n: number) => {
const i = n == 0 ? 0 : Math.floor(Math.log(n) / Math.log(1024))
const value = n / Math.pow(1024, i)
return { value, unit: UNITS[i] }
}
export const bytePerSecondFormatter = (n: number) => {
const { unit, value } = getValueAndUnit(n)
return new Intl.NumberFormat("en", {
notation: "compact",
style: "unit",
unit
}).format(value)
}