Skip to content

Commit 5c103bc

Browse files
committed
Fix zero byte case
1 parent 6244234 commit 5c103bc

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

redisinsight/ui/src/utils/tests/transformers/formatBytes.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('formatBytes', () => {
4646
it('should return proper array with splitResults', () => {
4747
expect(formatBytes(1572864, 0, true)).toEqual([2, 'MB'])
4848
expect(formatBytes(1347545989, 3, true)).toEqual([1.255, 'GB'])
49+
expect(formatBytes(0, 3, true)).toEqual([0, 'B'])
4950
})
5051

5152
it('should properly set the baseK', () => {

redisinsight/ui/src/utils/transformers/formatBytes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const formatBytes = (
1111
const k = baseK
1212
const dm = decimals < 0 ? 0 : decimals
1313
if (Number.isNaN(bytes) || bytes < 0) return '-'
14-
if (bytes === 0) return `0 ${SIZES[0]}`
14+
if (bytes === 0) return splitResult ? [0, SIZES[0]] : `0 ${SIZES[0]}`
1515

1616
const i = Math.floor(Math.log(bytes) / Math.log(k))
1717
const sizeIndex = Math.min(i, SIZES.length - 1)

0 commit comments

Comments
 (0)