| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  | import IntValidator from "./IntValidator" | 
					
						
							|  |  |  | import { Validator } from "../Validator" | 
					
						
							| 
									
										
										
										
											2023-03-29 17:21:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class DirectionValidator extends IntValidator { | 
					
						
							|  |  |  |     constructor() { | 
					
						
							|  |  |  |         super( | 
					
						
							|  |  |  |             "direction", | 
					
						
							|  |  |  |             "A geographical direction, in degrees. 0° is north, 90° is east, ... Will return a value between 0 (incl) and 360 (excl)" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-30 04:51:56 +02:00
										 |  |  |     isValid(str): boolean { | 
					
						
							|  |  |  |         if (str.endsWith("°")) { | 
					
						
							|  |  |  |             str = str.substring(0, str.length - 1) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return super.isValid(str) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-29 17:21:20 +02:00
										 |  |  |     reformat(str): string { | 
					
						
							| 
									
										
										
										
											2023-03-30 04:51:56 +02:00
										 |  |  |         if (str.endsWith("°")) { | 
					
						
							|  |  |  |             str = str.substring(0, str.length - 1) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-03-29 17:21:20 +02:00
										 |  |  |         const n = Number(str) % 360 | 
					
						
							|  |  |  |         return "" + n | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |