1 | import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js';
|
2 | import type { SizeForArbitrary } from './_internals/helpers/MaxLengthFromMinLength.js';
|
3 | import type { DepthIdentifier } from './_internals/helpers/DepthContext.js';
|
4 | /**
|
5 | * Shared constraints to be applied on {@link uniqueArray}
|
6 | * @remarks Since 2.23.0
|
7 | * @public
|
8 | */
|
9 | export type UniqueArraySharedConstraints = {
|
10 | /**
|
11 | * Lower bound of the generated array size
|
12 | * @defaultValue 0
|
13 | * @remarks Since 2.23.0
|
14 | */
|
15 | minLength?: number;
|
16 | /**
|
17 | * Upper bound of the generated array size
|
18 | * @defaultValue 0x7fffffff — _defaulting seen as "max non specified" when `defaultSizeToMaxWhenMaxSpecified=true`_
|
19 | * @remarks Since 2.23.0
|
20 | */
|
21 | maxLength?: number;
|
22 | /**
|
23 | * Define how large the generated values should be (at max)
|
24 | * @remarks Since 2.23.0
|
25 | */
|
26 | size?: SizeForArbitrary;
|
27 | /**
|
28 | * When receiving a depth identifier, the arbitrary will impact the depth
|
29 | * attached to it to avoid going too deep if it already generated lots of items.
|
30 | *
|
31 | * In other words, if the number of generated values within the collection is large
|
32 | * then the generated items will tend to be less deep to avoid creating structures a lot
|
33 | * larger than expected.
|
34 | *
|
35 | * For the moment, the depth is not taken into account to compute the number of items to
|
36 | * define for a precise generate call of the array. Just applied onto eligible items.
|
37 | *
|
38 | * @remarks Since 2.25.0
|
39 | */
|
40 | depthIdentifier?: DepthIdentifier | string;
|
41 | };
|
42 | /**
|
43 | * Constraints implying known and optimized comparison function
|
44 | * to be applied on {@link uniqueArray}
|
45 | *
|
46 | * @remarks Since 2.23.0
|
47 | * @public
|
48 | */
|
49 | export type UniqueArrayConstraintsRecommended<T, U> = UniqueArraySharedConstraints & {
|
50 | /**
|
51 | * The operator to be used to compare the values after having applied the selector (if any):
|
52 | * - SameValue behaves like `Object.is` — {@link https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevalue}
|
53 | * - SameValueZero behaves like `Set` or `Map` — {@link https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero}
|
54 | * - IsStrictlyEqual behaves like `===` — {@link https://tc39.es/ecma262/multipage/abstract-operations.html#sec-isstrictlyequal}
|
55 | * - Fully custom comparison function: it implies performance costs for large arrays
|
56 | *
|
57 | * @defaultValue 'SameValue'
|
58 | * @remarks Since 2.23.0
|
59 | */
|
60 | comparator?: 'SameValue' | 'SameValueZero' | 'IsStrictlyEqual';
|
61 | /**
|
62 | * How we should project the values before comparing them together
|
63 | * @defaultValue (v => v)
|
64 | * @remarks Since 2.23.0
|
65 | */
|
66 | selector?: (v: T) => U;
|
67 | };
|
68 | /**
|
69 | * Constraints implying a fully custom comparison function
|
70 | * to be applied on {@link uniqueArray}
|
71 | *
|
72 | * WARNING - Imply an extra performance cost whenever you want to generate large arrays
|
73 | *
|
74 | * @remarks Since 2.23.0
|
75 | * @public
|
76 | */
|
77 | export type UniqueArrayConstraintsCustomCompare<T> = UniqueArraySharedConstraints & {
|
78 | /**
|
79 | * The operator to be used to compare the values after having applied the selector (if any)
|
80 | * @remarks Since 2.23.0
|
81 | */
|
82 | comparator: (a: T, b: T) => boolean;
|
83 | /**
|
84 | * How we should project the values before comparing them together
|
85 | * @remarks Since 2.23.0
|
86 | */
|
87 | selector?: undefined;
|
88 | };
|
89 | /**
|
90 | * Constraints implying fully custom comparison function and selector
|
91 | * to be applied on {@link uniqueArray}
|
92 | *
|
93 | * WARNING - Imply an extra performance cost whenever you want to generate large arrays
|
94 | *
|
95 | * @remarks Since 2.23.0
|
96 | * @public
|
97 | */
|
98 | export type UniqueArrayConstraintsCustomCompareSelect<T, U> = UniqueArraySharedConstraints & {
|
99 | /**
|
100 | * The operator to be used to compare the values after having applied the selector (if any)
|
101 | * @remarks Since 2.23.0
|
102 | */
|
103 | comparator: (a: U, b: U) => boolean;
|
104 | /**
|
105 | * How we should project the values before comparing them together
|
106 | * @remarks Since 2.23.0
|
107 | */
|
108 | selector: (v: T) => U;
|
109 | };
|
110 | /**
|
111 | * Constraints implying known and optimized comparison function
|
112 | * to be applied on {@link uniqueArray}
|
113 | *
|
114 | * The defaults relies on the defaults specified by {@link UniqueArrayConstraintsRecommended}
|
115 | *
|
116 | * @remarks Since 2.23.0
|
117 | * @public
|
118 | */
|
119 | export type UniqueArrayConstraints<T, U> = UniqueArrayConstraintsRecommended<T, U> | UniqueArrayConstraintsCustomCompare<T> | UniqueArrayConstraintsCustomCompareSelect<T, U>;
|
120 | /**
|
121 | * For arrays of unique values coming from `arb`
|
122 | *
|
123 | * @param arb - Arbitrary used to generate the values inside the array
|
124 | * @param constraints - Constraints to apply when building instances
|
125 | *
|
126 | * @remarks Since 2.23.0
|
127 | * @public
|
128 | */
|
129 | export declare function uniqueArray<T, U>(arb: Arbitrary<T>, constraints?: UniqueArrayConstraintsRecommended<T, U>): Arbitrary<T[]>;
|
130 | /**
|
131 | * For arrays of unique values coming from `arb`
|
132 | *
|
133 | * @param arb - Arbitrary used to generate the values inside the array
|
134 | * @param constraints - Constraints to apply when building instances
|
135 | *
|
136 | * @remarks Since 2.23.0
|
137 | * @public
|
138 | */
|
139 | export declare function uniqueArray<T>(arb: Arbitrary<T>, constraints: UniqueArrayConstraintsCustomCompare<T>): Arbitrary<T[]>;
|
140 | /**
|
141 | * For arrays of unique values coming from `arb`
|
142 | *
|
143 | * @param arb - Arbitrary used to generate the values inside the array
|
144 | * @param constraints - Constraints to apply when building instances
|
145 | *
|
146 | * @remarks Since 2.23.0
|
147 | * @public
|
148 | */
|
149 | export declare function uniqueArray<T, U>(arb: Arbitrary<T>, constraints: UniqueArrayConstraintsCustomCompareSelect<T, U>): Arbitrary<T[]>;
|
150 | /**
|
151 | * For arrays of unique values coming from `arb`
|
152 | *
|
153 | * @param arb - Arbitrary used to generate the values inside the array
|
154 | * @param constraints - Constraints to apply when building instances
|
155 | *
|
156 | * @remarks Since 2.23.0
|
157 | * @public
|
158 | */
|
159 | export declare function uniqueArray<T, U>(arb: Arbitrary<T>, constraints: UniqueArrayConstraints<T, U>): Arbitrary<T[]>;
|