UNPKG

8.07 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Predicate } from './lib/predicates/predicate';
3import { AnyPredicate } from './lib/predicates/any';
4import { BasePredicate } from './lib/predicates/base-predicate';
5import { StringPredicate } from './lib/predicates/string';
6import { NumberPredicate } from './lib/predicates/number';
7import { BooleanPredicate } from './lib/predicates/boolean';
8import { ArrayPredicate } from './lib/predicates/array';
9import { ObjectPredicate } from './lib/predicates/object';
10import { DatePredicate } from './lib/predicates/date';
11import { ErrorPredicate } from './lib/predicates/error';
12import { MapPredicate } from './lib/predicates/map';
13import { WeakMapPredicate } from './lib/predicates/weak-map';
14import { SetPredicate } from './lib/predicates/set';
15import { WeakSetPredicate } from './lib/predicates/weak-set';
16declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
17export interface Ow {
18 /**
19 * Test if the value matches the predicate. Throws an `ArgumentError` if the test fails.
20 *
21 * @param value Value to test.
22 * @param predicate Predicate to test against.
23 */
24 <T>(value: T, predicate: BasePredicate<T>): void;
25 /**
26 * Test if `value` matches the provided `predicate`. Throws an `ArgumentError` with the specified `label` if the test fails.
27 *
28 * @param value Value to test.
29 * @param label Label which should be used in error messages.
30 * @param predicate Predicate to test against.
31 */
32 <T>(value: T, label: string, predicate: BasePredicate<T>): void;
33 /**
34 * Test the value to be a string.
35 */
36 readonly string: StringPredicate;
37 /**
38 * Test the value to be a number.
39 */
40 readonly number: NumberPredicate;
41 /**
42 * Test the value to be a boolean.
43 */
44 readonly boolean: BooleanPredicate;
45 /**
46 * Test the value to be undefined.
47 */
48 readonly undefined: Predicate<undefined>;
49 /**
50 * Test the value to be null.
51 */
52 readonly null: Predicate<null>;
53 /**
54 * Test the value to be null or undefined.
55 */
56 readonly nullOrUndefined: Predicate<null | undefined>;
57 /**
58 * Test the value to be not a number.
59 */
60 readonly nan: Predicate<number>;
61 /**
62 * Test the value to be a Symbol.
63 */
64 readonly symbol: Predicate<Symbol>;
65 /**
66 * Test the value to be an array.
67 */
68 readonly array: ArrayPredicate;
69 /**
70 * Test the value to be an object.
71 */
72 readonly object: ObjectPredicate;
73 /**
74 * Test the value to be a Date.
75 */
76 readonly date: DatePredicate;
77 /**
78 * Test the value to be an Error.
79 */
80 readonly error: ErrorPredicate;
81 /**
82 * Test the value to be a Map.
83 */
84 readonly map: MapPredicate;
85 /**
86 * Test the value to be a WeakMap.
87 */
88 readonly weakMap: WeakMapPredicate;
89 /**
90 * Test the value to be a Set.
91 */
92 readonly set: SetPredicate;
93 /**
94 * Test the value to be a WeakSet.
95 */
96 readonly weakSet: WeakSetPredicate;
97 /**
98 * Test the value to be a Function.
99 */
100 readonly function: Predicate<Function>;
101 /**
102 * Test the value to be a Buffer.
103 */
104 readonly buffer: Predicate<Buffer>;
105 /**
106 * Test the value to be a RegExp.
107 */
108 readonly regExp: Predicate<RegExp>;
109 /**
110 * Test the value to be a Promise.
111 */
112 readonly promise: Predicate<Promise<any>>;
113 /**
114 * Test the value to be a typed array.
115 */
116 readonly typedArray: Predicate<TypedArray>;
117 /**
118 * Test the value to be a Int8Array.
119 */
120 readonly int8Array: Predicate<Int8Array>;
121 /**
122 * Test the value to be a Uint8Array.
123 */
124 readonly uint8Array: Predicate<Uint8Array>;
125 /**
126 * Test the value to be a Uint8ClampedArray.
127 */
128 readonly uint8ClampedArray: Predicate<Uint8ClampedArray>;
129 /**
130 * Test the value to be a Int16Array.
131 */
132 readonly int16Array: Predicate<Int16Array>;
133 /**
134 * Test the value to be a Uint16Array.
135 */
136 readonly uint16Array: Predicate<Uint16Array>;
137 /**
138 * Test the value to be a Int32Array.
139 */
140 readonly int32Array: Predicate<Int32Array>;
141 /**
142 * Test the value to be a Uint32Array.
143 */
144 readonly uint32Array: Predicate<Uint32Array>;
145 /**
146 * Test the value to be a Float32Array.
147 */
148 readonly float32Array: Predicate<Float32Array>;
149 /**
150 * Test the value to be a Float64Array.
151 */
152 readonly float64Array: Predicate<Float64Array>;
153 /**
154 * Test the value to be a ArrayBuffer.
155 */
156 readonly arrayBuffer: Predicate<ArrayBuffer>;
157 /**
158 * Test the value to be a DataView.
159 */
160 readonly dataView: Predicate<DataView>;
161 /**
162 * Test the value to be Iterable.
163 */
164 readonly iterable: Predicate<Iterable<any>>;
165 /**
166 * Returns `true` if the value matches the predicate, otherwise returns `false`.
167 *
168 * @param value Value to test.
169 * @param predicate Predicate to test against.
170 */
171 isValid<T>(value: T, predicate: BasePredicate<T>): value is T;
172 /**
173 * Create a reusable validator.
174 *
175 * @param predicate Predicate used in the validator function.
176 */
177 create<T>(predicate: BasePredicate<T>): (value: T) => void;
178 /**
179 * Create a reusable validator.
180 *
181 * @param label Label which should be used in error messages.
182 * @param predicate Predicate used in the validator function.
183 */
184 create<T>(label: string, predicate: BasePredicate<T>): (value: T) => void;
185 /**
186 * Test that the value matches at least one of the given predicates.
187 */
188 any<T1>(p1: BasePredicate<T1>): AnyPredicate<T1>;
189 any<T1, T2>(p1: BasePredicate<T1>, p2: BasePredicate<T2>): AnyPredicate<T1 | T2>;
190 any<T1, T2, T3>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>): AnyPredicate<T1 | T2 | T3>;
191 any<T1, T2, T3, T4>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>): AnyPredicate<T1 | T2 | T3 | T4>;
192 any<T1, T2, T3, T4, T5>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>): AnyPredicate<T1 | T2 | T3 | T4 | T5>;
193 any<T1, T2, T3, T4, T5, T6>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6>;
194 any<T1, T2, T3, T4, T5, T6, T7>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7>;
195 any<T1, T2, T3, T4, T5, T6, T7, T8>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8>;
196 any<T1, T2, T3, T4, T5, T6, T7, T8, T9>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>, p9: BasePredicate<T9>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9>;
197 any<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>, p5: BasePredicate<T5>, p6: BasePredicate<T6>, p7: BasePredicate<T7>, p8: BasePredicate<T8>, p9: BasePredicate<T9>, p10: BasePredicate<T10>): AnyPredicate<T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10>;
198 any(...predicate: BasePredicate[]): AnyPredicate;
199}
200declare const _default: Ow;
201export default _default;
202export { BasePredicate, Predicate, AnyPredicate, StringPredicate, NumberPredicate, BooleanPredicate, ArrayPredicate, ObjectPredicate, DatePredicate, ErrorPredicate, MapPredicate, WeakMapPredicate, SetPredicate, WeakSetPredicate };