1 | import { Predicate } from './predicates/predicate';
|
2 | import { BasePredicate } from './predicates/base-predicate';
|
3 | import { Modifiers } from './modifiers';
|
4 | import { Predicates } from './predicates';
|
5 |
|
6 |
|
7 |
|
8 | export declare type Main = <T>(value: T, label: string | Function, predicate: BasePredicate<T>, idLabel?: boolean) => void;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export declare type Infer<P> = P extends BasePredicate<infer T> ? T : never;
|
24 | export interface Ow extends Modifiers, Predicates {
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | <T>(value: unknown, predicate: BasePredicate<T>): asserts value is T;
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | <T>(value: unknown, label: string, predicate: BasePredicate<T>): asserts value is T;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | isValid: <T>(value: unknown, predicate: BasePredicate<T>) => value is T;
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 | create: (<T>(predicate: BasePredicate<T>) => ReusableValidator<T>) & (<T>(label: string, predicate: BasePredicate<T>) => ReusableValidator<T>);
|
53 | }
|
54 | /**
|
55 | A reusable validator.
|
56 | */
|
57 | export interface ReusableValidator<T> {
|
58 | /**
|
59 | Test if the value matches the predicate. Throws an `ArgumentError` if the test fails.
|
60 |
|
61 | @param value - Value to test.
|
62 | @param label - Override the label which should be used in error messages.
|
63 | */
|
64 | (value: unknown | T, label?: string): void;
|
65 | }
|
66 | /**
|
67 | Turn a `ReusableValidator` into one with a type assertion.
|
68 |
|
69 | @example
|
70 | ```
|
71 | const checkUsername = ow.create(ow.string.minLength(3));
|
72 | const checkUsername_: AssertingValidator<typeof checkUsername> = checkUsername;
|
73 | ```
|
74 |
|
75 | @example
|
76 | ```
|
77 | const predicate = ow.string.minLength(3);
|
78 | const checkUsername: AssertingValidator<typeof predicate> = ow.create(predicate);
|
79 | ```
|
80 | */
|
81 | export declare type AssertingValidator<T> = T extends ReusableValidator<infer R> ? (value: unknown, label?: string) => asserts value is R : T extends BasePredicate<infer R> ? (value: unknown, label?: string) => asserts value is R : never;
|
82 | declare const _ow: Ow;
|
83 | export default _ow;
|
84 | export { BasePredicate, Predicate };
|
85 | export * from './predicates';
|
86 | export { ArgumentError } from './argument-error';
|