import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'fileSize' } ) export class FileSizePipe implements PipeTransform { transform ( size ) { if ( isNaN ( size ) ) { size = 0 ; } if ( size < 1024 ) { return size + ' Bytes' ; } size /= 1024 ; if ( size < 1024 ) { return size . toFixed ( 2 ) + ' Kb' ; } size /= 1024 ; if ( size < 1024 ) { return size . toFixed ( 2 ) + ' Mb' ; } size /= 1024 ; if ( size < 1024 ) { return size . toFixed ( 2 ) + ' Gb' ; } } }