import { Pipe , PipeTransform } from '@angular/core' ; /**
 * Digits pipe
 */ @ Pipe ( { name : 'digits' } ) export class DigitsPipe implements PipeTransform { transform ( digits , precision = 1 ) { if ( digits === 0 ) { return '0' ; } if ( ! isFinite ( digits ) ) { return '-' ; } const units = [ '' , 'K' , 'M' , 'B' , 'T' ] ; const value = Math . floor ( Math . log ( digits ) / Math . log ( 1000 ) ) ; if ( value === 0 ) { precision = 0 ; } return ( ( digits / Math . pow ( 1000 , Math . floor ( value ) ) ) . toFixed ( precision ) + ' ' + units [ value ] ) . trim ( ) ; } }