( validation: undefined | string | FormKitValidationIntent[], rules: FormKitValidationRules, node: FormKitNode )
| 587 | * @internal |
| 588 | */ |
| 589 | export function parseRules( |
| 590 | validation: undefined | string | FormKitValidationIntent[], |
| 591 | rules: FormKitValidationRules, |
| 592 | node: FormKitNode |
| 593 | ): FormKitValidation[] { |
| 594 | if (!validation) return [] |
| 595 | const intents = |
| 596 | typeof validation === 'string' |
| 597 | ? extractRules(validation) |
| 598 | : clone(validation) |
| 599 | return intents.reduce((validations, args) => { |
| 600 | let rule = args.shift() as string | FormKitValidationRule |
| 601 | const hints = {} |
| 602 | if (typeof rule === 'string') { |
| 603 | const [ruleName, parsedHints] = parseHints(rule) |
| 604 | if (has(rules, ruleName)) { |
| 605 | rule = rules[ruleName] |
| 606 | Object.assign(hints, parsedHints) |
| 607 | } |
| 608 | } |
| 609 | if (typeof rule === 'function') { |
| 610 | validations.push({ |
| 611 | observer: createObserver(node), |
| 612 | rule, |
| 613 | args, |
| 614 | timer: 0, |
| 615 | state: null, |
| 616 | queued: true, |
| 617 | deps: new Map(), |
| 618 | ...defaultHints, |
| 619 | ...fnHints(hints, rule), |
| 620 | }) |
| 621 | } |
| 622 | return validations |
| 623 | }, [] as FormKitValidation[]) |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * A string of validation rules written in FormKitRule notation. |
no test coverage detected