Skip to content

Commit e5b9d31

Browse files
AntikodeAntikode
authored andcommitted
fix: formatSize() rounding boundary showed "1024 KB" instead of switching to MB
Any file between 1048064-1048575 bytes (a completely realistic PDF size) rounded via toFixed(0) to display as "1024 KB" rather than switching to the MB tier, since the branch check compared raw bytes against 1024*1024 before rounding was applied. Fixed by checking the rounded KB value against the threshold instead.
1 parent fb12c50 commit e5b9d31

24 files changed

Lines changed: 48 additions & 24 deletions

app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ if ("PerformanceObserver" in window) {
3939

4040
function formatSize(bytes) {
4141
if (bytes < 1024) return `${bytes} B`;
42-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
42+
const kb = bytes / 1024;
43+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4344
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4445
}
4546

bookmarks.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ if ("PerformanceObserver" in window) {
4444

4545
function formatSize(bytes) {
4646
if (bytes < 1024) return `${bytes} B`;
47-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
47+
const kb = bytes / 1024;
48+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4849
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4950
}
5051

border.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ if ("PerformanceObserver" in window) {
4141

4242
function formatSize(bytes) {
4343
if (bytes < 1024) return `${bytes} B`;
44-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
44+
const kb = bytes / 1024;
45+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4546
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4647
}
4748

compress.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ if ("PerformanceObserver" in window) {
5454

5555
function formatSize(bytes) {
5656
if (bytes < 1024) return `${bytes} B`;
57-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
57+
const kb = bytes / 1024;
58+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
5859
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
5960
}
6061

crop.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ if ("PerformanceObserver" in window) {
4242

4343
function formatSize(bytes) {
4444
if (bytes < 1024) return `${bytes} B`;
45-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
45+
const kb = bytes / 1024;
46+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4647
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4748
}
4849

delete-pages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ if ("PerformanceObserver" in window) {
3939

4040
function formatSize(bytes) {
4141
if (bytes < 1024) return `${bytes} B`;
42-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
42+
const kb = bytes / 1024;
43+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4344
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4445
}
4546

duplicate-pages.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ if ("PerformanceObserver" in window) {
3939

4040
function formatSize(bytes) {
4141
if (bytes < 1024) return `${bytes} B`;
42-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
42+
const kb = bytes / 1024;
43+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4344
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4445
}
4546

extract-images.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ if ("PerformanceObserver" in window) {
4242

4343
function formatSize(bytes) {
4444
if (bytes < 1024) return `${bytes} B`;
45-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
45+
const kb = bytes / 1024;
46+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4647
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4748
}
4849

fill-form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ if ("PerformanceObserver" in window) {
3939

4040
function formatSize(bytes) {
4141
if (bytes < 1024) return `${bytes} B`;
42-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
42+
const kb = bytes / 1024;
43+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4344
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4445
}
4546

flatten.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ if ("PerformanceObserver" in window) {
3838

3939
function formatSize(bytes) {
4040
if (bytes < 1024) return `${bytes} B`;
41-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`;
41+
const kb = bytes / 1024;
42+
if (Math.round(kb) < 1024) return `${kb.toFixed(0)} KB`;
4243
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
4344
}
4445

0 commit comments

Comments
 (0)