1 | import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary.js';
|
2 | import type { DepthIdentifier } from './_internals/helpers/DepthContext.js';
|
3 | import type { DepthSize } from './_internals/helpers/MaxLengthFromMinLength.js';
|
4 | /**
|
5 | * Constraints to be applied on {@link option}
|
6 | * @remarks Since 2.2.0
|
7 | * @public
|
8 | */
|
9 | export interface OptionConstraints<TNil = null> {
|
10 | /**
|
11 | * The probability to build a nil value is of `1 / freq`
|
12 | * @defaultValue 5
|
13 | * @remarks Since 1.17.0
|
14 | */
|
15 | freq?: number;
|
16 | /**
|
17 | * The nil value
|
18 | * @defaultValue null
|
19 | * @remarks Since 1.17.0
|
20 | */
|
21 | nil?: TNil;
|
22 | /**
|
23 | * While going deeper and deeper within a recursive structure (see {@link letrec}),
|
24 | * this factor will be used to increase the probability to generate nil.
|
25 | *
|
26 | * @remarks Since 2.14.0
|
27 | */
|
28 | depthSize?: DepthSize;
|
29 | /**
|
30 | * Maximal authorized depth. Once this depth has been reached only nil will be used.
|
31 | * @defaultValue Number.POSITIVE_INFINITY — _defaulting seen as "max non specified" when `defaultSizeToMaxWhenMaxSpecified=true`_
|
32 | * @remarks Since 2.14.0
|
33 | */
|
34 | maxDepth?: number;
|
35 | /**
|
36 | * Depth identifier can be used to share the current depth between several instances.
|
37 | *
|
38 | * By default, if not specified, each instance of option will have its own depth.
|
39 | * In other words: you can have depth=1 in one while you have depth=100 in another one.
|
40 | *
|
41 | * @remarks Since 2.14.0
|
42 | */
|
43 | depthIdentifier?: DepthIdentifier | string;
|
44 | }
|
45 | /**
|
46 | * For either nil or a value coming from `arb` with custom frequency
|
47 | *
|
48 | * @param arb - Arbitrary that will be called to generate a non nil value
|
49 | * @param constraints - Constraints on the option(since 1.17.0)
|
50 | *
|
51 | * @remarks Since 0.0.6
|
52 | * @public
|
53 | */
|
54 | export declare function option<T, TNil = null>(arb: Arbitrary<T>, constraints?: OptionConstraints<TNil>): Arbitrary<T | TNil>;
|