Skip to content

Commit 5e3dbee

Browse files
committed
fix: 0 byte results in NaN in FileSizeIndicator
1 parent 34cabb6 commit 5e3dbee

File tree

1 file changed

+4
-4
lines changed
  • src/components/MessageComposer/hooks

1 file changed

+4
-4
lines changed

src/components/MessageComposer/hooks/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export function prettifyFileSize(bytes: number, precision = 3) {
22
const units = ['B', 'kB', 'MB', 'GB'];
3-
const exponent = Math.min(
4-
Math.floor(Math.log(bytes) / Math.log(1024)),
5-
units.length - 1,
6-
);
3+
const exponent =
4+
bytes === 0
5+
? 0
6+
: Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
77
const mantissa = bytes / 1024 ** exponent;
88
const formattedMantissa =
99
precision === 0 ? Math.round(mantissa).toString() : mantissa.toPrecision(precision);

0 commit comments

Comments
 (0)