import { BaseComponent, IValidationProperties, IRule } from './base-component'; enum ENumberValidatorType { GreaterThanNumber = 'greaterThanNumber', LessThanNumber = 'lessThanNumber', } interface INumberValidationProperties extends IValidationProperties { min?: number; max?: number; } export class NumberComponent extends BaseComponent { protected override getValidatorFromRule(rule: IRule): INumberValidationProperties | null { const mapping: Record = { max: ENumberValidatorType.LessThanNumber, min: ENumberValidatorType.GreaterThanNumber, }; const type = mapping[rule.name]; if (!type) { return null; } const argValue = rule.args?.limit ?? rule.arg; return { type, ...(type === ENumberValidatorType.LessThanNumber ? { max: argValue } : {}), ...(type === ENumberValidatorType.GreaterThanNumber ? { min: argValue } : {}), }; } }