import { Pipe , PipeTransform } from '@angular/core' ; import { FormatterService } from '@core/formatter.service' ; @ Pipe ( { name : 'sharedDirection' } ) export class DirectionPipe implements PipeTransform { constructor ( public formatter ) { } param value param empty return { String } transform ( value , empty = this . formatter . empty ) { const fullwind = 22.5 ; const directions = [ 'N' , 'NNE' , 'NE' , 'ENE' , 'E' , 'ESE' , 'SE' , 'SSE' , 'S' , 'SSW' , 'SW' , 'WSW' , 'W' , 'WNW' , 'NW' , 'NNW' , 'N' ] ; if ( typeof value === 'string' && directions . indexOf ( value ) > - 1 ) { return value ; } value = + value ; while ( value < 0 ) { value = value + 360 ; } return directions [ Math . round ( ( value % 360 ) / fullwind ) ] ; } }