Open richardscarrott opened 2 years ago
const minmax = (minValue: number, maxValue: number = minValue) => err(and(min(minValue), max(maxValue)), `Expected number between ${minValue} and ${maxValue}`);
const truthy = create(value => !!value)('Expected truthy value');
const falsy = create(value => !value)('Expected falsy value');
// `like` or `objectLike` or `looseObject` or `objectWith` or `objectContaining`
const like = (validators) => object(validators, { allowUnknown: true });
const trimmed = create(
(value) => typeof value === "string" && value === value.trim()
)("Expected trimmed string");
const any = create(() => true)('Expected any');
Could be useful when using array
and object
, e.g.
// Don't really care what's in the `errors` array or `headers` property, but don't want to loosen the response validator `allowUnknown`.
const gqlResponse = object({
data: object({ id: string }),
errors: or(undef, array(any)),
headers: any
});