From 166ba54c4b2fbd2c28a65b518ede9c9d9d7f6fd2 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 9 Nov 2019 23:34:36 -0500 Subject: [PATCH] change to 0 KB if bytes == 0 --- src/functions/dataConversion.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions/dataConversion.ts b/src/functions/dataConversion.ts index e38337d..f72a611 100644 --- a/src/functions/dataConversion.ts +++ b/src/functions/dataConversion.ts @@ -1,5 +1,8 @@ -export default function dataConversion(bytes: number) { +export default function dataConversion(bytes) { const i = Math.floor(Math.log(bytes) / Math.log(1024)); const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + if (bytes === 0) { + return '0 KB'; + } return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`; }