MCPcopy
hub / github.com/sindresorhus/ow / is

Method is

source/predicates/predicate.ts:232–240  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 7

customMethod · 0.95
test.tsFile · 0.80
custom-message.tsFile · 0.80
is-predicate.tsFile · 0.80
types.tsFile · 0.80

Calls 1

addValidatorMethod · 0.95

Tested by

no test coverage detected