mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
dashboard: BaseWidget - Improve _formatBytes function, remove nested if statements, always return size+unit, implement additional null check. (#7729)
This commit is contained in:
parent
4182f19938
commit
b76b69aacd
@ -239,17 +239,18 @@ export default class BaseWidget {
|
||||
}
|
||||
|
||||
_formatBytes(value, decimals = 2) {
|
||||
if (!isNaN(value) && value > 0) {
|
||||
let fileSizeTypes = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
||||
let ndx = Math.floor(Math.log(value) / Math.log(1000) );
|
||||
if (ndx > 0) {
|
||||
return (value / Math.pow(1000, ndx)).toFixed(2) + ' ' + fileSizeTypes[ndx];
|
||||
} else {
|
||||
return value.toFixed(2);
|
||||
}
|
||||
} else {
|
||||
if (isNaN(value) || value === null || value < 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const fileSizeTypes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
const ndx = Math.floor(Math.log(value) / Math.log(1000));
|
||||
|
||||
if (ndx === 0) {
|
||||
return value.toFixed(decimals) + ' ' + fileSizeTypes[0];
|
||||
}
|
||||
|
||||
return (value / Math.pow(1000, ndx)).toFixed(decimals) + ' ' + fileSizeTypes[ndx];
|
||||
}
|
||||
|
||||
sanitizeSelector(selector) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user