@bitbybit-dev/base 0.19.6 → 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.
Files changed (61) hide show
  1. package/babel.config.cjs +0 -1
  2. package/{index.js → index.ts} +2 -1
  3. package/lib/api/inputs/base-inputs.ts +18 -0
  4. package/lib/api/inputs/{color-inputs.d.ts → color-inputs.ts} +48 -26
  5. package/lib/api/inputs/{lists-inputs.d.ts → lists-inputs.ts} +190 -91
  6. package/lib/api/inputs/{logic-inputs.d.ts → logic-inputs.ts} +46 -24
  7. package/lib/api/inputs/{math-inputs.d.ts → math-inputs.ts} +97 -53
  8. package/lib/api/inputs/{point-inputs.d.ts → point-inputs.ts} +168 -77
  9. package/lib/api/inputs/text-inputs.ts +108 -0
  10. package/lib/api/inputs/{transforms-inputs.d.ts → transforms-inputs.ts} +64 -35
  11. package/lib/api/inputs/{vector-inputs.d.ts → vector-inputs.ts} +104 -48
  12. package/lib/api/services/color.test.ts +86 -0
  13. package/lib/api/services/{color.js → color.ts} +34 -15
  14. package/lib/api/services/{geometry-helper.js → geometry-helper.ts} +43 -31
  15. package/lib/api/services/{index.d.ts → index.ts} +1 -1
  16. package/lib/api/services/lists.test.ts +612 -0
  17. package/lib/api/services/{lists.js → lists.ts} +83 -59
  18. package/lib/api/services/logic.test.ts +187 -0
  19. package/lib/api/services/{logic.js → logic.ts} +32 -24
  20. package/lib/api/services/math.test.ts +622 -0
  21. package/lib/api/services/{math.js → math.ts} +136 -71
  22. package/lib/api/services/{point.js → point.ts} +67 -32
  23. package/lib/api/services/text.test.ts +55 -0
  24. package/lib/api/services/{text.js → text.ts} +17 -7
  25. package/lib/api/services/{transforms.js → transforms.ts} +83 -37
  26. package/lib/api/services/vector.test.ts +360 -0
  27. package/lib/api/services/{vector.js → vector.ts} +80 -42
  28. package/lib/{index.d.ts → index.ts} +1 -0
  29. package/package.json +1 -1
  30. package/tsconfig.bitbybit.json +26 -0
  31. package/tsconfig.json +24 -0
  32. package/babel.config.d.cts +0 -5
  33. package/index.d.ts +0 -1
  34. package/lib/api/index.js +0 -1
  35. package/lib/api/inputs/base-inputs.d.ts +0 -35
  36. package/lib/api/inputs/base-inputs.js +0 -1
  37. package/lib/api/inputs/color-inputs.js +0 -164
  38. package/lib/api/inputs/index.js +0 -9
  39. package/lib/api/inputs/inputs.js +0 -9
  40. package/lib/api/inputs/lists-inputs.js +0 -576
  41. package/lib/api/inputs/logic-inputs.js +0 -111
  42. package/lib/api/inputs/math-inputs.js +0 -391
  43. package/lib/api/inputs/point-inputs.js +0 -521
  44. package/lib/api/inputs/text-inputs.d.ts +0 -83
  45. package/lib/api/inputs/text-inputs.js +0 -120
  46. package/lib/api/inputs/transforms-inputs.js +0 -200
  47. package/lib/api/inputs/vector-inputs.js +0 -304
  48. package/lib/api/services/color.d.ts +0 -114
  49. package/lib/api/services/geometry-helper.d.ts +0 -15
  50. package/lib/api/services/index.js +0 -9
  51. package/lib/api/services/lists.d.ts +0 -287
  52. package/lib/api/services/logic.d.ts +0 -99
  53. package/lib/api/services/math.d.ts +0 -349
  54. package/lib/api/services/point.d.ts +0 -222
  55. package/lib/api/services/text.d.ts +0 -69
  56. package/lib/api/services/transforms.d.ts +0 -122
  57. package/lib/api/services/vector.d.ts +0 -320
  58. package/lib/index.js +0 -1
  59. /package/lib/api/{index.d.ts → index.ts} +0 -0
  60. /package/lib/api/inputs/{index.d.ts → index.ts} +0 -0
  61. /package/lib/api/inputs/{inputs.d.ts → inputs.ts} +0 -0
