UNPKG

6.99 kBTypeScriptView Raw
1/// <reference types="node" />
2import { TypedArray } from 'type-fest';
3import { StringPredicate } from './predicates/string';
4import { NumberPredicate } from './predicates/number';
5import { BooleanPredicate } from './predicates/boolean';
6import { Predicate, PredicateOptions } from './predicates/predicate';
7import { ArrayPredicate } from './predicates/array';
8import { ObjectPredicate, Shape } from './predicates/object';
9import { DatePredicate } from './predicates/date';
10import { ErrorPredicate } from './predicates/error';
11import { MapPredicate } from './predicates/map';
12import { WeakMapPredicate } from './predicates/weak-map';
13import { SetPredicate } from './predicates/set';
14import { WeakSetPredicate } from './predicates/weak-set';
15import { TypedArrayPredicate } from './predicates/typed-array';
16import { ArrayBufferPredicate } from './predicates/array-buffer';
17import { DataViewPredicate } from './predicates/data-view';
18import { BasePredicate } from './predicates/base-predicate';
19import { AnyPredicate } from './predicates/any';
20export interface Predicates {
21 /**
22 Test the value to be a string.
23 */
24 readonly string: StringPredicate;
25 /**
26 Test the value to be a number.
27 */
28 readonly number: NumberPredicate;
29 /**
30 Test the value to be a boolean.
31 */
32 readonly boolean: BooleanPredicate;
33 /**
34 Test the value to be undefined.
35 */
36 readonly undefined: Predicate<undefined>;
37 /**
38 Test the value to be null.
39 */
40 readonly null: Predicate<null>;
41 /**
42 Test the value to be null or undefined.
43 */
44 readonly nullOrUndefined: Predicate<null | undefined>;
45 /**
46 Test the value to be not a number.
47 */
48 readonly nan: Predicate<number>;
49 /**
50 Test the value to be a Symbol.
51 */
52 readonly symbol: Predicate<symbol>;
53 /**
54 Test the value to be an array.
55 */
56 readonly array: ArrayPredicate;
57 /**
58 Test the value to be an object.
59 */
60 readonly object: ObjectPredicate;
61 /**
62 Test the value to be a Date.
63 */
64 readonly date: DatePredicate;
65 /**
66 Test the value to be an Error.
67 */
68 readonly error: ErrorPredicate;
69 /**
70 Test the value to be a Map.
71 */
72 readonly map: MapPredicate;
73 /**
74 Test the value to be a WeakMap.
75 */
76 readonly weakMap: WeakMapPredicate;
77 /**
78 Test the value to be a Set.
79 */
80 readonly set: SetPredicate;
81 /**
82 Test the value to be a WeakSet.
83 */
84 readonly weakSet: WeakSetPredicate;
85 /**
86 Test the value to be a Function.
87 */
88 readonly function: Predicate<Function>;
89 /**
90 Test the value to be a Buffer.
91 */
92 readonly buffer: Predicate<Buffer>;
93 /**
94 Test the value to be a RegExp.
95 */
96 readonly regExp: Predicate<RegExp>;
97 /**
98 Test the value to be a Promise.
99 */
100 readonly promise: Predicate<Promise<unknown>>;
101 /**
102 Test the value to be a typed array.
103 */
104 readonly typedArray: TypedArrayPredicate<TypedArray>;
105 /**
106 Test the value to be a Int8Array.
107 */
108 readonly int8Array: TypedArrayPredicate<Int8Array>;
109 /**
110 Test the value to be a Uint8Array.
111 */
112 readonly uint8Array: TypedArrayPredicate<Uint8Array>;
113 /**
114 Test the value to be a Uint8ClampedArray.
115 */
116 readonly uint8ClampedArray: TypedArrayPredicate<Uint8ClampedArray>;
117 /**
118 Test the value to be a Int16Array.
119 */
120 readonly int16Array: TypedArrayPredicate<Int16Array>;
121 /**
122 Test the value to be a Uint16Array.
123 */
124 readonly uint16Array: TypedArrayPredicate<Uint16Array>;
125 /**
126 Test the value to be a Int32Array.
127 */
128 readonly int32Array: TypedArrayPredicate<Int32Array>;
129 /**
130 Test the value to be a Uint32Array.
131 */
132 readonly uint32Array: TypedArrayPredicate<Uint32Array>;
133 /**
134 Test the value to be a Float32Array.
135 */
136 readonly float32Array: TypedArrayPredicate<Float32Array>;
137 /**
138 Test the value to be a Float64Array.
139 */
140 readonly float64Array: TypedArrayPredicate<Float64Array>;
141 /**
142 Test the value to be a ArrayBuffer.
143 */
144 readonly arrayBuffer: ArrayBufferPredicate<ArrayBuffer>;
145 /**
146 Test the value to be a SharedArrayBuffer.
147 */
148 readonly sharedArrayBuffer: ArrayBufferPredicate<SharedArrayBuffer>;
149 /**
150 Test the value to be a DataView.
151 */
152 readonly dataView: DataViewPredicate;
153 /**
154 Test the value to be Iterable.
155 */
156 readonly iterable: Predicate<Iterable<unknown>>;
157 /**
158 Test that the value matches at least one of the given predicates.
159 */
160 any: (<T1>(p1: BasePredicate<T1>) => AnyPredicate<T1>) & (<T1, T2>(p1: BasePredicate<T1>, p2: BasePredicate<T2>) => AnyPredicate<T1 | T2>) & (<T1, T2, T3>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>) => AnyPredicate<T1 | T2 | T3>) & (<T1, T2, T3, T4>(p1: BasePredicate<T1>, p2: BasePredicate<T2>, p3: BasePredicate<T3>, p4: BasePredicate<T4>) => AnyPredicate<T1 | T2 | T3 | T4>) & (<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>) & (<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>) & (<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>) & (<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>) & (<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>) & (<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>) & ((...predicate: BasePredicate[]) => AnyPredicate);
161}
162declare const _default: <T>(object: T, options?: PredicateOptions | undefined) => T & Predicates;
163export default _default;
164export { StringPredicate, NumberPredicate, BooleanPredicate, ArrayPredicate, ObjectPredicate, DatePredicate, ErrorPredicate, MapPredicate, WeakMapPredicate, SetPredicate, WeakSetPredicate, TypedArrayPredicate, ArrayBufferPredicate, DataViewPredicate, AnyPredicate, Shape };