@bitbybit-dev/base 0.19.7 → 0.19.8
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/babel.config.cjs +0 -1
- package/{index.js → index.ts} +2 -1
- package/lib/api/inputs/base-inputs.ts +18 -0
- package/lib/api/inputs/{color-inputs.d.ts → color-inputs.ts} +48 -26
- package/lib/api/inputs/{lists-inputs.d.ts → lists-inputs.ts} +190 -91
- package/lib/api/inputs/{logic-inputs.d.ts → logic-inputs.ts} +46 -24
- package/lib/api/inputs/{math-inputs.d.ts → math-inputs.ts} +97 -53
- package/lib/api/inputs/{point-inputs.d.ts → point-inputs.ts} +168 -77
- package/lib/api/inputs/text-inputs.ts +108 -0
- package/lib/api/inputs/{transforms-inputs.d.ts → transforms-inputs.ts} +64 -35
- package/lib/api/inputs/{vector-inputs.d.ts → vector-inputs.ts} +104 -48
- package/lib/api/services/color.test.ts +86 -0
- package/lib/api/services/{color.js → color.ts} +34 -15
- package/lib/api/services/{geometry-helper.js → geometry-helper.ts} +43 -31
- package/lib/api/services/{index.d.ts → index.ts} +1 -1
- package/lib/api/services/lists.test.ts +612 -0
- package/lib/api/services/{lists.js → lists.ts} +83 -59
- package/lib/api/services/logic.test.ts +187 -0
- package/lib/api/services/{logic.js → logic.ts} +32 -24
- package/lib/api/services/math.test.ts +622 -0
- package/lib/api/services/{math.js → math.ts} +136 -71
- package/lib/api/services/{point.js → point.ts} +67 -32
- package/lib/api/services/text.test.ts +55 -0
- package/lib/api/services/{text.js → text.ts} +17 -7
- package/lib/api/services/{transforms.js → transforms.ts} +83 -37
- package/lib/api/services/vector.test.ts +360 -0
- package/lib/api/services/{vector.js → vector.ts} +80 -42
- package/lib/{index.d.ts → index.ts} +1 -0
- package/package.json +1 -1
- package/tsconfig.bitbybit.json +26 -0
- package/tsconfig.json +24 -0
- package/babel.config.d.cts +0 -5
- package/index.d.ts +0 -1
- package/lib/api/index.js +0 -1
- package/lib/api/inputs/base-inputs.d.ts +0 -35
- package/lib/api/inputs/base-inputs.js +0 -1
- package/lib/api/inputs/color-inputs.js +0 -164
- package/lib/api/inputs/index.js +0 -9
- package/lib/api/inputs/inputs.js +0 -9
- package/lib/api/inputs/lists-inputs.js +0 -576
- package/lib/api/inputs/logic-inputs.js +0 -111
- package/lib/api/inputs/math-inputs.js +0 -391
- package/lib/api/inputs/point-inputs.js +0 -521
- package/lib/api/inputs/text-inputs.d.ts +0 -83
- package/lib/api/inputs/text-inputs.js +0 -120
- package/lib/api/inputs/transforms-inputs.js +0 -200
- package/lib/api/inputs/vector-inputs.js +0 -304
- package/lib/api/services/color.d.ts +0 -114
- package/lib/api/services/geometry-helper.d.ts +0 -15
- package/lib/api/services/index.js +0 -9
- package/lib/api/services/lists.d.ts +0 -287
- package/lib/api/services/logic.d.ts +0 -99
- package/lib/api/services/math.d.ts +0 -349
- package/lib/api/services/point.d.ts +0 -222
- package/lib/api/services/text.d.ts +0 -69
- package/lib/api/services/transforms.d.ts +0 -122
- package/lib/api/services/vector.d.ts +0 -320
- package/lib/index.js +0 -1
- /package/lib/api/{index.d.ts → index.ts} +0 -0
- /package/lib/api/inputs/{index.d.ts → index.ts} +0 -0
- /package/lib/api/inputs/{inputs.d.ts → inputs.ts} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Contains various list methods.
|
|
4
5
|
* <div>
|
|
@@ -14,19 +15,20 @@ export class Lists {
|
|
|
14
15
|
* @shortname item by index
|
|
15
16
|
* @drawable false
|
|
16
17
|
*/
|
|
17
|
-
getItem(inputs) {
|
|
18
|
+
getItem<T>(inputs: Inputs.Lists.ListItemDto<T>): T {
|
|
18
19
|
if (inputs.index < 0 || inputs.index >= inputs.list.length) {
|
|
19
20
|
throw new Error("Index out of bounds");
|
|
20
21
|
}
|
|
21
22
|
let result;
|
|
22
23
|
if (inputs.clone) {
|
|
23
24
|
result = structuredClone(inputs.list[inputs.index]);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
25
|
+
} else {
|
|
26
26
|
result = inputs.list[inputs.index];
|
|
27
27
|
}
|
|
28
28
|
return result;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
|
|
30
32
|
/**
|
|
31
33
|
* Gets items randomly by using a threshold
|
|
32
34
|
* @param inputs a list and a threshold for randomization of items to remove
|
|
@@ -35,7 +37,7 @@ export class Lists {
|
|
|
35
37
|
* @shortname random get threshold
|
|
36
38
|
* @drawable false
|
|
37
39
|
*/
|
|
38
|
-
randomGetThreshold(inputs) {
|
|
40
|
+
randomGetThreshold<T>(inputs: Inputs.Lists.RandomThresholdDto<T>): T[] {
|
|
39
41
|
let res = inputs.list;
|
|
40
42
|
if (inputs.clone) {
|
|
41
43
|
res = structuredClone(inputs.list);
|
|
@@ -48,6 +50,7 @@ export class Lists {
|
|
|
48
50
|
}
|
|
49
51
|
return newList;
|
|
50
52
|
}
|
|
53
|
+
|
|
51
54
|
/**
|
|
52
55
|
* Gets a sub list between start and end indexes
|
|
53
56
|
* @param inputs a list and start and end indexes
|
|
@@ -56,16 +59,16 @@ export class Lists {
|
|
|
56
59
|
* @shortname sublist
|
|
57
60
|
* @drawable false
|
|
58
61
|
*/
|
|
59
|
-
getSubList(inputs) {
|
|
62
|
+
getSubList<T>(inputs: Inputs.Lists.SubListDto<T>): T[] {
|
|
60
63
|
let result;
|
|
61
64
|
if (inputs.clone) {
|
|
62
65
|
result = structuredClone(inputs.list.slice(inputs.indexStart, inputs.indexEnd));
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
66
|
+
} else {
|
|
65
67
|
result = inputs.list.slice(inputs.indexStart, inputs.indexEnd);
|
|
66
68
|
}
|
|
67
69
|
return result;
|
|
68
70
|
}
|
|
71
|
+
|
|
69
72
|
/**
|
|
70
73
|
* Gets nth item in the list
|
|
71
74
|
* @param inputs a list and index
|
|
@@ -74,7 +77,7 @@ export class Lists {
|
|
|
74
77
|
* @shortname every n-th
|
|
75
78
|
* @drawable false
|
|
76
79
|
*/
|
|
77
|
-
getNthItem(inputs) {
|
|
80
|
+
getNthItem<T>(inputs: Inputs.Lists.GetNthItemDto<T>): T[] {
|
|
78
81
|
let cloned = inputs.list;
|
|
79
82
|
if (inputs.clone) {
|
|
80
83
|
cloned = structuredClone(inputs.list);
|
|
@@ -95,7 +98,7 @@ export class Lists {
|
|
|
95
98
|
* @shortname by pattern
|
|
96
99
|
* @drawable false
|
|
97
100
|
*/
|
|
98
|
-
getByPattern(inputs) {
|
|
101
|
+
getByPattern<T>(inputs: Inputs.Lists.GetByPatternDto<T>): T[] {
|
|
99
102
|
const { list, pattern } = inputs;
|
|
100
103
|
if (!pattern || pattern.length === 0) {
|
|
101
104
|
throw new Error("Pattern is empty or does not exist");
|
|
@@ -124,6 +127,7 @@ export class Lists {
|
|
|
124
127
|
}
|
|
125
128
|
return result;
|
|
126
129
|
}
|
|
130
|
+
|
|
127
131
|
/**
|
|
128
132
|
* Merge elements of lists on a given level and flatten output if needed
|
|
129
133
|
* @param inputs lists, level and flatten data
|
|
@@ -132,9 +136,10 @@ export class Lists {
|
|
|
132
136
|
* @shortname merge levels
|
|
133
137
|
* @drawable false
|
|
134
138
|
*/
|
|
135
|
-
mergeElementsOfLists(inputs) {
|
|
139
|
+
mergeElementsOfLists<T>(inputs: Inputs.Lists.MergeElementsOfLists<T[]>): T[] {
|
|
136
140
|
const lists = inputs.lists;
|
|
137
141
|
const level = inputs.level;
|
|
142
|
+
|
|
138
143
|
const elToMerge = [];
|
|
139
144
|
const result = [];
|
|
140
145
|
lists.forEach(list => {
|
|
@@ -142,6 +147,7 @@ export class Lists {
|
|
|
142
147
|
const elementsToMerge = list.flat(level);
|
|
143
148
|
elToMerge.push(elementsToMerge);
|
|
144
149
|
});
|
|
150
|
+
|
|
145
151
|
const lengthMerge = this.getLongestListLength({ lists: elToMerge });
|
|
146
152
|
for (let i = 0; i < lengthMerge; i++) {
|
|
147
153
|
const temp = [];
|
|
@@ -155,25 +161,24 @@ export class Lists {
|
|
|
155
161
|
result.push(temp);
|
|
156
162
|
}
|
|
157
163
|
}
|
|
164
|
+
|
|
158
165
|
let final = [];
|
|
159
166
|
if (level > 0) {
|
|
160
167
|
for (let i = 0; i < level; i++) {
|
|
161
168
|
if (i === level - 1 && i !== 0) {
|
|
162
169
|
final[i - 1].push(result);
|
|
163
|
-
}
|
|
164
|
-
else if (i === level - 1) {
|
|
170
|
+
} else if (i === level - 1) {
|
|
165
171
|
final.push(result);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
172
|
+
} else {
|
|
168
173
|
final.push([]);
|
|
169
174
|
}
|
|
170
175
|
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
176
|
+
} else {
|
|
173
177
|
final = result;
|
|
174
178
|
}
|
|
175
179
|
return final;
|
|
176
180
|
}
|
|
181
|
+
|
|
177
182
|
/**
|
|
178
183
|
* Gets the longest list length from the list of lists
|
|
179
184
|
* @param inputs a list of lists
|
|
@@ -182,20 +187,21 @@ export class Lists {
|
|
|
182
187
|
* @shortname longest list length
|
|
183
188
|
* @drawable false
|
|
184
189
|
*/
|
|
185
|
-
getLongestListLength(inputs) {
|
|
190
|
+
getLongestListLength<T>(inputs: Inputs.Lists.GetLongestListLength<T[]>): number {
|
|
186
191
|
let longestSoFar = 0;
|
|
187
192
|
if (inputs.lists) {
|
|
193
|
+
|
|
188
194
|
inputs.lists.forEach(l => {
|
|
189
195
|
if (l.length > longestSoFar) {
|
|
190
196
|
longestSoFar = l.length;
|
|
191
197
|
}
|
|
192
198
|
});
|
|
193
199
|
return longestSoFar;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
200
|
+
} else {
|
|
196
201
|
return undefined;
|
|
197
202
|
}
|
|
198
203
|
}
|
|
204
|
+
|
|
199
205
|
/**
|
|
200
206
|
* Reverse the list
|
|
201
207
|
* @param inputs a list and an index
|
|
@@ -204,13 +210,14 @@ export class Lists {
|
|
|
204
210
|
* @shortname reverse
|
|
205
211
|
* @drawable false
|
|
206
212
|
*/
|
|
207
|
-
reverse(inputs) {
|
|
213
|
+
reverse<T>(inputs: Inputs.Lists.ListCloneDto<T>): T[] {
|
|
208
214
|
let res = inputs.list;
|
|
209
215
|
if (inputs.clone) {
|
|
210
216
|
res = structuredClone(inputs.list);
|
|
211
217
|
}
|
|
212
218
|
return res.reverse();
|
|
213
219
|
}
|
|
220
|
+
|
|
214
221
|
/**
|
|
215
222
|
* Flip 2d lists - every nth element of each list will form a separate list
|
|
216
223
|
* @param inputs a list of lists to flip
|
|
@@ -219,7 +226,7 @@ export class Lists {
|
|
|
219
226
|
* @shortname flip lists
|
|
220
227
|
* @drawable false
|
|
221
228
|
*/
|
|
222
|
-
flipLists(inputs) {
|
|
229
|
+
flipLists<T>(inputs: Inputs.Lists.ListCloneDto<T[]>): T[][] {
|
|
223
230
|
if (inputs.list.length > 0) {
|
|
224
231
|
const lengthOfFirstList = inputs.list[0].length;
|
|
225
232
|
let allListsSameLength = true;
|
|
@@ -238,15 +245,14 @@ export class Lists {
|
|
|
238
245
|
result.push(newList);
|
|
239
246
|
}
|
|
240
247
|
return result;
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
248
|
+
} else {
|
|
243
249
|
throw new Error("Lists are not of the same length");
|
|
244
250
|
}
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
251
|
+
} else {
|
|
247
252
|
throw new Error("List is empty");
|
|
248
253
|
}
|
|
249
254
|
}
|
|
255
|
+
|
|
250
256
|
/**
|
|
251
257
|
* Group in lists of n elements
|
|
252
258
|
* @param inputs a list
|
|
@@ -255,8 +261,8 @@ export class Lists {
|
|
|
255
261
|
* @shortname group elements
|
|
256
262
|
* @drawable false
|
|
257
263
|
*/
|
|
258
|
-
groupNth(inputs) {
|
|
259
|
-
const groupElements = (inputs) => {
|
|
264
|
+
groupNth<T>(inputs: Inputs.Lists.GroupListDto<T>): T[] {
|
|
265
|
+
const groupElements = (inputs: Inputs.Lists.GroupListDto<T>) => {
|
|
260
266
|
const { nrElements, list, keepRemainder } = inputs;
|
|
261
267
|
const nrElementsInGroup = nrElements;
|
|
262
268
|
const result = [];
|
|
@@ -276,6 +282,7 @@ export class Lists {
|
|
|
276
282
|
// TODO make this work on any level
|
|
277
283
|
return groupElements(inputs);
|
|
278
284
|
}
|
|
285
|
+
|
|
279
286
|
/**
|
|
280
287
|
* Get the depth of the list
|
|
281
288
|
* @param inputs a list
|
|
@@ -284,7 +291,7 @@ export class Lists {
|
|
|
284
291
|
* @shortname max list depth
|
|
285
292
|
* @drawable false
|
|
286
293
|
*/
|
|
287
|
-
getListDepth(inputs) {
|
|
294
|
+
getListDepth(inputs: Inputs.Lists.ListCloneDto<[]>): number {
|
|
288
295
|
let levels = 0;
|
|
289
296
|
let deeperLevelsExist = true;
|
|
290
297
|
let flatRes = inputs.list;
|
|
@@ -298,14 +305,14 @@ export class Lists {
|
|
|
298
305
|
flatRes = flatRes.flat();
|
|
299
306
|
if (foundArray) {
|
|
300
307
|
levels++;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
308
|
+
} else {
|
|
303
309
|
levels++;
|
|
304
310
|
deeperLevelsExist = false;
|
|
305
311
|
}
|
|
306
312
|
}
|
|
307
313
|
return levels;
|
|
308
314
|
}
|
|
315
|
+
|
|
309
316
|
/**
|
|
310
317
|
* Gets the length of the list
|
|
311
318
|
* @param inputs a length list
|
|
@@ -314,9 +321,10 @@ export class Lists {
|
|
|
314
321
|
* @shortname list length
|
|
315
322
|
* @drawable false
|
|
316
323
|
*/
|
|
317
|
-
listLength(inputs) {
|
|
324
|
+
listLength<T>(inputs: Inputs.Lists.ListCloneDto<T>): number {
|
|
318
325
|
return inputs.list.length;
|
|
319
326
|
}
|
|
327
|
+
|
|
320
328
|
/**
|
|
321
329
|
* Add item to the list
|
|
322
330
|
* @param inputs a list, item and an index
|
|
@@ -325,7 +333,7 @@ export class Lists {
|
|
|
325
333
|
* @shortname add item
|
|
326
334
|
* @drawable false
|
|
327
335
|
*/
|
|
328
|
-
addItemAtIndex(inputs) {
|
|
336
|
+
addItemAtIndex<T>(inputs: Inputs.Lists.AddItemAtIndexDto<T>): T[] {
|
|
329
337
|
let res = inputs.list;
|
|
330
338
|
if (inputs.clone) {
|
|
331
339
|
res = structuredClone(inputs.list);
|
|
@@ -335,6 +343,7 @@ export class Lists {
|
|
|
335
343
|
}
|
|
336
344
|
return res;
|
|
337
345
|
}
|
|
346
|
+
|
|
338
347
|
/**
|
|
339
348
|
* Adds item to the list of provided indexes
|
|
340
349
|
* @param inputs a list, item and an indexes
|
|
@@ -343,7 +352,7 @@ export class Lists {
|
|
|
343
352
|
* @shortname add item at indexes
|
|
344
353
|
* @drawable false
|
|
345
354
|
*/
|
|
346
|
-
addItemAtIndexes(inputs) {
|
|
355
|
+
addItemAtIndexes<T>(inputs: Inputs.Lists.AddItemAtIndexesDto<T>): T[] {
|
|
347
356
|
let cloned = inputs.list;
|
|
348
357
|
if (inputs.clone) {
|
|
349
358
|
cloned = structuredClone(inputs.list);
|
|
@@ -355,9 +364,11 @@ export class Lists {
|
|
|
355
364
|
if (index >= 0 && index + i <= cloned.length) {
|
|
356
365
|
cloned.splice(index + i, 0, inputs.item);
|
|
357
366
|
}
|
|
358
|
-
}
|
|
367
|
+
}
|
|
368
|
+
);
|
|
359
369
|
return cloned;
|
|
360
370
|
}
|
|
371
|
+
|
|
361
372
|
/**
|
|
362
373
|
* Adds items to the list of provided indexes matching 1:1, first item will go to first index provided, etc.
|
|
363
374
|
* @param inputs a list, items and an indexes
|
|
@@ -366,7 +377,7 @@ export class Lists {
|
|
|
366
377
|
* @shortname add items
|
|
367
378
|
* @drawable false
|
|
368
379
|
*/
|
|
369
|
-
addItemsAtIndexes(inputs) {
|
|
380
|
+
addItemsAtIndexes<T>(inputs: Inputs.Lists.AddItemsAtIndexesDto<T>): T[] {
|
|
370
381
|
if (inputs.items.length !== inputs.indexes.length) {
|
|
371
382
|
throw new Error("Items and indexes must have the same length");
|
|
372
383
|
}
|
|
@@ -390,6 +401,7 @@ export class Lists {
|
|
|
390
401
|
});
|
|
391
402
|
return cloned;
|
|
392
403
|
}
|
|
404
|
+
|
|
393
405
|
/**
|
|
394
406
|
* Remove item from the list
|
|
395
407
|
* @param inputs a list and index
|
|
@@ -398,7 +410,7 @@ export class Lists {
|
|
|
398
410
|
* @shortname remove item
|
|
399
411
|
* @drawable false
|
|
400
412
|
*/
|
|
401
|
-
removeItemAtIndex(inputs) {
|
|
413
|
+
removeItemAtIndex<T>(inputs: Inputs.Lists.RemoveItemAtIndexDto<T>): T[] {
|
|
402
414
|
let res = inputs.list;
|
|
403
415
|
if (inputs.clone) {
|
|
404
416
|
res = structuredClone(inputs.list);
|
|
@@ -408,6 +420,7 @@ export class Lists {
|
|
|
408
420
|
}
|
|
409
421
|
return res;
|
|
410
422
|
}
|
|
423
|
+
|
|
411
424
|
/**
|
|
412
425
|
* Remove items from the list of provided indexes
|
|
413
426
|
* @param inputs a list and indexes
|
|
@@ -416,7 +429,7 @@ export class Lists {
|
|
|
416
429
|
* @shortname remove items
|
|
417
430
|
* @drawable false
|
|
418
431
|
*/
|
|
419
|
-
removeItemsAtIndexes(inputs) {
|
|
432
|
+
removeItemsAtIndexes<T>(inputs: Inputs.Lists.RemoveItemsAtIndexesDto<T>): T[] {
|
|
420
433
|
let res = inputs.list;
|
|
421
434
|
if (inputs.clone) {
|
|
422
435
|
res = structuredClone(inputs.list);
|
|
@@ -430,6 +443,7 @@ export class Lists {
|
|
|
430
443
|
});
|
|
431
444
|
return res;
|
|
432
445
|
}
|
|
446
|
+
|
|
433
447
|
/**
|
|
434
448
|
* Remove all items from the list
|
|
435
449
|
* @param inputs a list
|
|
@@ -438,10 +452,11 @@ export class Lists {
|
|
|
438
452
|
* @shortname remove all items
|
|
439
453
|
* @drawable false
|
|
440
454
|
*/
|
|
441
|
-
removeAllItems(inputs) {
|
|
455
|
+
removeAllItems<T>(inputs: Inputs.Lists.ListDto<T>): T[] {
|
|
442
456
|
inputs.list.length = 0;
|
|
443
457
|
return inputs.list;
|
|
444
458
|
}
|
|
459
|
+
|
|
445
460
|
/**
|
|
446
461
|
* Remove item from the list
|
|
447
462
|
* @param inputs a list and index
|
|
@@ -450,7 +465,7 @@ export class Lists {
|
|
|
450
465
|
* @shortname every n-th
|
|
451
466
|
* @drawable false
|
|
452
467
|
*/
|
|
453
|
-
removeNthItem(inputs) {
|
|
468
|
+
removeNthItem<T>(inputs: Inputs.Lists.RemoveNthItemDto<T>): T[] {
|
|
454
469
|
let res = inputs.list;
|
|
455
470
|
if (inputs.clone) {
|
|
456
471
|
res = structuredClone(inputs.list);
|
|
@@ -463,6 +478,7 @@ export class Lists {
|
|
|
463
478
|
}
|
|
464
479
|
return result;
|
|
465
480
|
}
|
|
481
|
+
|
|
466
482
|
/**
|
|
467
483
|
* Removes items randomly by using a threshold
|
|
468
484
|
* @param inputs a list and a threshold for randomization of items to remove
|
|
@@ -471,7 +487,7 @@ export class Lists {
|
|
|
471
487
|
* @shortname random remove threshold
|
|
472
488
|
* @drawable false
|
|
473
489
|
*/
|
|
474
|
-
randomRemoveThreshold(inputs) {
|
|
490
|
+
randomRemoveThreshold<T>(inputs: Inputs.Lists.RandomThresholdDto<T>): T[] {
|
|
475
491
|
let res = inputs.list;
|
|
476
492
|
if (inputs.clone) {
|
|
477
493
|
res = structuredClone(inputs.list);
|
|
@@ -484,6 +500,7 @@ export class Lists {
|
|
|
484
500
|
}
|
|
485
501
|
return newList;
|
|
486
502
|
}
|
|
503
|
+
|
|
487
504
|
/**
|
|
488
505
|
* remove duplicate numbers from the list
|
|
489
506
|
* @param inputs a list of numbers
|
|
@@ -492,13 +509,14 @@ export class Lists {
|
|
|
492
509
|
* @shortname remove duplicates
|
|
493
510
|
* @drawable false
|
|
494
511
|
*/
|
|
495
|
-
removeDuplicateNumbers(inputs) {
|
|
512
|
+
removeDuplicateNumbers(inputs: Inputs.Lists.RemoveDuplicatesDto<number>): number[] {
|
|
496
513
|
let res = inputs.list;
|
|
497
514
|
if (inputs.clone) {
|
|
498
515
|
res = structuredClone(inputs.list);
|
|
499
516
|
}
|
|
500
517
|
return res.filter((value, index, self) => self.indexOf(value) === index);
|
|
501
518
|
}
|
|
519
|
+
|
|
502
520
|
/**
|
|
503
521
|
* remove duplicate numbers from the list with tolerance
|
|
504
522
|
* @param inputs a list of numbers and the tolerance
|
|
@@ -507,13 +525,14 @@ export class Lists {
|
|
|
507
525
|
* @shortname remove duplicates tol
|
|
508
526
|
* @drawable false
|
|
509
527
|
*/
|
|
510
|
-
removeDuplicateNumbersTolerance(inputs) {
|
|
528
|
+
removeDuplicateNumbersTolerance(inputs: Inputs.Lists.RemoveDuplicatesToleranceDto<number>): number[] {
|
|
511
529
|
let res = inputs.list;
|
|
512
530
|
if (inputs.clone) {
|
|
513
531
|
res = structuredClone(inputs.list);
|
|
514
532
|
}
|
|
515
533
|
return res.filter((value, index, self) => self.findIndex(s => Math.abs(s - value) < inputs.tolerance) === index);
|
|
516
534
|
}
|
|
535
|
+
|
|
517
536
|
/**
|
|
518
537
|
* Add item to the end of the list
|
|
519
538
|
* @param inputs a list and an item
|
|
@@ -522,7 +541,7 @@ export class Lists {
|
|
|
522
541
|
* @shortname add item to list
|
|
523
542
|
* @drawable false
|
|
524
543
|
*/
|
|
525
|
-
addItem(inputs) {
|
|
544
|
+
addItem<T>(inputs: Inputs.Lists.AddItemDto<T>): T[] {
|
|
526
545
|
let res = inputs.list;
|
|
527
546
|
if (inputs.clone) {
|
|
528
547
|
res = structuredClone(inputs.list);
|
|
@@ -530,6 +549,7 @@ export class Lists {
|
|
|
530
549
|
res.push(inputs.item);
|
|
531
550
|
return res;
|
|
532
551
|
}
|
|
552
|
+
|
|
533
553
|
/**
|
|
534
554
|
* Add item to the beginning of the list
|
|
535
555
|
* @param inputs a list and an item
|
|
@@ -538,7 +558,7 @@ export class Lists {
|
|
|
538
558
|
* @shortname prepend item to list
|
|
539
559
|
* @drawable false
|
|
540
560
|
*/
|
|
541
|
-
prependItem(inputs) {
|
|
561
|
+
prependItem<T>(inputs: Inputs.Lists.AddItemDto<T>): T[] {
|
|
542
562
|
let res = inputs.list;
|
|
543
563
|
if (inputs.clone) {
|
|
544
564
|
res = structuredClone(inputs.list);
|
|
@@ -546,6 +566,7 @@ export class Lists {
|
|
|
546
566
|
res.unshift(inputs.item);
|
|
547
567
|
return res;
|
|
548
568
|
}
|
|
569
|
+
|
|
549
570
|
/**
|
|
550
571
|
* Add item to the beginning or the end of the list
|
|
551
572
|
* @param inputs a list, item and an option for first or last position
|
|
@@ -554,19 +575,19 @@ export class Lists {
|
|
|
554
575
|
* @shortname item at first or last
|
|
555
576
|
* @drawable false
|
|
556
577
|
*/
|
|
557
|
-
addItemFirstLast(inputs) {
|
|
578
|
+
addItemFirstLast<T>(inputs: Inputs.Lists.AddItemFirstLastDto<T>): T[] {
|
|
558
579
|
let res = inputs.list;
|
|
559
580
|
if (inputs.clone) {
|
|
560
581
|
res = structuredClone(inputs.list);
|
|
561
582
|
}
|
|
562
583
|
if (inputs.position === Inputs.Lists.firstLastEnum.first) {
|
|
563
584
|
res.unshift(inputs.item);
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
585
|
+
} else {
|
|
566
586
|
res.push(inputs.item);
|
|
567
587
|
}
|
|
568
588
|
return res;
|
|
569
589
|
}
|
|
590
|
+
|
|
570
591
|
/**
|
|
571
592
|
* Creates an empty list
|
|
572
593
|
* @returns an empty array list
|
|
@@ -574,9 +595,10 @@ export class Lists {
|
|
|
574
595
|
* @shortname empty list
|
|
575
596
|
* @drawable false
|
|
576
597
|
*/
|
|
577
|
-
createEmptyList() {
|
|
598
|
+
createEmptyList(): [] {
|
|
578
599
|
return [];
|
|
579
600
|
}
|
|
601
|
+
|
|
580
602
|
/**
|
|
581
603
|
* Repeat the item and add it in the new list
|
|
582
604
|
* @param inputs an item to multiply
|
|
@@ -585,13 +607,14 @@ export class Lists {
|
|
|
585
607
|
* @shortname repeat
|
|
586
608
|
* @drawable false
|
|
587
609
|
*/
|
|
588
|
-
repeat(inputs) {
|
|
610
|
+
repeat<T>(inputs: Inputs.Lists.MultiplyItemDto<T>): T[] {
|
|
589
611
|
const result = [];
|
|
590
612
|
for (let i = 0; i < inputs.times; i++) {
|
|
591
613
|
result.push(inputs.item);
|
|
592
614
|
}
|
|
593
615
|
return result;
|
|
594
616
|
}
|
|
617
|
+
|
|
595
618
|
/**
|
|
596
619
|
* Repeat the list items by adding them in the new list till the certain length of the list is reached
|
|
597
620
|
* @param inputs a list to multiply and a length limit
|
|
@@ -600,7 +623,7 @@ export class Lists {
|
|
|
600
623
|
* @shortname repeat in pattern
|
|
601
624
|
* @drawable false
|
|
602
625
|
*/
|
|
603
|
-
repeatInPattern(inputs) {
|
|
626
|
+
repeatInPattern<T>(inputs: Inputs.Lists.RepeatInPatternDto<T>): T[] {
|
|
604
627
|
// will repeat the items provided in the patten till the certain length of the list is reached
|
|
605
628
|
let inpList = inputs.list;
|
|
606
629
|
if (inputs.clone) {
|
|
@@ -619,6 +642,7 @@ export class Lists {
|
|
|
619
642
|
}
|
|
620
643
|
return res;
|
|
621
644
|
}
|
|
645
|
+
|
|
622
646
|
/**
|
|
623
647
|
* Sort the list of numbers in ascending or descending order
|
|
624
648
|
* @param inputs a list of numbers to sort and an option for ascending or descending order
|
|
@@ -627,18 +651,18 @@ export class Lists {
|
|
|
627
651
|
* @shortname sort numbers
|
|
628
652
|
* @drawable false
|
|
629
653
|
*/
|
|
630
|
-
sortNumber(inputs) {
|
|
654
|
+
sortNumber(inputs: Inputs.Lists.SortDto<number>): number[] {
|
|
631
655
|
let res = inputs.list;
|
|
632
656
|
if (inputs.clone) {
|
|
633
657
|
res = structuredClone(inputs.list);
|
|
634
658
|
}
|
|
635
659
|
if (inputs.orderAsc) {
|
|
636
660
|
return res.sort((a, b) => a - b);
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
661
|
+
} else {
|
|
639
662
|
return res.sort((a, b) => b - a);
|
|
640
663
|
}
|
|
641
664
|
}
|
|
665
|
+
|
|
642
666
|
/**
|
|
643
667
|
* Sort the list of texts in ascending or descending order alphabetically
|
|
644
668
|
* @param inputs a list of texts to sort and an option for ascending or descending order
|
|
@@ -647,18 +671,18 @@ export class Lists {
|
|
|
647
671
|
* @shortname sort texts
|
|
648
672
|
* @drawable false
|
|
649
673
|
*/
|
|
650
|
-
sortTexts(inputs) {
|
|
674
|
+
sortTexts(inputs: Inputs.Lists.SortDto<string>): string[] {
|
|
651
675
|
let res = inputs.list;
|
|
652
676
|
if (inputs.clone) {
|
|
653
677
|
res = structuredClone(inputs.list);
|
|
654
678
|
}
|
|
655
679
|
if (inputs.orderAsc) {
|
|
656
680
|
return res.sort();
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
681
|
+
} else {
|
|
659
682
|
return res.sort().reverse();
|
|
660
683
|
}
|
|
661
684
|
}
|
|
685
|
+
|
|
662
686
|
/**
|
|
663
687
|
* Sort by numeric JSON property value
|
|
664
688
|
* @param inputs a list to sort, a property to sort by and an option for ascending or descending order
|
|
@@ -667,16 +691,16 @@ export class Lists {
|
|
|
667
691
|
* @shortname sort json objects
|
|
668
692
|
* @drawable false
|
|
669
693
|
*/
|
|
670
|
-
sortByPropValue(inputs) {
|
|
694
|
+
sortByPropValue(inputs: Inputs.Lists.SortJsonDto<any>): any[] {
|
|
671
695
|
let res = inputs.list;
|
|
672
696
|
if (inputs.clone) {
|
|
673
697
|
res = structuredClone(inputs.list);
|
|
674
698
|
}
|
|
675
699
|
if (inputs.orderAsc) {
|
|
676
700
|
return res.sort((a, b) => a[inputs.property] - b[inputs.property]);
|
|
677
|
-
}
|
|
678
|
-
else {
|
|
701
|
+
} else {
|
|
679
702
|
return res.sort((a, b) => b[inputs.property] - a[inputs.property]);
|
|
680
703
|
}
|
|
681
704
|
}
|
|
705
|
+
|
|
682
706
|
}
|