| 
									
										
										
										
											2023-03-29 17:21:20 +02:00
										 |  |  | import { Translation } from "../../i18n/Translation" | 
					
						
							|  |  |  | import Translations from "../../i18n/Translations" | 
					
						
							| 
									
										
										
										
											2023-03-29 17:56:42 +02:00
										 |  |  | import { Validator } from "../Validator" | 
					
						
							| 
									
										
										
										
											2023-03-29 17:21:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class IntValidator extends Validator { | 
					
						
							|  |  |  |     constructor(name?: string, explanation?: string) { | 
					
						
							|  |  |  |         super( | 
					
						
							|  |  |  |             name ?? "int", | 
					
						
							|  |  |  |             explanation ?? "A whole number, either positive, negative or zero", | 
					
						
							|  |  |  |             "numeric" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     isValid(str): boolean { | 
					
						
							|  |  |  |         str = "" + str | 
					
						
							|  |  |  |         return str !== undefined && str.indexOf(".") < 0 && !isNaN(Number(str)) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     getFeedback(s: string): Translation { | 
					
						
							|  |  |  |         const n = Number(s) | 
					
						
							|  |  |  |         if (isNaN(n)) { | 
					
						
							|  |  |  |             return Translations.t.validation.nat.notANumber | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (Math.floor(n) !== n) { | 
					
						
							|  |  |  |             return Translations.t.validation.nat.mustBeWhole | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return undefined | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |