UNPKG

2.04 kBTypeScriptView Raw
1import { Predicate } from './predicates/predicate';
2import { BasePredicate } from './predicates/base-predicate';
3import { Modifiers } from './modifiers';
4import { Predicates } from './predicates';
5/**
6@hidden
7*/
8export declare type Main = <T>(value: T, label: string | Function, predicate: BasePredicate<T>, idLabel?: boolean) => void;
9export interface Ow extends Modifiers, Predicates {
10 /**
11 Test if the value matches the predicate. Throws an `ArgumentError` if the test fails.
12
13 @param value - Value to test.
14 @param predicate - Predicate to test against.
15 */
16 <T>(value: unknown, predicate: BasePredicate<T>): asserts value is T;
17 /**
18 Test if `value` matches the provided `predicate`. Throws an `ArgumentError` with the specified `label` if the test fails.
19
20 @param value - Value to test.
21 @param label - Label which should be used in error messages.
22 @param predicate - Predicate to test against.
23 */
24 <T>(value: unknown, label: string, predicate: BasePredicate<T>): asserts value is T;
25 /**
26 Returns `true` if the value matches the predicate, otherwise returns `false`.
27
28 @param value - Value to test.
29 @param predicate - Predicate to test against.
30 */
31 isValid: <T>(value: T, predicate: BasePredicate<T>) => value is T;
32 /**
33 Create a reusable validator.
34
35 @param predicate - Predicate used in the validator function.
36 */
37 create: (<T>(predicate: BasePredicate<T>) => ReusableValidator<T>) & (<T>(label: string, predicate: BasePredicate<T>) => ReusableValidator<T>);
38}
39/**
40A reusable validator.
41*/
42export interface ReusableValidator<T> {
43 /**
44 Test if the value matches the predicate. Throws an `ArgumentError` if the test fails.
45
46 @param value - Value to test.
47 @param label - Override the label which should be used in error messages.
48 */
49 (value: T, label?: string): void;
50}
51declare const _ow: Ow;
52export default _ow;
53export { BasePredicate, Predicate };
54export * from './predicates';
55export { ArgumentError } from './argument-error';
56
\No newline at end of file