UNPKG

2.7 kBTypeScriptView Raw
1import { BasePredicate } from './base-predicate';
2import { Predicate, PredicateOptions } from './predicate';
3export declare class ArrayPredicate<T = unknown> extends Predicate<T[]> {
4 /**
5 @hidden
6 */
7 constructor(options?: PredicateOptions);
8 /**
9 Test an array to have a specific length.
10
11 @param length - The length of the array.
12 */
13 length(length: number): this;
14 /**
15 Test an array to have a minimum length.
16
17 @param length - The minimum length of the array.
18 */
19 minLength(length: number): this;
20 /**
21 Test an array to have a maximum length.
22
23 @param length - The maximum length of the array.
24 */
25 maxLength(length: number): this;
26 /**
27 Test an array to start with a specific value. The value is tested by identity, not structure.
28
29 @param searchElement - The value that should be the start of the array.
30 */
31 startsWith(searchElement: T): this;
32 /**
33 Test an array to end with a specific value. The value is tested by identity, not structure.
34
35 @param searchElement - The value that should be the end of the array.
36 */
37 endsWith(searchElement: T): this;
38 /**
39 Test an array to include all the provided elements. The values are tested by identity, not structure.
40
41 @param searchElements - The values that should be included in the array.
42 */
43 includes(...searchElements: readonly T[]): this;
44 /**
45 Test an array to include any of the provided elements. The values are tested by identity, not structure.
46
47 @param searchElements - The values that should be included in the array.
48 */
49 includesAny(...searchElements: readonly T[]): this;
50 /**
51 Test an array to be empty.
52 */
53 get empty(): this;
54 /**
55 Test an array to be not empty.
56 */
57 get nonEmpty(): this;
58 /**
59 Test an array to be deeply equal to the provided array.
60
61 @param expected - Expected value to match.
62 */
63 deepEqual(expected: readonly T[]): this;
64 /**
65 Test all elements in the array to match to provided predicate.
66
67 @param predicate - The predicate that should be applied against every individual item.
68
69 @example
70 ```
71 ow(['a', 1], ow.array.ofType(ow.any(ow.string, ow.number)));
72 ```
73 */
74 ofType<U extends T>(predicate: BasePredicate<U>): ArrayPredicate<U>;
75 /**
76 Test if the elements in the array exactly matches the elements placed at the same indices in the predicates array.
77
78 @param predicates - Predicates to test the array against. Describes what the tested array should look like.
79
80 @example
81 ```
82 ow(['1', 2], ow.array.exactShape([ow.string, ow.number]));
83 ```
84 */
85 exactShape(predicates: Predicate[]): this;
86}