mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
json viewer: updated size display
This commit is contained in:
@@ -14,10 +14,10 @@ export function ensureInt(value?: string | number | null | undefined): number {
|
||||
|
||||
export const formatNumber = {
|
||||
fileSize: (bytes: number, decimals = 2): string => {
|
||||
if (bytes === 0) return "0 Bytes";
|
||||
if (bytes === 0) return "0 B";
|
||||
const k = 1024;
|
||||
const dm = decimals < 0 ? 0 : decimals;
|
||||
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Number.parseFloat((bytes / k ** i).toFixed(dm)) + " " + sizes[i];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user