mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-12-02 21:30:16 +09:00
Fixes for 2 code quality findings (#3302)
* Apply suggested fix to src/themes/admin_default/assets/js/utils.js from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Apply suggested fix to src/themes/admin_default/assets/js/utils.js from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
21de5d8d21
commit
e21ebfcc4a
1 file changed
+3
-2
@@ -145,15 +145,16 @@ export function scrollToElement(target, options = {}) {
|
||||
* @returns {string} Formatted string
|
||||
*/
|
||||
export function formatBytes(bytes, decimals = 2) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
if (!Number.isFinite(bytes) || bytes <= 0) return '0 Bytes';
|
||||
|
||||
const k = 1024;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
const index = Math.min(Math.max(i, 0), sizes.length - 1);
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
return parseFloat((bytes / Math.pow(k, index)).toFixed(dm)) + ' ' + sizes[index];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user