@@ -1,13 +1,17 @@
1
+ import { GeometryHelper } from "./geometry-helper";
2
+ import * as Inputs from "../inputs";
3
+ import { Transforms } from "./transforms";
4
+
1
5
  /**
2
6
  * Contains various methods for points. Point in bitbybit is simply an array containing 3 numbers for [x, y, z].
3
7
  * Because of this form Point can be interchanged with Vector, which also is an array in [x, y, z] form.
4
8
  * When creating 2D points, z coordinate is simply set to 0 - [x, y, 0].
5
9
  */
10
+
6
11
  export class Point {
7
- constructor(geometryHelper, transforms) {
8
- this.geometryHelper = geometryHelper;
9
- this.transforms = transforms;
10
- }
12
+
13
+ constructor(private readonly geometryHelper: GeometryHelper, private readonly transforms: Transforms) { }
14
+
11
15
  /**
12
16
  * Transforms the single point
13
17
  * @param inputs Contains a point and the transformations to apply
@@ -16,12 +20,13 @@ export class Point {
16
20
  * @shortname transform point
17
21
  * @drawable true
18
22
  */
19
- transformPoint(inputs) {
23
+ transformPoint(inputs: Inputs.Point.TransformPointDto): Inputs.Base.Point3 {
20
24
  const transformation = inputs.transformation;
21
25
  let transformedControlPoints = [inputs.point];
22
26
  transformedControlPoints = this.geometryHelper.transformControlPoints(transformation, transformedControlPoints);
23
27
  return transformedControlPoints[0];
24
28
  }
29
+
25
30
  /**
26
31
  * Transforms multiple points
27
32
  * @param inputs Contains points and the transformations to apply
@@ -30,9 +35,10 @@ export class Point {
30
35
  * @shortname transform points
31
36
  * @drawable true
32
37
  */
33
- transformPoints(inputs) {
38
+ transformPoints(inputs: Inputs.Point.TransformPointsDto): Inputs.Base.Point3[] {
34
39
  return this.geometryHelper.transformControlPoints(inputs.transformation, inputs.points);
35
40
  }
41
+
36
42
  /**
37
43
  * Transforms multiple points by multiple transformations
38
44
  * @param inputs Contains points and the transformations to apply
@@ -41,7 +47,7 @@ export class Point {
41
47
  * @shortname transforms for points
42
48
  * @drawable true
43
49
  */
44
- transformsForPoints(inputs) {
50
+ transformsForPoints(inputs: Inputs.Point.TransformsForPointsDto): Inputs.Base.Point3[] {
45
51
  if (inputs.points.length !== inputs.transformation.length) {
46
52
  throw new Error("You must provide equal nr of points and transformations");
47
53
  }
@@ -49,6 +55,7 @@ export class Point {
49
55
  return this.geometryHelper.transformControlPoints(inputs.transformation[index], [pt])[0];
50
56
  });
51
57
  }
58
+
52
59
  /**
53
60
  * Translate multiple points
54
61
  * @param inputs Contains points and the translation vector
@@ -57,10 +64,11 @@ export class Point {
57
64
  * @shortname translate points
58
65
  * @drawable true
59
66
  */
60
- translatePoints(inputs) {
67
+ translatePoints(inputs: Inputs.Point.TranslatePointsDto): Inputs.Base.Point3[] {
61
68
  const translationTransform = this.transforms.translationXYZ({ translation: inputs.translation });
62
69
  return this.geometryHelper.transformControlPoints(translationTransform, inputs.points);
63
70
  }
71
+
64
72
  /**
65
73
  * Translate multiple points
66
74
  * @param inputs Contains points and the translation vector
@@ -69,7 +77,7 @@ export class Point {
69
77
  * @shortname translate points with vectors
70
78
  * @drawable true
71
79
  */
72
- translatePointsWithVectors(inputs) {
80
+ translatePointsWithVectors(inputs: Inputs.Point.TranslatePointsWithVectorsDto): Inputs.Base.Point3[] {
73
81
  if (inputs.points.length !== inputs.translations.length) {
74
82
  throw new Error("You must provide equal nr of points and translations");
75
83
  }
@@ -78,6 +86,7 @@ export class Point {
78
86
  return this.geometryHelper.transformControlPoints(translationTransforms[index], [pt])[0];
79
87
  });
80
88
  }
89
+
81
90
  /**
82
91
  * Translate multiple points by x, y, z values provided
83
92
  * @param inputs Contains points and the translation in x y and z
@@ -86,10 +95,11 @@ export class Point {
86
95
  * @shortname translate xyz points
87
96
  * @drawable true
88
97
  */
89
- translateXYZPoints(inputs) {
98
+ translateXYZPoints(inputs: Inputs.Point.TranslateXYZPointsDto): Inputs.Base.Point3[] {
90
99
  const translationTransform = this.transforms.translationXYZ({ translation: [inputs.x, inputs.y, inputs.z] });
91
100
  return this.geometryHelper.transformControlPoints(translationTransform, inputs.points);
92
101
  }
102
+
93
103
  /**
94
104
  * Scale multiple points by providing center point and x, y, z scale factors
95
105
  * @param inputs Contains points, center point and scale factors
@@ -98,10 +108,11 @@ export class Point {
98
108
  * @shortname scale points on center
99
109
  * @drawable true
100
110
  */
101
- scalePointsCenterXYZ(inputs) {
111
+ scalePointsCenterXYZ(inputs: Inputs.Point.ScalePointsCenterXYZDto): Inputs.Base.Point3[] {
102
112
  const scaleTransforms = this.transforms.scaleCenterXYZ({ center: inputs.center, scaleXyz: inputs.scaleXyz });
103
113
  return this.geometryHelper.transformControlPoints(scaleTransforms, inputs.points);
104
114
  }
115
+
105
116
  /**
106
117
  * Rotate multiple points by providing center point, axis and degrees of rotation
107
118
  * @param inputs Contains points, axis, center point and angle of rotation
@@ -110,10 +121,11 @@ export class Point {
110
121
  * @shortname rotate points center axis
111
122
  * @drawable true
112
123
  */
113
- rotatePointsCenterAxis(inputs) {
124
+ rotatePointsCenterAxis(inputs: Inputs.Point.RotatePointsCenterAxisDto): Inputs.Base.Point3[] {
114
125
  const rotationTransforms = this.transforms.rotationCenterAxis({ center: inputs.center, axis: inputs.axis, angle: inputs.angle });
115
126
  return this.geometryHelper.transformControlPoints(rotationTransforms, inputs.points);
116
127
  }
128
+
117
129
  /**
118
130
  * Measures the closest distance between a point and a collection of points
119
131
  * @param inputs Point from which to measure and points to measure the distance against
@@ -122,9 +134,10 @@ export class Point {
122
134
  * @shortname distance to closest pt
123
135
  * @drawable false
124
136
  */
125
- closestPointFromPointsDistance(inputs) {
137
+ closestPointFromPointsDistance(inputs: Inputs.Point.ClosestPointFromPointsDto): number {
126
138
  return this.closestPointFromPointData(inputs).distance;
127
139
  }
140
+
128
141
  /**
129
142
  * Finds the closest point index between a point and a collection of points. Caution, index is not 0 based, it starts with 1.
130
143
  * @param inputs Point from which to find the index in a collection of points
@@ -133,9 +146,10 @@ export class Point {
133
146
  * @shortname index of closest pt
134
147
  * @drawable false
135
148
  */
136
- closestPointFromPointsIndex(inputs) {
149
+ closestPointFromPointsIndex(inputs: Inputs.Point.ClosestPointFromPointsDto): number {
137
150
  return this.closestPointFromPointData(inputs).index;
138
151
  }
152
+
139
153
  /**
140
154
  * Finds the closest point in a collection
141
155
  * @param inputs Point and points collection to find the closest point in
@@ -144,9 +158,10 @@ export class Point {
144
158
  * @shortname closest pt
145
159
  * @drawable true
146
160
  */
147
- closestPointFromPoints(inputs) {
148
- return this.closestPointFromPointData(inputs).point;
161
+ closestPointFromPoints(inputs: Inputs.Point.ClosestPointFromPointsDto): Inputs.Base.Point3 {
162
+ return this.closestPointFromPointData(inputs).point as Inputs.Base.Point3;
149
163
  }
164
+
150
165
  /**
151
166
  * Finds the distance between two points
152
167
  * @param inputs Coordinates of start and end points
@@ -155,12 +170,13 @@ export class Point {
155
170
  * @shortname distance
156
171
  * @drawable false
157
172
  */
158
- distance(inputs) {
173
+ distance(inputs: Inputs.Point.StartEndPointsDto): number {
159
174
  const x = inputs.endPoint[0] - inputs.startPoint[0];
160
175
  const y = inputs.endPoint[1] - inputs.startPoint[1];
161
176
  const z = inputs.endPoint[2] - inputs.startPoint[2];
162
177
  return Math.sqrt(x * x + y * y + z * z);
163
178
  }
179
+
164
180
  /**
165
181
  * Finds the distances between the start point and multiple end points
166
182
  * @param inputs Coordinates of start and end points
@@ -169,11 +185,12 @@ export class Point {
169
185
  * @shortname distances to points
170
186
  * @drawable false
171
187
  */
172
- distancesToPoints(inputs) {
188
+ distancesToPoints(inputs: Inputs.Point.StartEndPointsListDto): number[] {
173
189
  return inputs.endPoints.map(pt => {
174
190
  return this.distance({ startPoint: inputs.startPoint, endPoint: pt });
175
191
  });
176
192
  }
193
+
177
194
  /**
178
195
  * Multiply point by a specified amount
179
196
  * @param inputs The point to be multiplied and the amount of points to create
@@ -182,13 +199,14 @@ export class Point {
182
199
  * @shortname multiply point
183
200
  * @drawable true
184
201
  */
185
- multiplyPoint(inputs) {
202
+ multiplyPoint(inputs: Inputs.Point.MultiplyPointDto): Inputs.Base.Point3[] {
186
203
  const points = [];
187
204
  for (let i = 0; i < inputs.amountOfPoints; i++) {
188
205
  points.push([inputs.point[0], inputs.point[1], inputs.point[2]]);
189
206
  }
190
207
  return points;
191
208
  }
209
+
192
210
  /**
193
211
  * Get x coordinate of the point
194
212
  * @param inputs The point
@@ -197,9 +215,10 @@ export class Point {
197
215
  * @shortname x coord
198
216
  * @drawable false
199
217
  */
200
- getX(inputs) {
218
+ getX(inputs: Inputs.Point.PointDto): number {
201
219
  return inputs.point[0];
202
220
  }
221
+
203
222
  /**
204
223
  * Get y coordinate of the point
205
224
  * @param inputs The point
@@ -208,9 +227,10 @@ export class Point {
208
227
  * @shortname y coord
209
228
  * @drawable false
210
229
  */
211
- getY(inputs) {
230
+ getY(inputs: Inputs.Point.PointDto): number {
212
231
  return inputs.point[1];
213
232
  }
233
+
214
234
  /**
215
235
  * Get z coordinate of the point
216
236
  * @param inputs The point
@@ -219,9 +239,10 @@ export class Point {
219
239
  * @shortname z coord
220
240
  * @drawable false
221
241
  */
222
- getZ(inputs) {
242
+ getZ(inputs: Inputs.Point.PointDto): number {
223
243
  return inputs.point[2];
224
244
  }
245
+
225
246
  /**
226
247
  * Get average point of points
227
248
  * @param inputs The points
@@ -230,21 +251,24 @@ export class Point {
230
251
  * @shortname average point
231
252
  * @drawable true
232
253
  */
233
- averagePoint(inputs) {
254
+ averagePoint(inputs: Inputs.Point.PointsDto): Inputs.Base.Point3 {
234
255
  const xVals = [];
235
256
  const yVals = [];
236
257
  const zVals = [];
258
+
237
259
  inputs.points.forEach(pt => {
238
260
  xVals.push(pt[0]);
239
261
  yVals.push(pt[1]);
240
262
  zVals.push(pt[2]);
241
263
  });
264
+
242
265
  return [
243
266
  xVals.reduce((p, c) => p + c, 0) / inputs.points.length,
244
267
  yVals.reduce((p, c) => p + c, 0) / inputs.points.length,
245
268
  zVals.reduce((p, c) => p + c, 0) / inputs.points.length,
246
269
  ];
247
270
  }
271
+
248
272
  /**
249
273
  * Creates the xyz point
250
274
  * @param inputs xyz information
@@ -253,9 +277,10 @@ export class Point {
253
277
  * @shortname point xyz
254
278
  * @drawable true
255
279
  */
256
- pointXYZ(inputs) {
280
+ pointXYZ(inputs: Inputs.Point.PointXYZDto): Inputs.Base.Point3 {
257
281
  return [inputs.x, inputs.y, inputs.z];
258
282
  }
283
+
259
284
  /**
260
285
  * Creates the xy point
261
286
  * @param inputs xy information
@@ -264,9 +289,10 @@ export class Point {
264
289
  * @shortname point xy
265
290
  * @drawable false
266
291
  */
267
- pointXY(inputs) {
292
+ pointXY(inputs: Inputs.Point.PointXYDto): Inputs.Base.Point2 {
268
293
  return [inputs.x, inputs.y];
269
294
  }
295
+
270
296
  /**
271
297
  * Creates the spiral out of multiple points
272
298
  * @param inputs Spiral information
@@ -275,7 +301,7 @@ export class Point {
275
301
  * @shortname spiral
276
302
  * @drawable true
277
303
  */
278
- spiral(inputs) {
304
+ spiral(inputs: Inputs.Point.SpiralDto): Inputs.Base.Point3[] {
279
305
  const phi = inputs.phi;
280
306
  const b = Math.log(phi) / (Math.PI / inputs.widening);
281
307
  const spiral = [];
@@ -288,6 +314,7 @@ export class Point {
288
314
  }
289
315
  return spiral;
290
316
  }
317
+
291
318
  /**
292
319
  * Creates a flat point grid on XY plane. This grid contains center points for hexagons of the given radius.
293
320
  * Be aware that we control only the nr of hexagons to be made and not the length and width of the grid.
@@ -297,7 +324,7 @@ export class Point {
297
324
  * @shortname hex grid
298
325
  * @drawable true
299
326
  */
300
- hexGrid(inputs) {
327
+ hexGrid(inputs: Inputs.Point.HexGridCentersDto): Inputs.Base.Point3[] {
301
328
  const xLength = Math.sqrt(Math.pow(inputs.radiusHexagon, 2) - Math.pow(inputs.radiusHexagon / 2, 2));
302
329
  const points = [];
303
330
  for (let ix = 0; ix < inputs.nrHexagonsX; ix++) {
@@ -308,6 +335,7 @@ export class Point {
308
335
  points.push([adjustX, coordY, 0]);
309
336
  }
310
337
  }
338
+
311
339
  if (inputs.orientOnCenter) {
312
340
  const compensateX = points[points.length - 1][0] / 2;
313
341
  const compensateY = points[points.length - 1][1] / 2;
@@ -315,13 +343,16 @@ export class Point {
315
343
  points[index] = [p[0] - compensateX, p[1] - compensateY, 0];
316
344
  });
317
345
  }
346
+
318
347
  if (inputs.pointsOnGround) {
319
348
  points.forEach((p, index) => {
320
349
  points[index] = [p[0], 0, p[1]];
321
350
  });
322
351
  }
352
+
323
353
  return points;
324
354
  }
355
+
325
356
  /**
326
357
  * Removes consecutive duplicates from the point array with tolerance
327
358
  * @param inputs points, tolerance and check first and last
@@ -330,22 +361,26 @@ export class Point {
330
361
  * @shortname remove duplicates
331
362
  * @drawable true
332
363
  */
333
- removeConsecutiveDuplicates(inputs) {
364
+ removeConsecutiveDuplicates(inputs: Inputs.Point.RemoveConsecutiveDuplicatesDto): Inputs.Base.Point3[] {
334
365
  return this.geometryHelper.removeConsecutivePointDuplicates(inputs.points, inputs.checkFirstAndLast, inputs.tolerance);
335
366
  }
336
- closestPointFromPointData(inputs) {
367
+
368
+ private closestPointFromPointData(inputs: Inputs.Point.ClosestPointFromPointsDto): {
369
+ index: number, point: Inputs.Base.Point3, distance: number
370
+ } {
337
371
  let distance = Number.MAX_SAFE_INTEGER;
338
- let closestPointIndex;
339
- let point;
372
+ let closestPointIndex: number;
373
+ let point: Inputs.Base.Point3;
340
374
  for (let i = 0; i < inputs.points.length; i++) {
341
375
  const pt = inputs.points[i];
342
376
  const currentDist = this.distance({ startPoint: inputs.point, endPoint: pt });
343
377
  if (currentDist < distance) {
344
378
  distance = currentDist;
345
379
  closestPointIndex = i;
346
- point = pt;
380
+ point = pt as Inputs.Base.Point3;
347
381
  }
348
382
  }
349
383
  return { index: closestPointIndex + 1, distance, point };
350
384
  }
385
+
351
386
  }
@@ -0,0 +1,55 @@
1
+ import { TextBitByBit } from "./text";
2
+
3
+ describe("Text unit tests", () => {
4
+ let text: TextBitByBit;
5
+
6
+ beforeAll(async () => {
7
+ text = new TextBitByBit();
8
+ });
9
+
10
+ it("should create a text", async () => {
11
+ const result = text.create({ text: "Hello World, Matas" });
12
+ expect(result).toEqual("Hello World, Matas");
13
+ });
14
+
15
+ it("should split text", async () => {
16
+ const result = text.split({ text: "Hello World, Matas, Ubarevicius", separator: "," });
17
+ expect(result).toEqual(["Hello World", " Matas", " Ubarevicius"]);
18
+ });
19
+
20
+ it("should replace all in text", async () => {
21
+ const result = text.replaceAll({ text: "Hello World, Matas, Ubarevicius", search: ",", replaceWith: "-" });
22
+ expect(result).toEqual("Hello World- Matas- Ubarevicius");
23
+ });
24
+
25
+ it("should join all items", async () => {
26
+ const result = text.join({ list: ["Hello World", " Matas", " Ubarevicius"], separator: "," });
27
+ expect(result).toEqual("Hello World, Matas, Ubarevicius");
28
+ });
29
+
30
+ it("should convert to string item", async () => {
31
+ const result = text.toString({ item: [0, 0, 0] });
32
+ expect(result).toEqual("0,0,0");
33
+ });
34
+
35
+ it("should convert to string items", async () => {
36
+ const result = text.toStringEach({ list: [0, 1, 2] });
37
+ expect(result).toEqual(["0", "1", "2"]);
38
+ });
39
+
40
+ it("should format string", () => {
41
+ const result = text.format({ text: "Hello {0}, {1}", values: ["World", "Matas"] });
42
+ expect(result).toEqual("Hello World, Matas");
43
+ });
44
+
45
+ it("should not format string if there are no values", () => {
46
+ const result = text.format({ text: "Hello {0}, {1}", values: [] });
47
+ expect(result).toEqual("Hello {0}, {1}");
48
+ });
49
+
50
+ it("should not format string if there are no placeholders", () => {
51
+ const result = text.format({ text: "Hello World, Matas", values: ["dada"] });
52
+ expect(result).toEqual("Hello World, Matas");
53
+ });
54
+ });
55
+
@@ -1,7 +1,10 @@
1
+ import * as Inputs from "../inputs";
2
+
1
3
  /**
2
4
  * Contains various text methods.
3
5
  */
4
6
  export class TextBitByBit {
7
+
5
8
  /**
6
9
  * Creates a text
7
10
  * @param inputs a text
@@ -10,9 +13,10 @@ export class TextBitByBit {
10
13
  * @shortname text
11
14
  * @drawable false
12
15
  */
13
- create(inputs) {
16
+ create(inputs: Inputs.Text.TextDto): string {
14
17
  return inputs.text;
15
18
  }
19
+
16
20
  /**
17
21
  * Split the text to multiple pieces by a separator
18
22
  * @param inputs a text
@@ -21,9 +25,10 @@ export class TextBitByBit {
21
25
  * @shortname split
22
26
  * @drawable false
23
27
  */
24
- split(inputs) {
28
+ split(inputs: Inputs.Text.TextSplitDto): string[] {
25
29
  return inputs.text.split(inputs.separator);
26
30
  }
31
+
27
32
  /**
28
33
  * Replace all occurrences of a text by another text
29
34
  * @param inputs a text
@@ -32,9 +37,10 @@ export class TextBitByBit {
32
37
  * @shortname replaceAll
33
38
  * @drawable false
34
39
  */
35
- replaceAll(inputs) {
40
+ replaceAll(inputs: Inputs.Text.TextReplaceDto): string {
36
41
  return inputs.text.split(inputs.search).join(inputs.replaceWith);
37
42
  }
43
+
38
44
  /**
39
45
  * Join multiple items by a separator into text
40
46
  * @param inputs a list of items
@@ -43,9 +49,10 @@ export class TextBitByBit {
43
49
  * @shortname join
44
50
  * @drawable false
45
51
  */
46
- join(inputs) {
52
+ join(inputs: Inputs.Text.TextJoinDto): string {
47
53
  return inputs.list.join(inputs.separator);
48
54
  }
55
+
49
56
  /**
50
57
  * Transform any item to text
51
58
  * @param inputs any item
@@ -54,9 +61,10 @@ export class TextBitByBit {
54
61
  * @shortname to string
55
62
  * @drawable false
56
63
  */
57
- toString(inputs) {
64
+ toString<T>(inputs: Inputs.Text.ToStringDto<T>): string {
58
65
  return inputs.item.toString();
59
66
  }
67
+
60
68
  /**
61
69
  * Transform each item in list to text
62
70
  * @param inputs list of items
@@ -65,9 +73,10 @@ export class TextBitByBit {
65
73
  * @shortname to strings
66
74
  * @drawable false
67
75
  */
68
- toStringEach(inputs) {
76
+ toStringEach<T>(inputs: Inputs.Text.ToStringEachDto<T>): string[] {
69
77
  return inputs.list.map(i => i.toString());
70
78
  }
79
+
71
80
  /**
72
81
  * Format a text with values
73
82
  * @param inputs a text and values
@@ -76,9 +85,10 @@ export class TextBitByBit {
76
85
  * @shortname format
77
86
  * @drawable false
78
87
  */
79
- format(inputs) {
88
+ format(inputs: Inputs.Text.TextFormatDto): string {
80
89
  return inputs.text.replace(/{(\d+)}/g, (match, number) => {
81
90
  return typeof inputs.values[number] !== "undefined" ? inputs.values[number] : match;
82
91
  });
83
92
  }
93
+
84
94
  }