change to 0 KB if bytes == 0

merge-requests/1/merge
Matthew 2019-11-09 23:34:36 -05:00
parent 0c55303505
commit 166ba54c4b
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 4 additions and 1 deletions

View File

@ -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 i = Math.floor(Math.log(bytes) / Math.log(1024));
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; 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]}`; return `${(bytes / 1024 ** i).toFixed(2)} ${sizes[i]}`;
} }