import { Pipe , PipeTransform } from '@angular/core' ; import { FormatterService } from '@core/formatter.service' ; import { DegreesPipe } from './degrees.pipe' ; @ Pipe ( { name : 'sharedUnits' } ) export class UnitsPipe implements PipeTransform { constructor ( public formatterService ) { } param value param units return { String | null } transform ( value , units , decimals = null ) { let output = null ; if ( value === null ) { return null ; } switch ( units ) { case 'count' : { output = value . toString ( ) ; break ; } case 'degrees' : { const degPipe = new DegreesPipe ( this . formatterService ) ; output = degPipe . transform ( value , decimals ) ; break ; } case 'latitude' : { output = this . formatterService . latitude ( + value ) ; break ; } case 'longitude' : { output = this . formatterService . longitude ( + value ) ; break ; } case 'intensity' : { output = `${ value } mmi` ; break ; } default : { output = `${ value } ${ units }` ; } } return output ; } }