We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 34cabb6 commit 5e3dbeeCopy full SHA for 5e3dbee
src/components/MessageComposer/hooks/utils.ts
@@ -1,9 +1,9 @@
1
export function prettifyFileSize(bytes: number, precision = 3) {
2
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
- );
+ const exponent =
+ bytes === 0
+ ? 0
+ : Math.min(Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
7
const mantissa = bytes / 1024 ** exponent;
8
const formattedMantissa =
9
precision === 0 ? Math.round(mantissa).toString() : mantissa.toPrecision(precision);
0 commit comments