| 28 | } |
| 29 | |
| 30 | export const validator: FieldValidationFunctionSync = fieldValidatorArgs => { |
| 31 | if (!fieldValidatorArgs.customArgs) { |
| 32 | throw new Error(BAD_PARAMETER); |
| 33 | } |
| 34 | const { |
| 35 | value, |
| 36 | customArgs = DEFAULT_PARAMS as PatternArgs, |
| 37 | message = defaultMessage, |
| 38 | } = fieldValidatorArgs; |
| 39 | |
| 40 | const pattern = parsePattern(customArgs); |
| 41 | const succeeded = isValidPattern(value, pattern); |
| 42 | |
| 43 | return { |
| 44 | succeeded, |
| 45 | message: succeeded |
| 46 | ? '' |
| 47 | : parseMessageWithCustomArgs(message as string, customArgs), |
| 48 | type: VALIDATOR_TYPE, |
| 49 | }; |
| 50 | }; |
no test coverage detected
searching dependent graphs…