* Given a rule name, detect if there are any additional hints like ! * @param ruleName - string representing a rule name * @returns
( ruleName: string )
| 665 | * @returns |
| 666 | */ |
| 667 | function parseHints( |
| 668 | ruleName: string |
| 669 | ): [string, Partial<FormKitValidationHints>] { |
| 670 | const matches = ruleName.match(hintExtractor) |
| 671 | if (!matches) { |
| 672 | return [ruleName, { name: ruleName }] |
| 673 | } |
| 674 | const map: { [index: string]: Partial<FormKitValidationHints> } = { |
| 675 | '*': { force: true }, |
| 676 | '+': { skipEmpty: false }, |
| 677 | '?': { blocking: false }, |
| 678 | } |
| 679 | const [, hints, rule] = matches |
| 680 | const hintGroups = hasDebounce.test(hints) |
| 681 | ? hints.match(debounceExtractor) || [] |
| 682 | : [, hints] |
| 683 | return [ |
| 684 | rule, |
| 685 | [hintGroups[1], hintGroups[2], hintGroups[3]].reduce( |
| 686 | (hints: Partial<FormKitValidationHints>, group: string | undefined) => { |
| 687 | if (!group) return hints |
| 688 | if (hasDebounce.test(group)) { |
| 689 | hints.debounce = parseInt(group.substr(1, group.length - 1)) |
| 690 | } else { |
| 691 | group |
| 692 | .split('') |
| 693 | .forEach( |
| 694 | (hint) => has(map, hint) && Object.assign(hints, map[hint]) |
| 695 | ) |
| 696 | } |
| 697 | return hints |
| 698 | }, |
| 699 | { name: rule } as Partial<FormKitValidationHints> |
| 700 | ), |
| 701 | ] |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Extracts hint properties from the validation rule function itself and applies |