UNPKG

3.63 kBTypeScriptView Raw
1import type { Arbitrary } from '../../../check/arbitrary/definition/Arbitrary.js';
2import type { StringConstraints } from '../../string.js';
3import type { DepthSize, SizeForArbitrary } from './MaxLengthFromMinLength.js';
4/**
5 * Constraints for {@link anything} and {@link object}
6 * @public
7 */
8export interface ObjectConstraints {
9 /**
10 * Limit the depth of the object by increasing the probability to generate simple values (defined via values)
11 * as we go deeper in the object.
12 * @remarks Since 2.20.0
13 */
14 depthSize?: DepthSize;
15 /**
16 * Maximal depth allowed
17 * @defaultValue Number.POSITIVE_INFINITY — _defaulting seen as "max non specified" when `defaultSizeToMaxWhenMaxSpecified=true`_
18 * @remarks Since 0.0.7
19 */
20 maxDepth?: number;
21 /**
22 * Maximal number of keys
23 * @defaultValue 0x7fffffff — _defaulting seen as "max non specified" when `defaultSizeToMaxWhenMaxSpecified=true`_
24 * @remarks Since 1.13.0
25 */
26 maxKeys?: number;
27 /**
28 * Define how large the generated values should be (at max)
29 * @remarks Since 2.22.0
30 */
31 size?: SizeForArbitrary;
32 /**
33 * Arbitrary for keys
34 * @defaultValue {@link string}
35 * @remarks Since 0.0.7
36 */
37 key?: Arbitrary<string>;
38 /**
39 * Arbitrary for values
40 * @defaultValue {@link boolean}, {@link integer}, {@link double}, {@link string}, null, undefined, Number.NaN, +0, -0, Number.EPSILON, Number.MIN_VALUE, Number.MAX_VALUE, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY
41 * @remarks Since 0.0.7
42 */
43 values?: Arbitrary<unknown>[];
44 /**
45 * Also generate boxed versions of values
46 * @defaultValue false
47 * @remarks Since 1.11.0
48 */
49 withBoxedValues?: boolean;
50 /**
51 * Also generate Set
52 * @defaultValue false
53 * @remarks Since 1.11.0
54 */
55 withSet?: boolean;
56 /**
57 * Also generate Map
58 * @defaultValue false
59 * @remarks Since 1.11.0
60 */
61 withMap?: boolean;
62 /**
63 * Also generate string representations of object instances
64 * @defaultValue false
65 * @remarks Since 1.17.0
66 */
67 withObjectString?: boolean;
68 /**
69 * Also generate object with null prototype
70 * @defaultValue false
71 * @remarks Since 1.23.0
72 */
73 withNullPrototype?: boolean;
74 /**
75 * Also generate BigInt
76 * @defaultValue false
77 * @remarks Since 1.26.0
78 */
79 withBigInt?: boolean;
80 /**
81 * Also generate Date
82 * @defaultValue false
83 * @remarks Since 2.5.0
84 */
85 withDate?: boolean;
86 /**
87 * Also generate typed arrays in: (Uint|Int)(8|16|32)Array and Float(32|64)Array
88 * Remark: no typed arrays made of bigint
89 * @defaultValue false
90 * @remarks Since 2.9.0
91 */
92 withTypedArray?: boolean;
93 /**
94 * Also generate sparse arrays (arrays with holes)
95 * @defaultValue false
96 * @remarks Since 2.13.0
97 */
98 withSparseArray?: boolean;
99 /**
100 * Replace the arbitrary of strings defaulted for key and values by one able to generate unicode strings with non-ascii characters.
101 * If you override key and/or values constraint, this flag will not apply to your override.
102 * @deprecated Prefer using `stringUnit` to customize the kind of strings that will be generated by default.
103 * @defaultValue false
104 * @remarks Since 3.19.0
105 */
106 withUnicodeString?: boolean;
107 /**
108 * Replace the default unit for strings.
109 * @defaultValue undefined
110 * @remarks Since 3.23.0
111 */
112 stringUnit?: StringConstraints['unit'];
113}