fix: use IEC units for binary sizes (#2901)
This commit is contained in:
@@ -34,7 +34,7 @@ function fm(value) {
|
|||||||
exports.sizeFormate = size => {
|
exports.sizeFormate = size => {
|
||||||
// https://gist.github.com/thomseddon/3511330
|
// https://gist.github.com/thomseddon/3511330
|
||||||
if (!size) return '0 b'
|
if (!size) return '0 b'
|
||||||
let units = ['b', 'kB', 'MB', 'GB', 'TB']
|
let units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||||
let number = Math.floor(Math.log(size) / Math.log(1024))
|
let number = Math.floor(Math.log(size) / Math.log(1024))
|
||||||
return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}`
|
return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const getRandom = (min: number, max: number): number => Math.floor(Math.r
|
|||||||
export const sizeFormate = (size: number): string => {
|
export const sizeFormate = (size: number): string => {
|
||||||
// https://gist.github.com/thomseddon/3511330
|
// https://gist.github.com/thomseddon/3511330
|
||||||
if (!size) return '0 B'
|
if (!size) return '0 B'
|
||||||
let units = ['B', 'KB', 'MB', 'GB', 'TB']
|
let units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||||
let number = Math.floor(Math.log(size) / Math.log(1024))
|
let number = Math.floor(Math.log(size) / Math.log(1024))
|
||||||
return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}`
|
return `${(size / Math.pow(1024, Math.floor(number))).toFixed(2)} ${units[number]}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user