import { BaseComponent, IValidationProperties, IRule } from './base-component'; enum EStringValidatorType { GreaterThanLength = 'greaterThanLength', LessThanLength = 'lessThanLength', ZA_ID = 'za_id', Email = 'email', IMEI = 'imei', } interface IStringValidationProperties extends IValidationProperties { min?: number; max?: number; } export class TextComponent extends BaseComponent { protected override getValidatorFromRule(rule: IRule): IStringValidationProperties | null { const mapping: Record = { max: EStringValidatorType.LessThanLength, min: EStringValidatorType.GreaterThanLength, idNumber: EStringValidatorType.ZA_ID, email: EStringValidatorType.Email, imei: EStringValidatorType.IMEI, }; const type = mapping[rule.name]; if (!type) { return null; } const argValue = rule.args?.limit ?? rule.arg; return { type, ...(type === EStringValidatorType.LessThanLength ? { max: argValue } : {}), ...(type === EStringValidatorType.GreaterThanLength ? { min: argValue } : {}), }; } }