Enhance FileSizePipe to handle NaN and zero bytes for better resilience

pull/385/head
vkartk 2024-01-26 09:48:44 +05:30
parent 3f4240a526
commit feec0c56b4
1 changed files with 1 additions and 1 deletions

View File

@ -50,7 +50,7 @@ export class EncodeURIComponent implements PipeTransform {
})
export class FileSizePipe implements PipeTransform {
transform(value: number): string {
if (value === 0) return '0 Bytes';
if (isNaN(value) || value === 0) return '0 Bytes';
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const unitIndex = Math.floor(Math.log(value) / Math.log(1000)); // Use 1000 for common units