Test if the value matches a custom validation function. The validation function should return `true` if the value passes the function. If the function either returns `false` or a string, the function fails and the string will be used as error message. @param validator - Validation function.
(validator: (value: T) => boolean | string)
| 230 | @param validator - Validation function. |
| 231 | */ |
| 232 | is(validator: (value: T) => boolean | string): this { |
| 233 | return this.addValidator({ |
| 234 | message: (value, label, error) => (error |
| 235 | ? `(${label}) ${String(error)}` |
| 236 | : `Expected ${label} \`${String(value)}\` to pass custom validation function` |
| 237 | ), |
| 238 | validator, |
| 239 | }); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | Use a custom validation function that throws an error when the validation fails. This is useful for reusing existing validators or composing complex validations. |
no test coverage detected