@bitbybit-dev/base 1.2.0-rc.2 → 1.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +13 -12
- package/lib/api/inputs/color-inputs.d.ts +97 -48
- package/lib/api/inputs/color-inputs.js +95 -46
- package/lib/api/inputs/dates-inputs.d.ts +67 -26
- package/lib/api/inputs/dates-inputs.js +57 -16
- package/lib/api/inputs/io-inputs.d.ts +13 -15
- package/lib/api/inputs/io-inputs.js +7 -8
- package/lib/api/inputs/line-inputs.d.ts +88 -33
- package/lib/api/inputs/line-inputs.js +61 -11
- package/lib/api/inputs/lists-inputs.d.ts +207 -96
- package/lib/api/inputs/lists-inputs.js +153 -45
- package/lib/api/inputs/logic-inputs.d.ts +52 -22
- package/lib/api/inputs/logic-inputs.js +41 -12
- package/lib/api/inputs/math-inputs.d.ts +113 -52
- package/lib/api/inputs/math-inputs.js +112 -51
- package/lib/api/inputs/mesh-inputs.d.ts +30 -11
- package/lib/api/inputs/mesh-inputs.js +21 -3
- package/lib/api/inputs/point-inputs.d.ts +240 -107
- package/lib/api/inputs/point-inputs.js +199 -73
- package/lib/api/inputs/polyline-inputs.d.ts +68 -28
- package/lib/api/inputs/polyline-inputs.js +48 -13
- package/lib/api/inputs/text-inputs.d.ts +117 -46
- package/lib/api/inputs/text-inputs.js +111 -41
- package/lib/api/inputs/transforms-inputs.d.ts +65 -23
- package/lib/api/inputs/transforms-inputs.js +64 -22
- package/lib/api/inputs/vector-inputs.d.ts +154 -76
- package/lib/api/inputs/vector-inputs.js +132 -57
- package/lib/api/models/point/hex-grid-data.d.ts +1 -1
- package/lib/api/models/point/hex-grid-data.js +1 -1
- package/lib/api/services/color.d.ts +149 -70
- package/lib/api/services/color.js +149 -70
- package/lib/api/services/dates.d.ts +313 -150
- package/lib/api/services/dates.js +313 -150
- package/lib/api/services/line.d.ts +138 -68
- package/lib/api/services/line.js +138 -68
- package/lib/api/services/lists.d.ts +357 -177
- package/lib/api/services/lists.js +357 -177
- package/lib/api/services/logic.d.ts +98 -45
- package/lib/api/services/logic.js +98 -45
- package/lib/api/services/math.d.ts +363 -211
- package/lib/api/services/math.js +363 -211
- package/lib/api/services/mesh.d.ts +73 -31
- package/lib/api/services/mesh.js +73 -31
- package/lib/api/services/point.d.ts +367 -147
- package/lib/api/services/point.js +367 -147
- package/lib/api/services/polyline.d.ts +146 -71
- package/lib/api/services/polyline.js +146 -71
- package/lib/api/services/text.d.ts +320 -165
- package/lib/api/services/text.js +320 -165
- package/lib/api/services/transforms.d.ts +145 -58
- package/lib/api/services/transforms.js +145 -58
- package/lib/api/services/vector.d.ts +381 -156
- package/lib/api/services/vector.js +381 -156
- package/package.json +1 -1
|
@@ -1,110 +1,163 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Booleans and decisions: comparing values, flipping booleans, turning lists of numbers into lists
|
|
4
|
+
* of booleans by thresholds, drawing random booleans, and gating a value so it passes only when a
|
|
5
|
+
* condition holds. The threshold methods are the usual way to decide which items of a pattern get a
|
|
6
|
+
* feature and which do not.
|
|
4
7
|
*/
|
|
5
8
|
export declare class Logic {
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
10
|
+
* Passes a boolean through unchanged, so a value can be given a name and reused.
|
|
11
|
+
*
|
|
12
|
+
* Example: true -> true
|
|
13
|
+
* @param inputs - The boolean
|
|
14
|
+
* @returns The same boolean
|
|
11
15
|
* @group create
|
|
12
16
|
* @shortname boolean
|
|
13
17
|
* @drawable false
|
|
14
18
|
*/
|
|
15
19
|
boolean(inputs: Inputs.Logic.BooleanDto): boolean;
|
|
16
20
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
+
* Draws a list of random booleans, each true with a given probability.
|
|
22
|
+
*
|
|
23
|
+
* Example: length 5 with trueThreshold 0.7 -> perhaps [true, true, false, true, true]
|
|
24
|
+
* @param inputs - How many booleans to draw and the probability of true
|
|
25
|
+
* @returns The random booleans
|
|
21
26
|
* @group create
|
|
22
27
|
* @shortname random booleans
|
|
23
28
|
* @drawable false
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const flags = bitbybit.logic.randomBooleans({ length: 5, trueThreshold: 0.7 });
|
|
32
|
+
* ```
|
|
24
33
|
*/
|
|
25
34
|
randomBooleans(inputs: Inputs.Logic.RandomBooleansDto): boolean[];
|
|
26
35
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* Turns numbers into booleans with a random blend between two thresholds.
|
|
37
|
+
*
|
|
38
|
+
* Below the first threshold a number is always true, above the second always false; in between,
|
|
39
|
+
* the chance of true falls in steps from one to the other, so a pattern fades out instead of
|
|
40
|
+
* switching sharply.
|
|
41
|
+
* Example: [0.1, 0.9] with thresholds 0.3 and 0.7 -> [true, false]
|
|
42
|
+
* @param inputs - The numbers, the two thresholds and how many steps the fade has
|
|
43
|
+
* @returns One boolean per number
|
|
33
44
|
* @group create
|
|
34
45
|
* @shortname 2 threshold random gradient
|
|
35
46
|
* @drawable false
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const fade = bitbybit.logic.twoThresholdRandomGradient({
|
|
50
|
+
* numbers: [0.1, 0.4, 0.6, 0.9],
|
|
51
|
+
* thresholdTotalTrue: 0.3,
|
|
52
|
+
* thresholdTotalFalse: 0.7,
|
|
53
|
+
* nrLevels: 10,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
36
56
|
*/
|
|
37
57
|
twoThresholdRandomGradient(inputs: Inputs.Logic.TwoThresholdRandomGradientDto): boolean[];
|
|
38
58
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
59
|
+
* Turns numbers into booleans: true below the threshold, false at or above it.
|
|
60
|
+
*
|
|
61
|
+
* `inverse` flips every result.
|
|
62
|
+
* Example: [0.3, 0.7, 0.5] with threshold 0.6 -> [true, false, true]
|
|
63
|
+
* @param inputs - The numbers, the threshold and whether to flip the result
|
|
64
|
+
* @returns One boolean per number
|
|
44
65
|
* @group create
|
|
45
66
|
* @shortname threshold boolean list
|
|
46
67
|
* @drawable false
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const below = bitbybit.logic.thresholdBooleanList({ numbers: [0.3, 0.7, 0.5], threshold: 0.6, inverse: false });
|
|
71
|
+
* ```
|
|
47
72
|
*/
|
|
48
73
|
thresholdBooleanList(inputs: Inputs.Logic.ThresholdBooleanListDto): boolean[];
|
|
49
74
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
75
|
+
* Turns numbers into booleans: true when the number falls inside any of the given ranges, false
|
|
76
|
+
* otherwise.
|
|
77
|
+
*
|
|
78
|
+
* Each range is `[min, max]` with both ends included; `inverse` flips every result.
|
|
79
|
+
* Example: [0.2, 0.5, 0.8] with ranges [[0.3, 0.6], [0.7, 0.9]] -> [false, true, true]
|
|
80
|
+
* @param inputs - The numbers, the ranges and whether to flip the result
|
|
81
|
+
* @returns One boolean per number
|
|
55
82
|
* @group create
|
|
56
83
|
* @shortname threshold gaps boolean list
|
|
57
84
|
* @drawable false
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const inside = bitbybit.logic.thresholdGapsBooleanList({
|
|
88
|
+
* numbers: [0.2, 0.5, 0.8],
|
|
89
|
+
* gapThresholds: [[0.3, 0.6], [0.7, 0.9]],
|
|
90
|
+
* inverse: false,
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
58
93
|
*/
|
|
59
94
|
thresholdGapsBooleanList(inputs: Inputs.Logic.ThresholdGapsBooleanListDto): boolean[];
|
|
60
95
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
96
|
+
* Flips a boolean: true becomes false and false becomes true.
|
|
97
|
+
*
|
|
98
|
+
* Example: true -> false
|
|
99
|
+
* @param inputs - The boolean
|
|
100
|
+
* @returns The opposite boolean
|
|
65
101
|
* @group edit
|
|
66
102
|
* @shortname not
|
|
67
103
|
* @drawable false
|
|
68
104
|
*/
|
|
69
105
|
not(inputs: Inputs.Logic.BooleanDto): boolean;
|
|
70
106
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @
|
|
107
|
+
* Flips every boolean in a list.
|
|
108
|
+
*
|
|
109
|
+
* Example: [true, false, true] -> [false, true, false]
|
|
110
|
+
* @param inputs - The booleans
|
|
111
|
+
* @returns The flipped booleans, in the same order
|
|
75
112
|
* @group edit
|
|
76
113
|
* @shortname not list
|
|
77
114
|
* @drawable false
|
|
78
115
|
*/
|
|
79
116
|
notList(inputs: Inputs.Logic.BooleanListDto): boolean[];
|
|
80
117
|
/**
|
|
81
|
-
* Compares two values
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
118
|
+
* Compares two values with an operator: less, less or equal, greater, greater or equal, equal
|
|
119
|
+
* or not equal, in the loose (`==`) or strict (`===`) form.
|
|
120
|
+
*
|
|
121
|
+
* Example: 5 greater than 3 -> true; 'hello' strictly equal to 'world' -> false
|
|
122
|
+
* @param inputs - The two values and the operator
|
|
123
|
+
* @returns The result of the comparison
|
|
85
124
|
* @group operations
|
|
86
125
|
* @shortname compare
|
|
87
126
|
* @drawable false
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const bigger = bitbybit.logic.compare({ first: 5, second: 3, operator: Bit.Inputs.Logic.BooleanOperatorsEnum.greater });
|
|
130
|
+
* ```
|
|
88
131
|
*/
|
|
89
132
|
compare<T>(inputs: Inputs.Logic.ComparisonDto<T>): boolean;
|
|
90
133
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @
|
|
134
|
+
* Lets a value through when the boolean is true and gives undefined when it is false.
|
|
135
|
+
*
|
|
136
|
+
* Example: 42 with true -> 42; 42 with false -> undefined
|
|
137
|
+
* @param inputs - The value and the boolean that opens the gate
|
|
138
|
+
* @returns The value, or undefined when the gate is closed
|
|
95
139
|
* @group operations
|
|
96
140
|
* @shortname value gate
|
|
97
141
|
* @drawable false
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const maybe = bitbybit.logic.valueGate({ value: 42, boolean: true });
|
|
145
|
+
* ```
|
|
98
146
|
*/
|
|
99
147
|
valueGate<T>(inputs: Inputs.Logic.ValueGateDto<T>): T | undefined;
|
|
100
148
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @
|
|
149
|
+
* Picks the first of two values that is defined, so the second acts as a fallback.
|
|
150
|
+
*
|
|
151
|
+
* Example: 42 and 10 -> 42; undefined and 10 -> 10
|
|
152
|
+
* @param inputs - The preferred value and the fallback
|
|
153
|
+
* @returns The first defined value, or undefined when both are missing
|
|
105
154
|
* @group operations
|
|
106
155
|
* @shortname first defined value gate
|
|
107
156
|
* @drawable false
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const chosen = bitbybit.logic.firstDefinedValueGate({ value1: undefined, value2: 10 });
|
|
160
|
+
* ```
|
|
108
161
|
*/
|
|
109
162
|
firstDefinedValueGate<T, U>(inputs: Inputs.Logic.TwoValueGateDto<T, U>): T | U | undefined;
|
|
110
163
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Booleans and decisions: comparing values, flipping booleans, turning lists of numbers into lists
|
|
3
|
+
* of booleans by thresholds, drawing random booleans, and gating a value so it passes only when a
|
|
4
|
+
* condition holds. The threshold methods are the usual way to decide which items of a pattern get a
|
|
5
|
+
* feature and which do not.
|
|
3
6
|
*/
|
|
4
7
|
export class Logic {
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
9
|
+
* Passes a boolean through unchanged, so a value can be given a name and reused.
|
|
10
|
+
*
|
|
11
|
+
* Example: true -> true
|
|
12
|
+
* @param inputs - The boolean
|
|
13
|
+
* @returns The same boolean
|
|
10
14
|
* @group create
|
|
11
15
|
* @shortname boolean
|
|
12
16
|
* @drawable false
|
|
@@ -15,13 +19,18 @@ export class Logic {
|
|
|
15
19
|
return inputs.boolean;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
+
* Draws a list of random booleans, each true with a given probability.
|
|
23
|
+
*
|
|
24
|
+
* Example: length 5 with trueThreshold 0.7 -> perhaps [true, true, false, true, true]
|
|
25
|
+
* @param inputs - How many booleans to draw and the probability of true
|
|
26
|
+
* @returns The random booleans
|
|
22
27
|
* @group create
|
|
23
28
|
* @shortname random booleans
|
|
24
29
|
* @drawable false
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const flags = bitbybit.logic.randomBooleans({ length: 5, trueThreshold: 0.7 });
|
|
33
|
+
* ```
|
|
25
34
|
*/
|
|
26
35
|
randomBooleans(inputs) {
|
|
27
36
|
const booleans = [];
|
|
@@ -31,15 +40,26 @@ export class Logic {
|
|
|
31
40
|
return booleans;
|
|
32
41
|
}
|
|
33
42
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
43
|
+
* Turns numbers into booleans with a random blend between two thresholds.
|
|
44
|
+
*
|
|
45
|
+
* Below the first threshold a number is always true, above the second always false; in between,
|
|
46
|
+
* the chance of true falls in steps from one to the other, so a pattern fades out instead of
|
|
47
|
+
* switching sharply.
|
|
48
|
+
* Example: [0.1, 0.9] with thresholds 0.3 and 0.7 -> [true, false]
|
|
49
|
+
* @param inputs - The numbers, the two thresholds and how many steps the fade has
|
|
50
|
+
* @returns One boolean per number
|
|
40
51
|
* @group create
|
|
41
52
|
* @shortname 2 threshold random gradient
|
|
42
53
|
* @drawable false
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const fade = bitbybit.logic.twoThresholdRandomGradient({
|
|
57
|
+
* numbers: [0.1, 0.4, 0.6, 0.9],
|
|
58
|
+
* thresholdTotalTrue: 0.3,
|
|
59
|
+
* thresholdTotalFalse: 0.7,
|
|
60
|
+
* nrLevels: 10,
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
43
63
|
*/
|
|
44
64
|
twoThresholdRandomGradient(inputs) {
|
|
45
65
|
const booleans = [];
|
|
@@ -67,14 +87,19 @@ export class Logic {
|
|
|
67
87
|
return booleans;
|
|
68
88
|
}
|
|
69
89
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* @
|
|
90
|
+
* Turns numbers into booleans: true below the threshold, false at or above it.
|
|
91
|
+
*
|
|
92
|
+
* `inverse` flips every result.
|
|
93
|
+
* Example: [0.3, 0.7, 0.5] with threshold 0.6 -> [true, false, true]
|
|
94
|
+
* @param inputs - The numbers, the threshold and whether to flip the result
|
|
95
|
+
* @returns One boolean per number
|
|
75
96
|
* @group create
|
|
76
97
|
* @shortname threshold boolean list
|
|
77
98
|
* @drawable false
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const below = bitbybit.logic.thresholdBooleanList({ numbers: [0.3, 0.7, 0.5], threshold: 0.6, inverse: false });
|
|
102
|
+
* ```
|
|
78
103
|
*/
|
|
79
104
|
thresholdBooleanList(inputs) {
|
|
80
105
|
const booleans = [];
|
|
@@ -92,14 +117,24 @@ export class Logic {
|
|
|
92
117
|
return booleans;
|
|
93
118
|
}
|
|
94
119
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
120
|
+
* Turns numbers into booleans: true when the number falls inside any of the given ranges, false
|
|
121
|
+
* otherwise.
|
|
122
|
+
*
|
|
123
|
+
* Each range is `[min, max]` with both ends included; `inverse` flips every result.
|
|
124
|
+
* Example: [0.2, 0.5, 0.8] with ranges [[0.3, 0.6], [0.7, 0.9]] -> [false, true, true]
|
|
125
|
+
* @param inputs - The numbers, the ranges and whether to flip the result
|
|
126
|
+
* @returns One boolean per number
|
|
100
127
|
* @group create
|
|
101
128
|
* @shortname threshold gaps boolean list
|
|
102
129
|
* @drawable false
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const inside = bitbybit.logic.thresholdGapsBooleanList({
|
|
133
|
+
* numbers: [0.2, 0.5, 0.8],
|
|
134
|
+
* gapThresholds: [[0.3, 0.6], [0.7, 0.9]],
|
|
135
|
+
* inverse: false,
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
103
138
|
*/
|
|
104
139
|
thresholdGapsBooleanList(inputs) {
|
|
105
140
|
const booleans = [];
|
|
@@ -123,10 +158,11 @@ export class Logic {
|
|
|
123
158
|
return booleans;
|
|
124
159
|
}
|
|
125
160
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @
|
|
161
|
+
* Flips a boolean: true becomes false and false becomes true.
|
|
162
|
+
*
|
|
163
|
+
* Example: true -> false
|
|
164
|
+
* @param inputs - The boolean
|
|
165
|
+
* @returns The opposite boolean
|
|
130
166
|
* @group edit
|
|
131
167
|
* @shortname not
|
|
132
168
|
* @drawable false
|
|
@@ -135,10 +171,11 @@ export class Logic {
|
|
|
135
171
|
return !inputs.boolean;
|
|
136
172
|
}
|
|
137
173
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
174
|
+
* Flips every boolean in a list.
|
|
175
|
+
*
|
|
176
|
+
* Example: [true, false, true] -> [false, true, false]
|
|
177
|
+
* @param inputs - The booleans
|
|
178
|
+
* @returns The flipped booleans, in the same order
|
|
142
179
|
* @group edit
|
|
143
180
|
* @shortname not list
|
|
144
181
|
* @drawable false
|
|
@@ -147,13 +184,19 @@ export class Logic {
|
|
|
147
184
|
return inputs.booleans.map(b => !b);
|
|
148
185
|
}
|
|
149
186
|
/**
|
|
150
|
-
* Compares two values
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
187
|
+
* Compares two values with an operator: less, less or equal, greater, greater or equal, equal
|
|
188
|
+
* or not equal, in the loose (`==`) or strict (`===`) form.
|
|
189
|
+
*
|
|
190
|
+
* Example: 5 greater than 3 -> true; 'hello' strictly equal to 'world' -> false
|
|
191
|
+
* @param inputs - The two values and the operator
|
|
192
|
+
* @returns The result of the comparison
|
|
154
193
|
* @group operations
|
|
155
194
|
* @shortname compare
|
|
156
195
|
* @drawable false
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const bigger = bitbybit.logic.compare({ first: 5, second: 3, operator: Bit.Inputs.Logic.BooleanOperatorsEnum.greater });
|
|
199
|
+
* ```
|
|
157
200
|
*/
|
|
158
201
|
compare(inputs) {
|
|
159
202
|
switch (inputs.operator) {
|
|
@@ -178,25 +221,35 @@ export class Logic {
|
|
|
178
221
|
}
|
|
179
222
|
}
|
|
180
223
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* @
|
|
224
|
+
* Lets a value through when the boolean is true and gives undefined when it is false.
|
|
225
|
+
*
|
|
226
|
+
* Example: 42 with true -> 42; 42 with false -> undefined
|
|
227
|
+
* @param inputs - The value and the boolean that opens the gate
|
|
228
|
+
* @returns The value, or undefined when the gate is closed
|
|
185
229
|
* @group operations
|
|
186
230
|
* @shortname value gate
|
|
187
231
|
* @drawable false
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* const maybe = bitbybit.logic.valueGate({ value: 42, boolean: true });
|
|
235
|
+
* ```
|
|
188
236
|
*/
|
|
189
237
|
valueGate(inputs) {
|
|
190
238
|
return inputs.boolean ? inputs.value : undefined;
|
|
191
239
|
}
|
|
192
240
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @
|
|
241
|
+
* Picks the first of two values that is defined, so the second acts as a fallback.
|
|
242
|
+
*
|
|
243
|
+
* Example: 42 and 10 -> 42; undefined and 10 -> 10
|
|
244
|
+
* @param inputs - The preferred value and the fallback
|
|
245
|
+
* @returns The first defined value, or undefined when both are missing
|
|
197
246
|
* @group operations
|
|
198
247
|
* @shortname first defined value gate
|
|
199
248
|
* @drawable false
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const chosen = bitbybit.logic.firstDefinedValueGate({ value1: undefined, value2: 10 });
|
|
252
|
+
* ```
|
|
200
253
|
*/
|
|
201
254
|
firstDefinedValueGate(inputs) {
|
|
202
255
|
let res;
|