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