mirror of
https://github.com/BioArchLinux/Rosa.git
synced 2025-03-10 12:02:43 +00:00
use constant
This commit is contained in:
parent
a67b4c3a9e
commit
403d260b91
1 changed files with 6 additions and 4 deletions
|
@ -1,14 +1,16 @@
|
|||
const DATA_UNIT_FACTOR = 1024
|
||||
|
||||
export function calculateSize(size) {
|
||||
function wellSized(num) {
|
||||
return num > 1 && num < 1024
|
||||
return num > 1 && num < DATA_UNIT_FACTOR
|
||||
}
|
||||
if (size === undefined) { return }
|
||||
if (wellSized(size)) { return `${size.toFixed(1)} B` }
|
||||
size /= 1024
|
||||
size /= DATA_UNIT_FACTOR
|
||||
if (wellSized(size)) { return `${size.toFixed(1)} KB` }
|
||||
size /= 1024
|
||||
size /= DATA_UNIT_FACTOR
|
||||
if (wellSized(size)) { return `${size.toFixed(1)} MB` }
|
||||
size /= 1024
|
||||
size /= DATA_UNIT_FACTOR
|
||||
if (wellSized(size)) { return `${size.toFixed(1)} GB` }
|
||||
console.error('size too big')
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue