import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'fileSize' } ) export class FileSizePipe implements PipeTransform { transform ( value ) { if ( ! value ) { return value ; } const units = [ 'B' , 'KB' , 'MB' , 'GB' , 'TB' ] ; const idx = Math . floor ( Math . log ( value ) / Math . log ( 1024 ) ) ; const formattedValue = value / Math . pow ( 1024 , idx ) ; return `${ formattedValue . toFixed ( 2 ) } ${ units [ idx ] }` ; } }