Skip to content

Commit ed058eb

Browse files
committed
Improved formatBytes fn
1 parent 7e6673b commit ed058eb

File tree

1 file changed

+2
-1
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query

1 file changed

+2
-1
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query/route.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2033,9 +2033,10 @@ function formatQueryStats(stats: {
20332033

20342034
function formatBytes(bytes: number): string {
20352035
if (bytes === 0) return "0 B";
2036+
if (bytes < 0) return "-" + formatBytes(-bytes);
20362037
const k = 1024;
20372038
const sizes = ["B", "KB", "MB", "GB"];
2038-
const i = Math.floor(Math.log(bytes) / Math.log(k));
2039+
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
20392040
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
20402041
}
20412042

0 commit comments

Comments
 (0)