@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
package/lib/api/services/text.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
2
|
import { defaultsVectorParams } from "../models/simplex";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Working with text: splitting, joining, searching, trimming, padding, changing case, regular
|
|
5
|
+
* expressions and formatting with placeholders. `vectorChar` and `vectorText` turn text into line
|
|
6
|
+
* paths drawn with a simple stroke font, so words can become geometry. Positions in text count from
|
|
7
|
+
* 0.
|
|
5
8
|
*/
|
|
6
9
|
export class TextBitByBit {
|
|
7
10
|
constructor(point) {
|
|
8
11
|
this.point = point;
|
|
9
12
|
}
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
14
|
+
* Passes a text through unchanged, so a value can be given a name and reused.
|
|
15
|
+
*
|
|
16
|
+
* Example: 'Hello World' -> 'Hello World'
|
|
17
|
+
* @param inputs - The text
|
|
18
|
+
* @returns The same text
|
|
15
19
|
* @group create
|
|
16
20
|
* @shortname text
|
|
17
21
|
* @drawable false
|
|
@@ -20,71 +24,97 @@ export class TextBitByBit {
|
|
|
20
24
|
return inputs.text;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
* Cuts a text into pieces wherever a separator occurs; the separator itself is dropped.
|
|
28
|
+
*
|
|
29
|
+
* Example: 'apple,banana,cherry' split by ',' -> ['apple', 'banana', 'cherry']
|
|
30
|
+
* @param inputs - The text and the separator
|
|
31
|
+
* @returns The pieces, in order
|
|
32
|
+
* @group transform
|
|
33
|
+
* @shortname split
|
|
34
|
+
* @drawable false
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const parts = bitbybit.text.split({ text: "apple,banana,cherry", separator: "," });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
31
40
|
split(inputs) {
|
|
32
41
|
return inputs.text.split(inputs.separator);
|
|
33
42
|
}
|
|
34
43
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
* Replaces every occurrence of a search text with another text.
|
|
45
|
+
*
|
|
46
|
+
* Example: 'hello hello' replacing 'hello' with 'hi' -> 'hi hi'
|
|
47
|
+
* @param inputs - The text, what to search for and what to put in its place
|
|
48
|
+
* @returns The text with the replacements made
|
|
49
|
+
* @group transform
|
|
50
|
+
* @shortname replaceAll
|
|
51
|
+
* @drawable false
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const greeting = bitbybit.text.replaceAll({ text: "hello hello", search: "hello", replaceWith: "hi" });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
43
57
|
replaceAll(inputs) {
|
|
44
58
|
return inputs.text.split(inputs.search).join(inputs.replaceWith);
|
|
45
59
|
}
|
|
46
60
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
* Joins a list of texts into one, with a separator between neighbors.
|
|
62
|
+
*
|
|
63
|
+
* Example: ['apple', 'banana', 'cherry'] joined by ', ' -> 'apple, banana, cherry'
|
|
64
|
+
* @param inputs - The texts and the separator
|
|
65
|
+
* @returns The joined text
|
|
66
|
+
* @group transform
|
|
67
|
+
* @shortname join
|
|
68
|
+
* @drawable false
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const line = bitbybit.text.join({ list: ["apple", "banana"], separator: ", " });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
55
74
|
join(inputs) {
|
|
56
75
|
return inputs.list.join(inputs.separator);
|
|
57
76
|
}
|
|
58
77
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
* Turns any value into text, the way JavaScript prints it.
|
|
79
|
+
*
|
|
80
|
+
* Example: 42 -> '42', [1, 2] -> '1,2'
|
|
81
|
+
* @param inputs - The value
|
|
82
|
+
* @returns The value as text
|
|
83
|
+
* @group transform
|
|
84
|
+
* @shortname to string
|
|
85
|
+
* @drawable false
|
|
86
|
+
*/
|
|
66
87
|
toString(inputs) {
|
|
67
88
|
return inputs.item.toString();
|
|
68
89
|
}
|
|
69
90
|
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
* Turns every item of a list into text, the way JavaScript prints it.
|
|
92
|
+
*
|
|
93
|
+
* Example: [1, 2.5, true] -> ['1', '2.5', 'true']
|
|
94
|
+
* @param inputs - The list of values
|
|
95
|
+
* @returns One text per item, in order
|
|
96
|
+
* @group transform
|
|
97
|
+
* @shortname to strings
|
|
98
|
+
* @drawable false
|
|
99
|
+
*/
|
|
77
100
|
toStringEach(inputs) {
|
|
78
101
|
return inputs.list.map(i => i.toString());
|
|
79
102
|
}
|
|
80
103
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
104
|
+
* Fills numbered placeholders in a text with values: `{0}` takes the first value, `{1}` the
|
|
105
|
+
* second, and so on.
|
|
106
|
+
*
|
|
107
|
+
* A placeholder without a value is left as it is.
|
|
108
|
+
* Example: 'Point: ({0}, {1})' with [10, 5] -> 'Point: (10, 5)'
|
|
109
|
+
* @param inputs - The text with placeholders and the values to fill in
|
|
110
|
+
* @returns The filled-in text
|
|
85
111
|
* @group transform
|
|
86
112
|
* @shortname format
|
|
87
113
|
* @drawable false
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const label = bitbybit.text.format({ text: "Point: ({0}, {1})", values: ["10", "5"] });
|
|
117
|
+
* ```
|
|
88
118
|
*/
|
|
89
119
|
format(inputs) {
|
|
90
120
|
return inputs.text.replace(/{(\d+)}/g, (match, number) => {
|
|
@@ -92,106 +122,151 @@ export class TextBitByBit {
|
|
|
92
122
|
});
|
|
93
123
|
}
|
|
94
124
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
125
|
+
* Tells whether a text contains a search text.
|
|
126
|
+
*
|
|
127
|
+
* Example: 'hello world' includes 'world' -> true
|
|
128
|
+
* @param inputs - The text and what to look for
|
|
129
|
+
* @returns True when the search text occurs in it
|
|
99
130
|
* @group query
|
|
100
131
|
* @shortname includes
|
|
101
132
|
* @drawable false
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const has = bitbybit.text.includes({ text: "hello world", search: "world" });
|
|
136
|
+
* ```
|
|
102
137
|
*/
|
|
103
138
|
includes(inputs) {
|
|
104
139
|
return inputs.text.includes(inputs.search);
|
|
105
140
|
}
|
|
106
141
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* @
|
|
142
|
+
* Tells whether a text begins with a search text.
|
|
143
|
+
*
|
|
144
|
+
* Example: 'hello world' starts with 'hello' -> true
|
|
145
|
+
* @param inputs - The text and what to look for at its start
|
|
146
|
+
* @returns True when the text begins with it
|
|
111
147
|
* @group query
|
|
112
148
|
* @shortname starts with
|
|
113
149
|
* @drawable false
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const starts = bitbybit.text.startsWith({ text: "hello world", search: "hello" });
|
|
153
|
+
* ```
|
|
114
154
|
*/
|
|
115
155
|
startsWith(inputs) {
|
|
116
156
|
return inputs.text.startsWith(inputs.search);
|
|
117
157
|
}
|
|
118
158
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* @
|
|
159
|
+
* Tells whether a text ends with a search text.
|
|
160
|
+
*
|
|
161
|
+
* Example: 'hello world' ends with 'world' -> true
|
|
162
|
+
* @param inputs - The text and what to look for at its end
|
|
163
|
+
* @returns True when the text ends with it
|
|
123
164
|
* @group query
|
|
124
165
|
* @shortname ends with
|
|
125
166
|
* @drawable false
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const ends = bitbybit.text.endsWith({ text: "hello world", search: "world" });
|
|
170
|
+
* ```
|
|
126
171
|
*/
|
|
127
172
|
endsWith(inputs) {
|
|
128
173
|
return inputs.text.endsWith(inputs.search);
|
|
129
174
|
}
|
|
130
175
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
176
|
+
* Finds where a search text first occurs, counting characters from 0, or -1 when it does not
|
|
177
|
+
* occur.
|
|
178
|
+
*
|
|
179
|
+
* Example: 'hello world' finding 'world' -> 6
|
|
180
|
+
* @param inputs - The text and what to look for
|
|
181
|
+
* @returns The position of the first occurrence, or -1
|
|
135
182
|
* @group query
|
|
136
183
|
* @shortname index of
|
|
137
184
|
* @drawable false
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const at = bitbybit.text.indexOf({ text: "hello world", search: "world" });
|
|
188
|
+
* ```
|
|
138
189
|
*/
|
|
139
190
|
indexOf(inputs) {
|
|
140
191
|
return inputs.text.indexOf(inputs.search);
|
|
141
192
|
}
|
|
142
193
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
194
|
+
* Finds where a search text last occurs, counting characters from 0, or -1 when it does not
|
|
195
|
+
* occur.
|
|
196
|
+
*
|
|
197
|
+
* Example: 'hello world hello' finding 'hello' -> 12
|
|
198
|
+
* @param inputs - The text and what to look for
|
|
199
|
+
* @returns The position of the last occurrence, or -1
|
|
147
200
|
* @group query
|
|
148
201
|
* @shortname last index of
|
|
149
202
|
* @drawable false
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const at = bitbybit.text.lastIndexOf({ text: "hello world hello", search: "hello" });
|
|
206
|
+
* ```
|
|
150
207
|
*/
|
|
151
208
|
lastIndexOf(inputs) {
|
|
152
209
|
return inputs.text.lastIndexOf(inputs.search);
|
|
153
210
|
}
|
|
154
211
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
212
|
+
* Takes the characters from a start position up to, but not including, an end position.
|
|
213
|
+
*
|
|
214
|
+
* A start larger than the end swaps the two, and negative positions count as 0.
|
|
215
|
+
* Example: 'hello world' from 0 to 5 -> 'hello'
|
|
216
|
+
* @param inputs - The text and the start and end positions
|
|
217
|
+
* @returns The characters in that range
|
|
159
218
|
* @group transform
|
|
160
219
|
* @shortname substring
|
|
161
220
|
* @drawable false
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const word = bitbybit.text.substring({ text: "hello world", start: 0, end: 5 });
|
|
224
|
+
* ```
|
|
162
225
|
*/
|
|
163
226
|
substring(inputs) {
|
|
164
227
|
return inputs.text.substring(inputs.start, inputs.end);
|
|
165
228
|
}
|
|
166
229
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
230
|
+
* Takes the characters from a start position up to, but not including, an end position.
|
|
231
|
+
*
|
|
232
|
+
* Unlike `substring`, a negative position counts from the end of the text.
|
|
233
|
+
* Example: 'hello world' from 0 to 5 -> 'hello'; from -5 -> 'world'
|
|
234
|
+
* @param inputs - The text and the start and end positions
|
|
235
|
+
* @returns The characters in that range
|
|
171
236
|
* @group transform
|
|
172
237
|
* @shortname slice
|
|
173
238
|
* @drawable false
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const tail = bitbybit.text.slice({ text: "hello world", start: 6, end: 11 });
|
|
242
|
+
* ```
|
|
174
243
|
*/
|
|
175
244
|
slice(inputs) {
|
|
176
245
|
return inputs.text.slice(inputs.start, inputs.end);
|
|
177
246
|
}
|
|
178
247
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
* @
|
|
248
|
+
* Reads the character at a position, counting from 0.
|
|
249
|
+
*
|
|
250
|
+
* Example: 'hello' at 1 -> 'e'
|
|
251
|
+
* @param inputs - The text and the position
|
|
252
|
+
* @returns The character, or an empty text when the position is outside the text
|
|
183
253
|
* @group query
|
|
184
254
|
* @shortname char at
|
|
185
255
|
* @drawable false
|
|
256
|
+
* @example
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const second = bitbybit.text.charAt({ text: "hello", index: 1 });
|
|
259
|
+
* ```
|
|
186
260
|
*/
|
|
187
261
|
charAt(inputs) {
|
|
188
262
|
return inputs.text.charAt(inputs.index);
|
|
189
263
|
}
|
|
190
264
|
/**
|
|
191
|
-
* Removes
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* @
|
|
265
|
+
* Removes spaces, tabs and line breaks from both ends of a text.
|
|
266
|
+
*
|
|
267
|
+
* Example: ' hello ' -> 'hello'
|
|
268
|
+
* @param inputs - The text
|
|
269
|
+
* @returns The trimmed text
|
|
195
270
|
* @group transform
|
|
196
271
|
* @shortname trim
|
|
197
272
|
* @drawable false
|
|
@@ -200,10 +275,11 @@ export class TextBitByBit {
|
|
|
200
275
|
return inputs.text.trim();
|
|
201
276
|
}
|
|
202
277
|
/**
|
|
203
|
-
* Removes
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* @
|
|
278
|
+
* Removes spaces, tabs and line breaks from the start of a text.
|
|
279
|
+
*
|
|
280
|
+
* Example: ' hello ' -> 'hello '
|
|
281
|
+
* @param inputs - The text
|
|
282
|
+
* @returns The text without leading whitespace
|
|
207
283
|
* @group transform
|
|
208
284
|
* @shortname trim start
|
|
209
285
|
* @drawable false
|
|
@@ -212,10 +288,11 @@ export class TextBitByBit {
|
|
|
212
288
|
return inputs.text.trimStart();
|
|
213
289
|
}
|
|
214
290
|
/**
|
|
215
|
-
* Removes
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* @
|
|
291
|
+
* Removes spaces, tabs and line breaks from the end of a text.
|
|
292
|
+
*
|
|
293
|
+
* Example: ' hello ' -> ' hello'
|
|
294
|
+
* @param inputs - The text
|
|
295
|
+
* @returns The text without trailing whitespace
|
|
219
296
|
* @group transform
|
|
220
297
|
* @shortname trim end
|
|
221
298
|
* @drawable false
|
|
@@ -224,34 +301,47 @@ export class TextBitByBit {
|
|
|
224
301
|
return inputs.text.trimEnd();
|
|
225
302
|
}
|
|
226
303
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
304
|
+
* Adds a filler text in front until the text reaches a length; a text already that long is left
|
|
305
|
+
* alone.
|
|
306
|
+
*
|
|
307
|
+
* Example: 'x' to length 3 with 'a' -> 'aax'
|
|
308
|
+
* @param inputs - The text, the length to reach and the filler
|
|
309
|
+
* @returns The padded text
|
|
231
310
|
* @group transform
|
|
232
311
|
* @shortname pad start
|
|
233
312
|
* @drawable false
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* const padded = bitbybit.text.padStart({ text: "7", length: 3, padString: "0" });
|
|
316
|
+
* ```
|
|
234
317
|
*/
|
|
235
318
|
padStart(inputs) {
|
|
236
319
|
return inputs.text.padStart(inputs.length, inputs.padString);
|
|
237
320
|
}
|
|
238
321
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
322
|
+
* Adds a filler text behind until the text reaches a length; a text already that long is left
|
|
323
|
+
* alone.
|
|
324
|
+
*
|
|
325
|
+
* Example: 'x' to length 3 with 'a' -> 'xaa'
|
|
326
|
+
* @param inputs - The text, the length to reach and the filler
|
|
327
|
+
* @returns The padded text
|
|
243
328
|
* @group transform
|
|
244
329
|
* @shortname pad end
|
|
245
330
|
* @drawable false
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const padded = bitbybit.text.padEnd({ text: "x", length: 3, padString: "a" });
|
|
334
|
+
* ```
|
|
246
335
|
*/
|
|
247
336
|
padEnd(inputs) {
|
|
248
337
|
return inputs.text.padEnd(inputs.length, inputs.padString);
|
|
249
338
|
}
|
|
250
339
|
/**
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* @
|
|
340
|
+
* Turns every letter into a capital.
|
|
341
|
+
*
|
|
342
|
+
* Example: 'hello' -> 'HELLO'
|
|
343
|
+
* @param inputs - The text
|
|
344
|
+
* @returns The text in capitals
|
|
255
345
|
* @group transform
|
|
256
346
|
* @shortname to upper case
|
|
257
347
|
* @drawable false
|
|
@@ -260,10 +350,11 @@ export class TextBitByBit {
|
|
|
260
350
|
return inputs.text.toUpperCase();
|
|
261
351
|
}
|
|
262
352
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* @
|
|
353
|
+
* Turns every letter into lower case.
|
|
354
|
+
*
|
|
355
|
+
* Example: 'HELLO' -> 'hello'
|
|
356
|
+
* @param inputs - The text
|
|
357
|
+
* @returns The text in lower case
|
|
267
358
|
* @group transform
|
|
268
359
|
* @shortname to lower case
|
|
269
360
|
* @drawable false
|
|
@@ -272,10 +363,11 @@ export class TextBitByBit {
|
|
|
272
363
|
return inputs.text.toLowerCase();
|
|
273
364
|
}
|
|
274
365
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
* @
|
|
366
|
+
* Turns the first character into a capital and leaves the rest as it is.
|
|
367
|
+
*
|
|
368
|
+
* Example: 'hello world' -> 'Hello world'
|
|
369
|
+
* @param inputs - The text
|
|
370
|
+
* @returns The text with its first character capitalized
|
|
279
371
|
* @group transform
|
|
280
372
|
* @shortname capitalize first
|
|
281
373
|
* @drawable false
|
|
@@ -286,10 +378,11 @@ export class TextBitByBit {
|
|
|
286
378
|
return inputs.text.charAt(0).toUpperCase() + inputs.text.slice(1);
|
|
287
379
|
}
|
|
288
380
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* @
|
|
381
|
+
* Turns the first character into lower case and leaves the rest as it is.
|
|
382
|
+
*
|
|
383
|
+
* Example: 'Hello World' -> 'hello World'
|
|
384
|
+
* @param inputs - The text
|
|
385
|
+
* @returns The text with its first character in lower case
|
|
293
386
|
* @group transform
|
|
294
387
|
* @shortname uncapitalize first
|
|
295
388
|
* @drawable false
|
|
@@ -300,22 +393,28 @@ export class TextBitByBit {
|
|
|
300
393
|
return inputs.text.charAt(0).toLowerCase() + inputs.text.slice(1);
|
|
301
394
|
}
|
|
302
395
|
/**
|
|
303
|
-
* Repeats text a
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* @
|
|
396
|
+
* Repeats a text a number of times, end to end.
|
|
397
|
+
*
|
|
398
|
+
* Example: 'ha' three times -> 'hahaha'
|
|
399
|
+
* @param inputs - The text and how many times to repeat it
|
|
400
|
+
* @returns The repeated text
|
|
307
401
|
* @group transform
|
|
308
402
|
* @shortname repeat
|
|
309
403
|
* @drawable false
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const laugh = bitbybit.text.repeat({ text: "ha", count: 3 });
|
|
407
|
+
* ```
|
|
310
408
|
*/
|
|
311
409
|
repeat(inputs) {
|
|
312
410
|
return inputs.text.repeat(inputs.count);
|
|
313
411
|
}
|
|
314
412
|
/**
|
|
315
|
-
* Reverses the
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* @
|
|
413
|
+
* Reverses the order of the characters.
|
|
414
|
+
*
|
|
415
|
+
* Example: 'hello' -> 'olleh'
|
|
416
|
+
* @param inputs - The text
|
|
417
|
+
* @returns The reversed text
|
|
319
418
|
* @group transform
|
|
320
419
|
* @shortname reverse
|
|
321
420
|
* @drawable false
|
|
@@ -324,10 +423,11 @@ export class TextBitByBit {
|
|
|
324
423
|
return inputs.text.split("").reverse().join("");
|
|
325
424
|
}
|
|
326
425
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* @
|
|
426
|
+
* Counts the characters in a text.
|
|
427
|
+
*
|
|
428
|
+
* Example: 'hello' -> 5
|
|
429
|
+
* @param inputs - The text
|
|
430
|
+
* @returns The number of characters
|
|
331
431
|
* @group query
|
|
332
432
|
* @shortname length
|
|
333
433
|
* @drawable false
|
|
@@ -336,10 +436,11 @@ export class TextBitByBit {
|
|
|
336
436
|
return inputs.text.length;
|
|
337
437
|
}
|
|
338
438
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* @
|
|
439
|
+
* Tells whether a text is empty or holds only whitespace.
|
|
440
|
+
*
|
|
441
|
+
* Example: ' ' -> true, 'a' -> false
|
|
442
|
+
* @param inputs - The text
|
|
443
|
+
* @returns True when there is nothing but whitespace
|
|
343
444
|
* @group query
|
|
344
445
|
* @shortname is empty
|
|
345
446
|
* @drawable false
|
|
@@ -348,38 +449,55 @@ export class TextBitByBit {
|
|
|
348
449
|
return !inputs.text || inputs.text.trim().length === 0;
|
|
349
450
|
}
|
|
350
451
|
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @
|
|
452
|
+
* Joins several texts into one with nothing between them.
|
|
453
|
+
*
|
|
454
|
+
* Example: ['hello', ' ', 'world'] -> 'hello world'
|
|
455
|
+
* @param inputs - The texts to join
|
|
456
|
+
* @returns The joined text
|
|
355
457
|
* @group transform
|
|
356
458
|
* @shortname concat
|
|
357
459
|
* @drawable false
|
|
460
|
+
* @example
|
|
461
|
+
* ```typescript
|
|
462
|
+
* const sentence = bitbybit.text.concat({ texts: ["hello", " ", "world"] });
|
|
463
|
+
* ```
|
|
358
464
|
*/
|
|
359
465
|
concat(inputs) {
|
|
360
466
|
return inputs.texts.join("");
|
|
361
467
|
}
|
|
362
468
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* @
|
|
469
|
+
* Tells whether a regular expression matches somewhere in a text.
|
|
470
|
+
*
|
|
471
|
+
* Example: 'hello123' against '[0-9]+' -> true
|
|
472
|
+
* @param inputs - The text, the pattern and the flags
|
|
473
|
+
* @returns True when the pattern matches
|
|
367
474
|
* @group regex
|
|
368
475
|
* @shortname test regex
|
|
369
476
|
* @drawable false
|
|
477
|
+
* @example
|
|
478
|
+
* ```typescript
|
|
479
|
+
* const hasDigits = bitbybit.text.regexTest({ text: "hello123", pattern: "[0-9]+", flags: "" });
|
|
480
|
+
* ```
|
|
370
481
|
*/
|
|
371
482
|
regexTest(inputs) {
|
|
372
483
|
const regex = new RegExp(inputs.pattern, inputs.flags);
|
|
373
484
|
return regex.test(inputs.text);
|
|
374
485
|
}
|
|
375
486
|
/**
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
487
|
+
* Finds the parts of a text that a regular expression matches.
|
|
488
|
+
*
|
|
489
|
+
* With the `g` flag every match is listed; without it only the first match and its capture
|
|
490
|
+
* groups. No match gives null.
|
|
491
|
+
* Example: 'hello123world456' against '[0-9]+' with 'g' -> ['123', '456']
|
|
492
|
+
* @param inputs - The text, the pattern and the flags
|
|
493
|
+
* @returns The matches, or null when there are none
|
|
380
494
|
* @group regex
|
|
381
495
|
* @shortname regex match
|
|
382
496
|
* @drawable false
|
|
497
|
+
* @example
|
|
498
|
+
* ```typescript
|
|
499
|
+
* const numbers = bitbybit.text.regexMatch({ text: "hello123world456", pattern: "[0-9]+", flags: "g" });
|
|
500
|
+
* ```
|
|
383
501
|
*/
|
|
384
502
|
regexMatch(inputs) {
|
|
385
503
|
const regex = new RegExp(inputs.pattern, inputs.flags);
|
|
@@ -387,53 +505,78 @@ export class TextBitByBit {
|
|
|
387
505
|
return result ? Array.from(result) : null;
|
|
388
506
|
}
|
|
389
507
|
/**
|
|
390
|
-
* Replaces
|
|
391
|
-
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
508
|
+
* Replaces what a regular expression matches with another text.
|
|
509
|
+
*
|
|
510
|
+
* With the `g` flag every match is replaced; without it only the first.
|
|
511
|
+
* Example: 'hello123world456' against '[0-9]+' with 'g', replaced by 'X' -> 'helloXworldX'
|
|
512
|
+
* @param inputs - The text, the pattern, the flags and the replacement
|
|
513
|
+
* @returns The text with the replacements made
|
|
394
514
|
* @group regex
|
|
395
515
|
* @shortname regex replace
|
|
396
516
|
* @drawable false
|
|
517
|
+
* @example
|
|
518
|
+
* ```typescript
|
|
519
|
+
* const clean = bitbybit.text.regexReplace({ text: "hello123world456", pattern: "[0-9]+", flags: "g", replaceWith: "X" });
|
|
520
|
+
* ```
|
|
397
521
|
*/
|
|
398
522
|
regexReplace(inputs) {
|
|
399
523
|
const regex = new RegExp(inputs.pattern, inputs.flags);
|
|
400
524
|
return inputs.text.replace(regex, inputs.replaceWith);
|
|
401
525
|
}
|
|
402
526
|
/**
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
527
|
+
* Finds where a regular expression first matches, counting characters from 0, or -1 when it
|
|
528
|
+
* does not match.
|
|
529
|
+
*
|
|
530
|
+
* Example: 'hello123' against '[0-9]+' -> 5
|
|
531
|
+
* @param inputs - The text, the pattern and the flags
|
|
532
|
+
* @returns The position of the first match, or -1
|
|
407
533
|
* @group regex
|
|
408
534
|
* @shortname regex search
|
|
409
535
|
* @drawable false
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const at = bitbybit.text.regexSearch({ text: "hello123", pattern: "[0-9]+", flags: "" });
|
|
539
|
+
* ```
|
|
410
540
|
*/
|
|
411
541
|
regexSearch(inputs) {
|
|
412
542
|
const regex = new RegExp(inputs.pattern, inputs.flags);
|
|
413
543
|
return inputs.text.search(regex);
|
|
414
544
|
}
|
|
415
545
|
/**
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
546
|
+
* Cuts a text into pieces wherever a regular expression matches; the matches themselves are
|
|
547
|
+
* dropped.
|
|
548
|
+
*
|
|
549
|
+
* Example: 'a1b2c3' split by '[0-9]+' -> ['a', 'b', 'c', '']
|
|
550
|
+
* @param inputs - The text, the pattern and the flags
|
|
551
|
+
* @returns The pieces, in order
|
|
420
552
|
* @group regex
|
|
421
553
|
* @shortname regex split
|
|
422
554
|
* @drawable false
|
|
555
|
+
* @example
|
|
556
|
+
* ```typescript
|
|
557
|
+
* const letters = bitbybit.text.regexSplit({ text: "a1b2c3", pattern: "[0-9]+", flags: "" });
|
|
558
|
+
* ```
|
|
423
559
|
*/
|
|
424
560
|
regexSplit(inputs) {
|
|
425
561
|
const regex = new RegExp(inputs.pattern, inputs.flags);
|
|
426
562
|
return inputs.text.split(regex);
|
|
427
563
|
}
|
|
428
564
|
/**
|
|
429
|
-
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
565
|
+
* Draws one character as line paths with a simple stroke font.
|
|
566
|
+
*
|
|
567
|
+
* The paths lie flat on the XZ plane, scaled so the character is `height` tall, and are
|
|
568
|
+
* returned with the character's width and height. An unknown character is drawn as a question
|
|
569
|
+
* mark.
|
|
570
|
+
* Example: 'A' at height 10 -> the strokes of an A, 10 units tall
|
|
571
|
+
* @param inputs - The character, its height and its offsets
|
|
572
|
+
* @returns The character's width, height and stroke paths as lists of points
|
|
434
573
|
* @group vector
|
|
435
574
|
* @shortname vector char
|
|
436
575
|
* @drawable false
|
|
576
|
+
* @example
|
|
577
|
+
* ```typescript
|
|
578
|
+
* const letter = bitbybit.text.vectorChar({ char: "A", height: 10, xOffset: 0, yOffset: 0, extrudeOffset: 0 });
|
|
579
|
+
* ```
|
|
437
580
|
*/
|
|
438
581
|
vectorChar(inputs) {
|
|
439
582
|
const { xOffset, yOffset, font, input, height, extrudeOffset } = this.vectorParamsChar(inputs);
|
|
@@ -464,14 +607,26 @@ export class TextBitByBit {
|
|
|
464
607
|
return { width, height, paths };
|
|
465
608
|
}
|
|
466
609
|
/**
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
610
|
+
* Draws a text, with line breaks, as line paths with a simple stroke font.
|
|
611
|
+
*
|
|
612
|
+
* Each line comes back as its characters with their paths, laid out flat on the XZ plane with
|
|
613
|
+
* the given height, spacing and alignment; `centerOnOrigin` puts the middle of the block at the
|
|
614
|
+
* origin.
|
|
615
|
+
* Example: 'Hello' at height 10 -> five characters with their strokes
|
|
616
|
+
* @param inputs - The text and how to lay it out
|
|
617
|
+
* @returns One entry per line, each with its characters and their stroke paths
|
|
472
618
|
* @group vector
|
|
473
619
|
* @shortname vector text
|
|
474
620
|
* @drawable false
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* const lines = bitbybit.text.vectorText({
|
|
624
|
+
* text: "Hello\nWorld",
|
|
625
|
+
* height: 10,
|
|
626
|
+
* align: Bit.Inputs.Base.horizontalAlignEnum.center,
|
|
627
|
+
* centerOnOrigin: true,
|
|
628
|
+
* });
|
|
629
|
+
* ```
|
|
475
630
|
*/
|
|
476
631
|
vectorText(inputs) {
|
|
477
632
|
const { xOffset, yOffset, height, align, extrudeOffset, lineSpacing, letterSpacing } = Object.assign({}, defaultsVectorParams, inputs);
|