UNPKG

2.17 kBTypeScriptView Raw
1import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js';
2import type { SizeForArbitrary } from './_internals/helpers/MaxLengthFromMinLength.js';
3import type { DepthIdentifier } from './_internals/helpers/DepthContext.js';
4/**
5 * Constraints to be applied on {@link array}
6 * @remarks Since 2.4.0
7 * @public
8 */
9export interface ArrayConstraints {
10 /**
11 * Lower bound of the generated array size
12 * @defaultValue 0
13 * @remarks Since 2.4.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.4.0
20 */
21 maxLength?: number;
22 /**
23 * Define how large the generated values should be (at max)
24 *
25 * When used in conjonction with `maxLength`, `size` will be used to define
26 * the upper bound of the generated array size while `maxLength` will be used
27 * to define and document the general maximal length allowed for this case.
28 *
29 * @remarks Since 2.22.0
30 */
31 size?: SizeForArbitrary;
32 /**
33 * When receiving a depth identifier, the arbitrary will impact the depth
34 * attached to it to avoid going too deep if it already generated lots of items.
35 *
36 * In other words, if the number of generated values within the collection is large
37 * then the generated items will tend to be less deep to avoid creating structures a lot
38 * larger than expected.
39 *
40 * For the moment, the depth is not taken into account to compute the number of items to
41 * define for a precise generate call of the array. Just applied onto eligible items.
42 *
43 * @remarks Since 2.25.0
44 */
45 depthIdentifier?: DepthIdentifier | string;
46}
47/**
48 * For arrays of values coming from `arb`
49 *
50 * @param arb - Arbitrary used to generate the values inside the array
51 * @param constraints - Constraints to apply when building instances (since 2.4.0)
52 *
53 * @remarks Since 0.0.1
54 * @public
55 */
56declare function array<T>(arb: Arbitrary<T>, constraints?: ArrayConstraints): Arbitrary<T[]>;
57export { array };