@bitbybit-dev/base 0.20.13 → 0.20.14
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/lists-inputs.d.ts +39 -0
- package/lib/api/inputs/lists-inputs.js +43 -0
- package/lib/api/inputs/math-inputs.d.ts +154 -0
- package/lib/api/inputs/math-inputs.js +217 -0
- package/lib/api/inputs/text-inputs.d.ts +139 -0
- package/lib/api/inputs/text-inputs.js +215 -0
- package/lib/api/inputs/vector-inputs.d.ts +8 -0
- package/lib/api/inputs/vector-inputs.js +8 -0
- package/lib/api/services/color.d.ts +27 -12
- package/lib/api/services/color.js +27 -12
- package/lib/api/services/dates.d.ts +62 -30
- package/lib/api/services/dates.js +62 -30
- package/lib/api/services/geometry-helper.d.ts +50 -0
- package/lib/api/services/geometry-helper.js +50 -2
- package/lib/api/services/helpers/dxf/dxf.d.ts +19 -9
- package/lib/api/services/helpers/dxf/dxf.js +19 -9
- package/lib/api/services/line.d.ts +34 -16
- package/lib/api/services/line.js +34 -16
- package/lib/api/services/lists.d.ts +175 -32
- package/lib/api/services/lists.js +275 -32
- package/lib/api/services/logic.d.ts +24 -13
- package/lib/api/services/logic.js +24 -13
- package/lib/api/services/math.d.ts +180 -35
- package/lib/api/services/math.js +215 -35
- package/lib/api/services/mesh.d.ts +17 -6
- package/lib/api/services/mesh.js +17 -6
- package/lib/api/services/point.d.ts +63 -32
- package/lib/api/services/point.js +63 -32
- package/lib/api/services/polyline.d.ts +27 -11
- package/lib/api/services/polyline.js +27 -11
- package/lib/api/services/text.d.ts +286 -7
- package/lib/api/services/text.js +350 -7
- package/lib/api/services/transforms.d.ts +30 -16
- package/lib/api/services/transforms.js +30 -16
- package/lib/api/services/vector.d.ts +85 -38
- package/lib/api/services/vector.js +87 -38
- package/package.json +1 -1
|
@@ -7,7 +7,8 @@ import * as Inputs from "../inputs";
|
|
|
7
7
|
*/
|
|
8
8
|
export class Lists {
|
|
9
9
|
/**
|
|
10
|
-
* Gets an item from the list
|
|
10
|
+
* Gets an item from the list at a specific position using zero-based indexing.
|
|
11
|
+
* Example: From [10, 20, 30, 40], getting index 2 returns 30
|
|
11
12
|
* @param inputs a list and an index
|
|
12
13
|
* @returns item
|
|
13
14
|
* @group get
|
|
@@ -28,7 +29,52 @@ export class Lists {
|
|
|
28
29
|
return result;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
|
-
* Gets
|
|
32
|
+
* Gets the first item from the list.
|
|
33
|
+
* Example: From [10, 20, 30, 40], returns 10
|
|
34
|
+
* @param inputs a list
|
|
35
|
+
* @returns first item
|
|
36
|
+
* @group get
|
|
37
|
+
* @shortname first item
|
|
38
|
+
* @drawable false
|
|
39
|
+
*/
|
|
40
|
+
getFirstItem(inputs) {
|
|
41
|
+
if (inputs.list.length === 0) {
|
|
42
|
+
throw new Error("List is empty");
|
|
43
|
+
}
|
|
44
|
+
let result;
|
|
45
|
+
if (inputs.clone) {
|
|
46
|
+
result = structuredClone(inputs.list[0]);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
result = inputs.list[0];
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the last item from the list.
|
|
55
|
+
* Example: From [10, 20, 30, 40], returns 40
|
|
56
|
+
* @param inputs a list
|
|
57
|
+
* @returns last item
|
|
58
|
+
* @group get
|
|
59
|
+
* @shortname last item
|
|
60
|
+
* @drawable false
|
|
61
|
+
*/
|
|
62
|
+
getLastItem(inputs) {
|
|
63
|
+
if (inputs.list.length === 0) {
|
|
64
|
+
throw new Error("List is empty");
|
|
65
|
+
}
|
|
66
|
+
let result;
|
|
67
|
+
if (inputs.clone) {
|
|
68
|
+
result = structuredClone(inputs.list[inputs.list.length - 1]);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
result = inputs.list[inputs.list.length - 1];
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Randomly keeps items from the list based on a probability threshold (0 to 1).
|
|
77
|
+
* Example: From [1, 2, 3, 4, 5] with threshold 0.5, might return [1, 3, 5] (50% chance for each item)
|
|
32
78
|
* @param inputs a list and a threshold for randomization of items to remove
|
|
33
79
|
* @returns list with remaining items
|
|
34
80
|
* @group get
|
|
@@ -49,7 +95,8 @@ export class Lists {
|
|
|
49
95
|
return newList;
|
|
50
96
|
}
|
|
51
97
|
/**
|
|
52
|
-
*
|
|
98
|
+
* Extracts a portion of the list between start and end positions (end is exclusive).
|
|
99
|
+
* Example: From [10, 20, 30, 40, 50] with start=1 and end=4, returns [20, 30, 40]
|
|
53
100
|
* @param inputs a list and start and end indexes
|
|
54
101
|
* @returns sub list
|
|
55
102
|
* @group get
|
|
@@ -67,7 +114,9 @@ export class Lists {
|
|
|
67
114
|
return result;
|
|
68
115
|
}
|
|
69
116
|
/**
|
|
70
|
-
* Gets nth item
|
|
117
|
+
* Gets every nth item from the list, starting from an optional offset position.
|
|
118
|
+
* Example: From [0, 1, 2, 3, 4, 5, 6, 7, 8] with nth=3 and offset=0, returns [0, 3, 6]
|
|
119
|
+
* Example: From [0, 1, 2, 3, 4, 5, 6, 7, 8] with nth=2 and offset=1, returns [1, 3, 5, 7]
|
|
71
120
|
* @param inputs a list and index
|
|
72
121
|
* @returns list with filtered items
|
|
73
122
|
* @group get
|
|
@@ -88,7 +137,8 @@ export class Lists {
|
|
|
88
137
|
return result;
|
|
89
138
|
}
|
|
90
139
|
/**
|
|
91
|
-
*
|
|
140
|
+
* Filters items from the list using a repeating true/false pattern.
|
|
141
|
+
* Example: From [0, 1, 2, 3, 4, 5] with pattern [true, true, false], returns [0, 1, 3, 4] (keeps items where pattern is true)
|
|
92
142
|
* @param inputs a list and index
|
|
93
143
|
* @returns list with filtered items
|
|
94
144
|
* @group get
|
|
@@ -125,7 +175,8 @@ export class Lists {
|
|
|
125
175
|
return result;
|
|
126
176
|
}
|
|
127
177
|
/**
|
|
128
|
-
*
|
|
178
|
+
* Merges elements from multiple lists at a specific nesting level, grouping elements by position.
|
|
179
|
+
* Example: From [[0, 1, 2], [3, 4, 5]] at level 0, returns [[0, 3], [1, 4], [2, 5]]
|
|
129
180
|
* @param inputs lists, level and flatten data
|
|
130
181
|
* @returns list with merged lists and flattened lists
|
|
131
182
|
* @group get
|
|
@@ -175,7 +226,8 @@ export class Lists {
|
|
|
175
226
|
return final;
|
|
176
227
|
}
|
|
177
228
|
/**
|
|
178
|
-
*
|
|
229
|
+
* Finds the length of the longest list among multiple lists.
|
|
230
|
+
* Example: From [[1, 2], [3, 4, 5, 6], [7]], returns 4 (length of [3, 4, 5, 6])
|
|
179
231
|
* @param inputs a list of lists
|
|
180
232
|
* @returns number of max length
|
|
181
233
|
* @group get
|
|
@@ -197,7 +249,8 @@ export class Lists {
|
|
|
197
249
|
}
|
|
198
250
|
}
|
|
199
251
|
/**
|
|
200
|
-
*
|
|
252
|
+
* Reverses the order of items in the list.
|
|
253
|
+
* Example: From [1, 2, 3, 4, 5], returns [5, 4, 3, 2, 1]
|
|
201
254
|
* @param inputs a list and an index
|
|
202
255
|
* @returns item
|
|
203
256
|
* @group edit
|
|
@@ -212,7 +265,28 @@ export class Lists {
|
|
|
212
265
|
return res.reverse();
|
|
213
266
|
}
|
|
214
267
|
/**
|
|
215
|
-
*
|
|
268
|
+
* Randomly rearranges all items in the list (using Fisher-Yates algorithm).
|
|
269
|
+
* Example: From [1, 2, 3, 4, 5], might return [3, 1, 5, 2, 4] (order varies each time)
|
|
270
|
+
* @param inputs a list
|
|
271
|
+
* @returns shuffled list
|
|
272
|
+
* @group edit
|
|
273
|
+
* @shortname shuffle
|
|
274
|
+
* @drawable false
|
|
275
|
+
*/
|
|
276
|
+
shuffle(inputs) {
|
|
277
|
+
let res = inputs.list;
|
|
278
|
+
if (inputs.clone) {
|
|
279
|
+
res = structuredClone(inputs.list);
|
|
280
|
+
}
|
|
281
|
+
for (let i = res.length - 1; i > 0; i--) {
|
|
282
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
283
|
+
[res[i], res[j]] = [res[j], res[i]];
|
|
284
|
+
}
|
|
285
|
+
return res;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Transposes a 2D list by swapping rows and columns (all sublists must be equal length).
|
|
289
|
+
* Example: From [[0, 1, 2], [3, 4, 5]], returns [[0, 3], [1, 4], [2, 5]]
|
|
216
290
|
* @param inputs a list of lists to flip
|
|
217
291
|
* @returns item
|
|
218
292
|
* @group edit
|
|
@@ -248,7 +322,9 @@ export class Lists {
|
|
|
248
322
|
}
|
|
249
323
|
}
|
|
250
324
|
/**
|
|
251
|
-
*
|
|
325
|
+
* Splits the list into smaller lists of n elements each.
|
|
326
|
+
* Example: From [0, 1, 2, 3, 4, 5, 6, 7, 8] with n=3, returns [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
|
|
327
|
+
* Example: From [0, 1, 2, 3, 4] with n=2 and keepRemainder=true, returns [[0, 1], [2, 3], [4]]
|
|
252
328
|
* @param inputs a list
|
|
253
329
|
* @returns items grouped in lists of n elements
|
|
254
330
|
* @group edit
|
|
@@ -276,7 +352,32 @@ export class Lists {
|
|
|
276
352
|
return groupElements(inputs);
|
|
277
353
|
}
|
|
278
354
|
/**
|
|
279
|
-
*
|
|
355
|
+
* Checks whether the list contains a specific item.
|
|
356
|
+
* Example: List [10, 20, 30, 40] with item 30 returns true, with item 50 returns false
|
|
357
|
+
* @param inputs a list and an item
|
|
358
|
+
* @returns true if item is in list
|
|
359
|
+
* @group get
|
|
360
|
+
* @shortname contains item
|
|
361
|
+
* @drawable false
|
|
362
|
+
*/
|
|
363
|
+
includes(inputs) {
|
|
364
|
+
return inputs.list.includes(inputs.item);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Finds the position (index) of the first occurrence of an item in the list.
|
|
368
|
+
* Example: In [10, 20, 30, 20, 40], finding 20 returns 1 (first occurrence), finding 50 returns -1 (not found)
|
|
369
|
+
* @param inputs a list and an item
|
|
370
|
+
* @returns index of the item or -1 if not found
|
|
371
|
+
* @group get
|
|
372
|
+
* @shortname find index
|
|
373
|
+
* @drawable false
|
|
374
|
+
*/
|
|
375
|
+
findIndex(inputs) {
|
|
376
|
+
return inputs.list.indexOf(inputs.item);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Determines the maximum nesting level (depth) of a list structure.
|
|
380
|
+
* Example: [1, 2, 3] has depth 1, [[1, 2], [3, 4]] has depth 2, [[[1]]] has depth 3
|
|
280
381
|
* @param inputs a list
|
|
281
382
|
* @returns number of depth
|
|
282
383
|
* @group get
|
|
@@ -306,7 +407,8 @@ export class Lists {
|
|
|
306
407
|
return levels;
|
|
307
408
|
}
|
|
308
409
|
/**
|
|
309
|
-
*
|
|
410
|
+
* Returns the number of items in the list.
|
|
411
|
+
* Example: [10, 20, 30, 40, 50] returns 5, [] returns 0
|
|
310
412
|
* @param inputs a length list
|
|
311
413
|
* @returns a number
|
|
312
414
|
* @group get
|
|
@@ -317,7 +419,8 @@ export class Lists {
|
|
|
317
419
|
return inputs.list.length;
|
|
318
420
|
}
|
|
319
421
|
/**
|
|
320
|
-
*
|
|
422
|
+
* Inserts an item at a specific position in the list.
|
|
423
|
+
* Example: In [10, 20, 30, 40], adding 99 at index 2 gives [10, 20, 99, 30, 40]
|
|
321
424
|
* @param inputs a list, item and an index
|
|
322
425
|
* @returns list with added item
|
|
323
426
|
* @group add
|
|
@@ -335,7 +438,8 @@ export class Lists {
|
|
|
335
438
|
return res;
|
|
336
439
|
}
|
|
337
440
|
/**
|
|
338
|
-
*
|
|
441
|
+
* Inserts the same item at multiple specified positions in the list.
|
|
442
|
+
* Example: In [10, 20, 30], adding 99 at indexes [0, 2] gives [99, 10, 20, 99, 30]
|
|
339
443
|
* @param inputs a list, item and an indexes
|
|
340
444
|
* @returns list with added item
|
|
341
445
|
* @group add
|
|
@@ -358,7 +462,8 @@ export class Lists {
|
|
|
358
462
|
return cloned;
|
|
359
463
|
}
|
|
360
464
|
/**
|
|
361
|
-
*
|
|
465
|
+
* Inserts multiple items at corresponding positions (first item at first index, second item at second index, etc.).
|
|
466
|
+
* Example: In [10, 20, 30], adding items [88, 99] at indexes [1, 2] gives [10, 88, 20, 99, 30]
|
|
362
467
|
* @param inputs a list, items and an indexes
|
|
363
468
|
* @returns list with added items
|
|
364
469
|
* @group add
|
|
@@ -390,7 +495,8 @@ export class Lists {
|
|
|
390
495
|
return cloned;
|
|
391
496
|
}
|
|
392
497
|
/**
|
|
393
|
-
*
|
|
498
|
+
* Removes the item at a specific position in the list.
|
|
499
|
+
* Example: From [10, 20, 30, 40, 50], removing index 2 gives [10, 20, 40, 50]
|
|
394
500
|
* @param inputs a list and index
|
|
395
501
|
* @returns list with removed item
|
|
396
502
|
* @group remove
|
|
@@ -408,7 +514,66 @@ export class Lists {
|
|
|
408
514
|
return res;
|
|
409
515
|
}
|
|
410
516
|
/**
|
|
411
|
-
*
|
|
517
|
+
* Removes the first item from the list.
|
|
518
|
+
* Example: From [10, 20, 30, 40], returns [20, 30, 40]
|
|
519
|
+
* @param inputs a list
|
|
520
|
+
* @returns list with first item removed
|
|
521
|
+
* @group remove
|
|
522
|
+
* @shortname remove first item
|
|
523
|
+
* @drawable false
|
|
524
|
+
*/
|
|
525
|
+
removeFirstItem(inputs) {
|
|
526
|
+
let res = inputs.list;
|
|
527
|
+
if (inputs.clone) {
|
|
528
|
+
res = structuredClone(inputs.list);
|
|
529
|
+
}
|
|
530
|
+
if (res.length > 0) {
|
|
531
|
+
res.shift();
|
|
532
|
+
}
|
|
533
|
+
return res;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Removes the last item from the list.
|
|
537
|
+
* Example: From [10, 20, 30, 40], returns [10, 20, 30]
|
|
538
|
+
* @param inputs a list
|
|
539
|
+
* @returns list with last item removed
|
|
540
|
+
* @group remove
|
|
541
|
+
* @shortname remove last item
|
|
542
|
+
* @drawable false
|
|
543
|
+
*/
|
|
544
|
+
removeLastItem(inputs) {
|
|
545
|
+
let res = inputs.list;
|
|
546
|
+
if (inputs.clone) {
|
|
547
|
+
res = structuredClone(inputs.list);
|
|
548
|
+
}
|
|
549
|
+
if (res.length > 0) {
|
|
550
|
+
res.pop();
|
|
551
|
+
}
|
|
552
|
+
return res;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Removes an item counting from the end of the list (index 0 = last item, 1 = second-to-last, etc.).
|
|
556
|
+
* Example: From [10, 20, 30, 40, 50], removing index 1 from end gives [10, 20, 30, 50] (removes 40)
|
|
557
|
+
* @param inputs a list and index from end
|
|
558
|
+
* @returns list with removed item
|
|
559
|
+
* @group remove
|
|
560
|
+
* @shortname remove item from end
|
|
561
|
+
* @drawable false
|
|
562
|
+
*/
|
|
563
|
+
removeItemAtIndexFromEnd(inputs) {
|
|
564
|
+
let res = inputs.list;
|
|
565
|
+
if (inputs.clone) {
|
|
566
|
+
res = structuredClone(inputs.list);
|
|
567
|
+
}
|
|
568
|
+
if (inputs.index >= 0 && inputs.index < res.length) {
|
|
569
|
+
const actualIndex = res.length - 1 - inputs.index;
|
|
570
|
+
res.splice(actualIndex, 1);
|
|
571
|
+
}
|
|
572
|
+
return res;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Removes items at multiple specified positions from the list.
|
|
576
|
+
* Example: From [10, 20, 30, 40, 50], removing indexes [1, 3] gives [10, 30, 50]
|
|
412
577
|
* @param inputs a list and indexes
|
|
413
578
|
* @returns list with removed items
|
|
414
579
|
* @group remove
|
|
@@ -430,7 +595,8 @@ export class Lists {
|
|
|
430
595
|
return res;
|
|
431
596
|
}
|
|
432
597
|
/**
|
|
433
|
-
*
|
|
598
|
+
* Clears all items from the list, resulting in an empty list.
|
|
599
|
+
* Example: From [10, 20, 30, 40], returns []
|
|
434
600
|
* @param inputs a list
|
|
435
601
|
* @returns The length is set to 0 and same array memory object is returned
|
|
436
602
|
* @group remove
|
|
@@ -442,7 +608,8 @@ export class Lists {
|
|
|
442
608
|
return inputs.list;
|
|
443
609
|
}
|
|
444
610
|
/**
|
|
445
|
-
*
|
|
611
|
+
* Removes every nth item from the list, starting from an optional offset position.
|
|
612
|
+
* Example: From [0, 1, 2, 3, 4, 5, 6, 7, 8] with nth=3 and offset=0, returns [1, 2, 4, 5, 7, 8] (removes 0, 3, 6)
|
|
446
613
|
* @param inputs a list and index
|
|
447
614
|
* @returns list with removed item
|
|
448
615
|
* @group remove
|
|
@@ -463,7 +630,8 @@ export class Lists {
|
|
|
463
630
|
return result;
|
|
464
631
|
}
|
|
465
632
|
/**
|
|
466
|
-
*
|
|
633
|
+
* Randomly removes items from the list based on a probability threshold (0 to 1).
|
|
634
|
+
* Example: From [1, 2, 3, 4, 5] with threshold 0.5, might return [2, 4] (50% chance to remove each item)
|
|
467
635
|
* @param inputs a list and a threshold for randomization of items to remove
|
|
468
636
|
* @returns list with removed items
|
|
469
637
|
* @group remove
|
|
@@ -484,11 +652,12 @@ export class Lists {
|
|
|
484
652
|
return newList;
|
|
485
653
|
}
|
|
486
654
|
/**
|
|
487
|
-
*
|
|
655
|
+
* Removes duplicate numbers from the list, keeping only the first occurrence of each value.
|
|
656
|
+
* Example: From [1, 2, 3, 2, 4, 3, 5], returns [1, 2, 3, 4, 5]
|
|
488
657
|
* @param inputs a list of numbers
|
|
489
658
|
* @returns list with unique numbers
|
|
490
659
|
* @group remove
|
|
491
|
-
* @shortname remove
|
|
660
|
+
* @shortname remove duplicate numbers
|
|
492
661
|
* @drawable false
|
|
493
662
|
*/
|
|
494
663
|
removeDuplicateNumbers(inputs) {
|
|
@@ -499,7 +668,8 @@ export class Lists {
|
|
|
499
668
|
return res.filter((value, index, self) => self.indexOf(value) === index);
|
|
500
669
|
}
|
|
501
670
|
/**
|
|
502
|
-
*
|
|
671
|
+
* Removes duplicate numbers that are within a specified tolerance range of each other.
|
|
672
|
+
* Example: From [1.0, 1.001, 2.0, 2.002, 3.0] with tolerance 0.01, returns [1.0, 2.0, 3.0]
|
|
503
673
|
* @param inputs a list of numbers and the tolerance
|
|
504
674
|
* @returns list with unique numbers
|
|
505
675
|
* @group remove
|
|
@@ -514,7 +684,24 @@ export class Lists {
|
|
|
514
684
|
return res.filter((value, index, self) => self.findIndex(s => Math.abs(s - value) < inputs.tolerance) === index);
|
|
515
685
|
}
|
|
516
686
|
/**
|
|
517
|
-
*
|
|
687
|
+
* Removes duplicate items from the list using strict equality comparison (works with any type).
|
|
688
|
+
* Example: From ['a', 'b', 'c', 'a', 'd', 'b'], returns ['a', 'b', 'c', 'd']
|
|
689
|
+
* @param inputs a list
|
|
690
|
+
* @returns list with unique items
|
|
691
|
+
* @group remove
|
|
692
|
+
* @shortname remove duplicates
|
|
693
|
+
* @drawable false
|
|
694
|
+
*/
|
|
695
|
+
removeDuplicates(inputs) {
|
|
696
|
+
let res = inputs.list;
|
|
697
|
+
if (inputs.clone) {
|
|
698
|
+
res = structuredClone(inputs.list);
|
|
699
|
+
}
|
|
700
|
+
return res.filter((value, index, self) => self.indexOf(value) === index);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Appends an item to the end of the list.
|
|
704
|
+
* Example: To [10, 20, 30], adding 40 gives [10, 20, 30, 40]
|
|
518
705
|
* @param inputs a list and an item
|
|
519
706
|
* @returns list with added item
|
|
520
707
|
* @group add
|
|
@@ -530,7 +717,8 @@ export class Lists {
|
|
|
530
717
|
return res;
|
|
531
718
|
}
|
|
532
719
|
/**
|
|
533
|
-
*
|
|
720
|
+
* Adds an item to the beginning of the list.
|
|
721
|
+
* Example: To [10, 20, 30], prepending 5 gives [5, 10, 20, 30]
|
|
534
722
|
* @param inputs a list and an item
|
|
535
723
|
* @returns list with added item
|
|
536
724
|
* @group add
|
|
@@ -546,7 +734,8 @@ export class Lists {
|
|
|
546
734
|
return res;
|
|
547
735
|
}
|
|
548
736
|
/**
|
|
549
|
-
*
|
|
737
|
+
* Adds an item either at the beginning or end of the list based on the position parameter.
|
|
738
|
+
* Example: To [10, 20, 30], adding 5 at 'first' gives [5, 10, 20, 30], at 'last' gives [10, 20, 30, 5]
|
|
550
739
|
* @param inputs a list, item and an option for first or last position
|
|
551
740
|
* @returns list with added item
|
|
552
741
|
* @group add
|
|
@@ -567,7 +756,31 @@ export class Lists {
|
|
|
567
756
|
return res;
|
|
568
757
|
}
|
|
569
758
|
/**
|
|
570
|
-
*
|
|
759
|
+
* Combines multiple lists into a single list by joining them end-to-end.
|
|
760
|
+
* Example: From [[1, 2], [3, 4], [5, 6]], returns [1, 2, 3, 4, 5, 6]
|
|
761
|
+
* @param inputs lists to concatenate
|
|
762
|
+
* @returns concatenated list
|
|
763
|
+
* @group add
|
|
764
|
+
* @shortname concatenate lists
|
|
765
|
+
* @drawable false
|
|
766
|
+
*/
|
|
767
|
+
concatenate(inputs) {
|
|
768
|
+
let result = [];
|
|
769
|
+
if (inputs.clone) {
|
|
770
|
+
inputs.lists.forEach(list => {
|
|
771
|
+
result = result.concat(structuredClone(list));
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
inputs.lists.forEach(list => {
|
|
776
|
+
result = result.concat(list);
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
return result;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Creates a new empty list with no items.
|
|
783
|
+
* Example: Returns []
|
|
571
784
|
* @returns an empty array list
|
|
572
785
|
* @group create
|
|
573
786
|
* @shortname empty list
|
|
@@ -577,7 +790,8 @@ export class Lists {
|
|
|
577
790
|
return [];
|
|
578
791
|
}
|
|
579
792
|
/**
|
|
580
|
-
*
|
|
793
|
+
* Creates a new list by repeating an item a specified number of times.
|
|
794
|
+
* Example: Repeating 5 three times returns [5, 5, 5]
|
|
581
795
|
* @param inputs an item to multiply
|
|
582
796
|
* @returns list
|
|
583
797
|
* @group create
|
|
@@ -592,7 +806,8 @@ export class Lists {
|
|
|
592
806
|
return result;
|
|
593
807
|
}
|
|
594
808
|
/**
|
|
595
|
-
*
|
|
809
|
+
* Repeats a pattern of items cyclically until reaching a target list length.
|
|
810
|
+
* Example: Pattern [1, 2, 3] with length 7 returns [1, 2, 3, 1, 2, 3, 1]
|
|
596
811
|
* @param inputs a list to multiply and a length limit
|
|
597
812
|
* @returns list
|
|
598
813
|
* @group create
|
|
@@ -619,7 +834,8 @@ export class Lists {
|
|
|
619
834
|
return res;
|
|
620
835
|
}
|
|
621
836
|
/**
|
|
622
|
-
*
|
|
837
|
+
* Sorts numbers in ascending (lowest to highest) or descending (highest to lowest) order.
|
|
838
|
+
* Example: [5, 2, 8, 1, 9] ascending returns [1, 2, 5, 8, 9], descending returns [9, 8, 5, 2, 1]
|
|
623
839
|
* @param inputs a list of numbers to sort and an option for ascending or descending order
|
|
624
840
|
* @returns list
|
|
625
841
|
* @group sorting
|
|
@@ -639,7 +855,8 @@ export class Lists {
|
|
|
639
855
|
}
|
|
640
856
|
}
|
|
641
857
|
/**
|
|
642
|
-
*
|
|
858
|
+
* Sorts text strings alphabetically in ascending (A to Z) or descending (Z to A) order.
|
|
859
|
+
* Example: ['dog', 'apple', 'cat', 'banana'] ascending returns ['apple', 'banana', 'cat', 'dog']
|
|
643
860
|
* @param inputs a list of texts to sort and an option for ascending or descending order
|
|
644
861
|
* @returns list
|
|
645
862
|
* @group sorting
|
|
@@ -659,7 +876,8 @@ export class Lists {
|
|
|
659
876
|
}
|
|
660
877
|
}
|
|
661
878
|
/**
|
|
662
|
-
*
|
|
879
|
+
* Sorts objects by comparing numeric values of a specified property.
|
|
880
|
+
* Example: [{age: 30}, {age: 20}, {age: 25}] sorted by 'age' ascending returns [{age: 20}, {age: 25}, {age: 30}]
|
|
663
881
|
* @param inputs a list to sort, a property to sort by and an option for ascending or descending order
|
|
664
882
|
* @returns list
|
|
665
883
|
* @group sorting
|
|
@@ -678,4 +896,29 @@ export class Lists {
|
|
|
678
896
|
return res.sort((a, b) => b[inputs.property] - a[inputs.property]);
|
|
679
897
|
}
|
|
680
898
|
}
|
|
899
|
+
/**
|
|
900
|
+
* Combines multiple lists by alternating elements from each list (first from list1, first from list2, second from list1, etc.).
|
|
901
|
+
* Example: From [[0, 1, 2], [3, 4, 5]], returns [0, 3, 1, 4, 2, 5]
|
|
902
|
+
* @param inputs Lists to interleave
|
|
903
|
+
* @returns Flattened interleaved list
|
|
904
|
+
* @group transform
|
|
905
|
+
* @shortname interleave lists
|
|
906
|
+
* @drawable false
|
|
907
|
+
*/
|
|
908
|
+
interleave(inputs) {
|
|
909
|
+
const lists = inputs.clone ? structuredClone(inputs.lists) : inputs.lists;
|
|
910
|
+
if (!lists || lists.length === 0) {
|
|
911
|
+
throw new Error("Lists array is empty or does not exist");
|
|
912
|
+
}
|
|
913
|
+
const result = [];
|
|
914
|
+
const maxLength = Math.max(...lists.map(list => list.length));
|
|
915
|
+
for (let i = 0; i < maxLength; i++) {
|
|
916
|
+
for (const list of lists) {
|
|
917
|
+
if (i < list.length) {
|
|
918
|
+
result.push(list[i]);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return result;
|
|
923
|
+
}
|
|
681
924
|
}
|
|
@@ -4,7 +4,8 @@ import * as Inputs from "../inputs";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class Logic {
|
|
6
6
|
/**
|
|
7
|
-
* Creates a boolean value -
|
|
7
|
+
* Creates and returns a boolean value (pass-through for boolean input).
|
|
8
|
+
* Example: true → true, false → false
|
|
8
9
|
* @param inputs a true or false boolean
|
|
9
10
|
* @returns boolean
|
|
10
11
|
* @group create
|
|
@@ -13,7 +14,8 @@ export declare class Logic {
|
|
|
13
14
|
*/
|
|
14
15
|
boolean(inputs: Inputs.Logic.BooleanDto): boolean;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* Generates a random boolean list where each value has a threshold chance of being true.
|
|
18
|
+
* Example: length=5, threshold=0.7 → might produce [true, true, false, true, true]
|
|
17
19
|
* @param inputs a length and a threshold for randomization of true values
|
|
18
20
|
* @returns booleans
|
|
19
21
|
* @group create
|
|
@@ -22,10 +24,10 @@ export declare class Logic {
|
|
|
22
24
|
*/
|
|
23
25
|
randomBooleans(inputs: Inputs.Logic.RandomBooleansDto): boolean[];
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* Converts numbers to booleans using two thresholds with gradient randomization between them.
|
|
28
|
+
* Values below trueThreshold → always true, above falseThreshold → always false.
|
|
29
|
+
* Between thresholds → probability gradient (closer to false threshold = higher chance of false).
|
|
30
|
+
* Example: [0.1, 0.4, 0.6, 0.9] with thresholds [0.3, 0.7] → [true, gradient, gradient, false]
|
|
29
31
|
* @param inputs a length and a threshold for randomization of true values
|
|
30
32
|
* @returns booleans
|
|
31
33
|
* @group create
|
|
@@ -34,7 +36,9 @@ export declare class Logic {
|
|
|
34
36
|
*/
|
|
35
37
|
twoThresholdRandomGradient(inputs: Inputs.Logic.TwoThresholdRandomGradientDto): boolean[];
|
|
36
38
|
/**
|
|
37
|
-
*
|
|
39
|
+
* Converts numbers to booleans based on a threshold (below threshold → true, above → false).
|
|
40
|
+
* Can be inverted to flip the logic.
|
|
41
|
+
* Example: [0.3, 0.7, 0.5] with threshold=0.6 → [true, false, true]
|
|
38
42
|
* @param inputs a length and a threshold for randomization of true values
|
|
39
43
|
* @returns booleans
|
|
40
44
|
* @group create
|
|
@@ -43,7 +47,9 @@ export declare class Logic {
|
|
|
43
47
|
*/
|
|
44
48
|
thresholdBooleanList(inputs: Inputs.Logic.ThresholdBooleanListDto): boolean[];
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
50
|
+
* Converts numbers to booleans using multiple range thresholds (gaps define true ranges).
|
|
51
|
+
* Values within any gap range → true, outside all gaps → false. Can be inverted.
|
|
52
|
+
* Example: [0.2, 0.5, 0.8] with gaps [[0.3, 0.6], [0.7, 0.9]] → [false, true, true]
|
|
47
53
|
* @param inputs a length and a threshold for randomization of true values
|
|
48
54
|
* @returns booleans
|
|
49
55
|
* @group create
|
|
@@ -52,7 +58,8 @@ export declare class Logic {
|
|
|
52
58
|
*/
|
|
53
59
|
thresholdGapsBooleanList(inputs: Inputs.Logic.ThresholdGapsBooleanListDto): boolean[];
|
|
54
60
|
/**
|
|
55
|
-
*
|
|
61
|
+
* Applies NOT operator to flip a boolean value.
|
|
62
|
+
* Example: true → false, false → true
|
|
56
63
|
* @param inputs a true or false boolean
|
|
57
64
|
* @returns boolean
|
|
58
65
|
* @group edit
|
|
@@ -61,7 +68,8 @@ export declare class Logic {
|
|
|
61
68
|
*/
|
|
62
69
|
not(inputs: Inputs.Logic.BooleanDto): boolean;
|
|
63
70
|
/**
|
|
64
|
-
*
|
|
71
|
+
* Applies NOT operator to flip all boolean values in a list.
|
|
72
|
+
* Example: [true, false, true] → [false, true, false]
|
|
65
73
|
* @param inputs a list of true or false booleans
|
|
66
74
|
* @returns booleans
|
|
67
75
|
* @group edit
|
|
@@ -70,7 +78,8 @@ export declare class Logic {
|
|
|
70
78
|
*/
|
|
71
79
|
notList(inputs: Inputs.Logic.BooleanListDto): boolean[];
|
|
72
80
|
/**
|
|
73
|
-
*
|
|
81
|
+
* Compares two values using various operators (==, !=, ===, !==, <, <=, >, >=).
|
|
82
|
+
* Example: 5 > 3 → true, 'hello' === 'world' → false
|
|
74
83
|
* @param inputs two values to be compared
|
|
75
84
|
* @returns Result of the comparison
|
|
76
85
|
* @group operations
|
|
@@ -79,7 +88,8 @@ export declare class Logic {
|
|
|
79
88
|
*/
|
|
80
89
|
compare<T>(inputs: Inputs.Logic.ComparisonDto<T>): boolean;
|
|
81
90
|
/**
|
|
82
|
-
*
|
|
91
|
+
* Conditionally passes a value through if boolean is true, otherwise returns undefined.
|
|
92
|
+
* Example: value=42, boolean=true → 42, value=42, boolean=false → undefined
|
|
83
93
|
* @param inputs a value and a boolean value
|
|
84
94
|
* @returns value or undefined
|
|
85
95
|
* @group operations
|
|
@@ -88,7 +98,8 @@ export declare class Logic {
|
|
|
88
98
|
*/
|
|
89
99
|
valueGate<T>(inputs: Inputs.Logic.ValueGateDto<T>): T | undefined;
|
|
90
100
|
/**
|
|
91
|
-
* Returns first defined value
|
|
101
|
+
* Returns the first defined (non-undefined) value from two options (fallback pattern).
|
|
102
|
+
* Example: value1=42, value2=10 → 42, value1=undefined, value2=10 → 10
|
|
92
103
|
* @param inputs two values
|
|
93
104
|
* @returns value or undefined
|
|
94
105
|
* @group operations
|