UNPKG

2.4 kBTypeScriptView Raw
1import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js';
2import type { DepthIdentifier } from './_internals/helpers/DepthContext.js';
3import type { SizeForArbitrary } from './_internals/helpers/MaxLengthFromMinLength.js';
4/**
5 * Constraints to be applied on {@link sparseArray}
6 * @remarks Since 2.13.0
7 * @public
8 */
9export interface SparseArrayConstraints {
10 /**
11 * Upper bound of the generated array size (maximal size: 4294967295)
12 * @defaultValue 0x7fffffff — _defaulting seen as "max non specified" when `defaultSizeToMaxWhenMaxSpecified=true`_
13 * @remarks Since 2.13.0
14 */
15 maxLength?: number;
16 /**
17 * Lower bound of the number of non-hole elements
18 * @defaultValue 0
19 * @remarks Since 2.13.0
20 */
21 minNumElements?: number;
22 /**
23 * Upper bound of the number of non-hole elements
24 * @defaultValue 0x7fffffff — _defaulting seen as "max non specified" when `defaultSizeToMaxWhenMaxSpecified=true`_
25 * @remarks Since 2.13.0
26 */
27 maxNumElements?: number;
28 /**
29 * When enabled, all generated arrays will either be the empty array or end by a non-hole
30 * @defaultValue false
31 * @remarks Since 2.13.0
32 */
33 noTrailingHole?: boolean;
34 /**
35 * Define how large the generated values should be (at max)
36 * @remarks Since 2.22.0
37 */
38 size?: SizeForArbitrary;
39 /**
40 * When receiving a depth identifier, the arbitrary will impact the depth
41 * attached to it to avoid going too deep if it already generated lots of items.
42 *
43 * In other words, if the number of generated values within the collection is large
44 * then the generated items will tend to be less deep to avoid creating structures a lot
45 * larger than expected.
46 *
47 * For the moment, the depth is not taken into account to compute the number of items to
48 * define for a precise generate call of the array. Just applied onto eligible items.
49 *
50 * @remarks Since 2.25.0
51 */
52 depthIdentifier?: DepthIdentifier | string;
53}
54/**
55 * For sparse arrays of values coming from `arb`
56 * @param arb - Arbitrary used to generate the values inside the sparse array
57 * @param constraints - Constraints to apply when building instances
58 * @remarks Since 2.13.0
59 * @public
60 */
61export declare function sparseArray<T>(arb: Arbitrary<T>, constraints?: SparseArrayConstraints): Arbitrary<T[]>;