UNPKG

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