mirror of https://github.com/lukechilds/ow.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
443 B
20 lines
443 B
import * as is from '@sindresorhus/is';
|
|
|
|
export type Validator = (value: any) => string | undefined;
|
|
|
|
export interface Context {
|
|
validators: Validator[];
|
|
}
|
|
|
|
export class Predicate {
|
|
constructor(
|
|
type: string,
|
|
public context: Context = { validators: [] }
|
|
) {
|
|
this.context.validators.push(value => {
|
|
if (!is[type](value)) {
|
|
return `Expected argument to be of type \`${type}\` but received type \`${is(value)}\``;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|