import { Pipe } from '@angular/core' ; @ Pipe ( { name : 'abbr' , } ) export class AbbrPipe { numberAbbrev = [ 'k' , 'm' , 'b' , 't' ] ; bytesAbbrev = [ 'K' , 'M' , 'G' , 'T' ] ; transform ( number , decimals = 2 , isBytes = false ) { const abbrev = isBytes ? this . bytesAbbrev : this . numberAbbrev ; decimals = Math . pow ( 10 , decimals ) ; for ( let i = abbrev . length - 1 ; i >= 0 ; i -- ) { const size = Math . pow ( 10 , ( i + 1 ) * 3 ) ; if ( size <= number ) { number = Math . round ( ( number * decimals ) / size ) / decimals ; if ( number === 1000 && i < abbrev . length - 1 ) { number = 1 ; i ++ ; } number += abbrev [ i ] ; break ; } } return number ; } }