| 13 | const NUMERIC_RULES = new Set(["min", "max", "minLength", "maxLength"]); |
| 14 | |
| 15 | export function parseRule(rule: string): ParsedRule { |
| 16 | const colonIdx = rule.indexOf(":"); |
| 17 | if (colonIdx === -1) return { type: rule }; |
| 18 | |
| 19 | const type = rule.slice(0, colonIdx); |
| 20 | const rawArg = rule.slice(colonIdx + 1); |
| 21 | const arg = NUMERIC_RULES.has(type) && !Number.isNaN(Number(rawArg)) ? Number(rawArg) : rawArg; |
| 22 | return { type, arg }; |
| 23 | } |
| 24 | |
| 25 | export function parseRules(rules: unknown): ParsedRule[] { |
| 26 | if (!Array.isArray(rules)) return []; |