Skip to content

Commit f94f9d6

Browse files
committed
fix: allow negative bytes
1 parent cd8efe3 commit f94f9d6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

build/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24561,10 +24561,12 @@ var core5 = __toESM(require_core(), 1);
2456124561
// src/common.ts
2456224562
function formatBytes(bytes) {
2456324563
if (bytes === 0) return "0 B";
24564+
const absBytes = Math.abs(bytes);
2456424565
const k = 1e3;
2456524566
const sizes = ["B", "kB", "MB", "GB"];
24566-
const i = Math.floor(Math.log(bytes) / Math.log(k));
24567-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
24567+
const i = Math.floor(Math.log(absBytes) / Math.log(k));
24568+
const byteValue = parseFloat((absBytes / Math.pow(k, i)).toFixed(1));
24569+
return `${bytes < 0 ? -byteValue : byteValue} ${sizes[i]}`;
2456824570
}
2456924571

2457024572
// src/checks/dependency-size.ts

src/common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export function formatBytes(bytes: number): string {
22
if (bytes === 0) return '0 B';
3+
const absBytes = Math.abs(bytes);
34
const k = 1000;
45
const sizes = ['B', 'kB', 'MB', 'GB'];
5-
const i = Math.floor(Math.log(bytes) / Math.log(k));
6-
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
6+
const i = Math.floor(Math.log(absBytes) / Math.log(k));
7+
const byteValue = parseFloat((absBytes / Math.pow(k, i)).toFixed(1));
8+
return `${bytes < 0 ? -byteValue : byteValue} ${sizes[i]}`;
79
}

0 commit comments

Comments
 (0)