fix filesizeformat const/let stuff
This commit is contained in:
parent
b44df37c1b
commit
ee066c4436
|
@ -1,14 +1,13 @@
|
||||||
const fileSizeFormat = (num) => {
|
const fileSizeFormat = (numArg) => {
|
||||||
let exponent
|
|
||||||
let unit
|
|
||||||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||||
|
let num = numArg
|
||||||
if (num < 1) {
|
if (num < 1) {
|
||||||
return num + ' ' + units[0]
|
return num + ' ' + units[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1)
|
const exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1)
|
||||||
num = (num / Math.pow(1024, exponent)).toFixed(2) * 1
|
num = (num / Math.pow(1024, exponent)).toFixed(2) * 1
|
||||||
unit = units[exponent]
|
const unit = units[exponent]
|
||||||
return { num, unit }
|
return { num, unit }
|
||||||
}
|
}
|
||||||
const fileSizeFormatService = {
|
const fileSizeFormatService = {
|
||||||
|
|
Loading…
Reference in New Issue