@hotmeshio/hotmesh 0.14.0 → 0.14.2
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/build/package.json +1 -1
- package/build/services/pipe/functions/array.d.ts +219 -0
- package/build/services/pipe/functions/array.js +219 -0
- package/build/services/pipe/functions/bitwise.d.ts +94 -0
- package/build/services/pipe/functions/bitwise.js +94 -0
- package/build/services/pipe/functions/conditional.d.ts +161 -0
- package/build/services/pipe/functions/conditional.js +161 -0
- package/build/services/pipe/functions/cron.d.ts +23 -4
- package/build/services/pipe/functions/cron.js +23 -4
- package/build/services/pipe/functions/date.d.ts +737 -6
- package/build/services/pipe/functions/date.js +742 -5
- package/build/services/pipe/functions/json.d.ts +42 -0
- package/build/services/pipe/functions/json.js +42 -0
- package/build/services/pipe/functions/logical.d.ts +38 -0
- package/build/services/pipe/functions/logical.js +38 -0
- package/build/services/pipe/functions/math.d.ts +533 -0
- package/build/services/pipe/functions/math.js +533 -0
- package/build/services/pipe/functions/number.d.ts +258 -0
- package/build/services/pipe/functions/number.js +258 -0
- package/build/services/pipe/functions/object.d.ts +321 -0
- package/build/services/pipe/functions/object.js +321 -0
- package/build/services/pipe/functions/string.d.ts +306 -0
- package/build/services/pipe/functions/string.js +306 -0
- package/build/services/pipe/functions/symbol.d.ts +112 -0
- package/build/services/pipe/functions/symbol.js +112 -0
- package/build/services/pipe/functions/unary.d.ts +65 -0
- package/build/services/pipe/functions/unary.js +65 -0
- package/build/services/router/error-handling/index.js +7 -1
- package/build/services/virtual/index.js +6 -0
- package/build/services/virtual/schemas/factory.js +1 -1
- package/build/types/virtual.d.ts +21 -0
- package/package.json +1 -1
|
@@ -1,23 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provides string manipulation functions for use in HotMesh mapping rules.
|
|
3
|
+
* Although inspired by JavaScript's String API, these methods follow a
|
|
4
|
+
* functional approach where each transformation expects one or more input
|
|
5
|
+
* parameters from the prior row in the `@pipe` structure.
|
|
6
|
+
*
|
|
7
|
+
* @remarks Methods are invoked with the syntax `{@string.<method>}`, e.g., `{@string.trim}` or `{@string.toUpperCase}`.
|
|
8
|
+
*/
|
|
1
9
|
declare class StringHandler {
|
|
10
|
+
/**
|
|
11
|
+
* Splits a string into an array of substrings based on a specified
|
|
12
|
+
* delimiter.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} input - The string to split.
|
|
15
|
+
* @param {string} delimiter - The delimiter to split on.
|
|
16
|
+
* @returns {string[]} An array of substrings.
|
|
17
|
+
* @example
|
|
18
|
+
* ```yaml
|
|
19
|
+
* words:
|
|
20
|
+
* "@pipe":
|
|
21
|
+
* - ["{a.output.data.sentence}", " "]
|
|
22
|
+
* - ["{@string.split}"]
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
2
25
|
split(input: string, delimiter: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the character at a specified index in a string.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} input - The string to retrieve the character from.
|
|
30
|
+
* @param {number} index - The zero-based index of the character.
|
|
31
|
+
* @returns {string} The character at the specified index.
|
|
32
|
+
* @example
|
|
33
|
+
* ```yaml
|
|
34
|
+
* first_letter:
|
|
35
|
+
* "@pipe":
|
|
36
|
+
* - ["{a.output.data.word}", 0]
|
|
37
|
+
* - ["{@string.charAt}"]
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
3
40
|
charAt(input: string, index: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Concatenates two or more strings into a single string.
|
|
43
|
+
*
|
|
44
|
+
* @param {...string[]} strings - The strings to concatenate.
|
|
45
|
+
* @returns {string} The concatenated result.
|
|
46
|
+
* @example
|
|
47
|
+
* ```yaml
|
|
48
|
+
* full_name:
|
|
49
|
+
* "@pipe":
|
|
50
|
+
* - ["{a.output.data.first_name}", " ", "{a.output.data.last_name}"]
|
|
51
|
+
* - ["{@string.concat}"]
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
4
54
|
concat(...strings: string[]): string;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a string contains a specified substring, optionally starting
|
|
57
|
+
* the search at a given position.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} input - The string to search within.
|
|
60
|
+
* @param {string} searchString - The substring to search for.
|
|
61
|
+
* @param {number} [position] - Optional position to start searching from.
|
|
62
|
+
* @returns {boolean} `true` if the substring is found, `false` otherwise.
|
|
63
|
+
* @example
|
|
64
|
+
* ```yaml
|
|
65
|
+
* contains_fox:
|
|
66
|
+
* "@pipe":
|
|
67
|
+
* - ["{a.output.data.sentence}", "fox"]
|
|
68
|
+
* - ["{@string.includes}"]
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
5
71
|
includes(input: string, searchString: string, position?: number): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the index of the first occurrence of a specified substring in a
|
|
74
|
+
* string, or -1 if not found.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} input - The string to search within.
|
|
77
|
+
* @param {string} searchString - The substring to search for.
|
|
78
|
+
* @param {number} [fromIndex] - Optional index to start searching from.
|
|
79
|
+
* @returns {number} The index of the first occurrence, or -1.
|
|
80
|
+
* @example
|
|
81
|
+
* ```yaml
|
|
82
|
+
* fox_index:
|
|
83
|
+
* "@pipe":
|
|
84
|
+
* - ["{a.output.data.sentence}", "fox"]
|
|
85
|
+
* - ["{@string.indexOf}"]
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
6
88
|
indexOf(input: string, searchString: string, fromIndex?: number): number;
|
|
89
|
+
/**
|
|
90
|
+
* Returns the index of the last occurrence of a specified substring in a
|
|
91
|
+
* string, or -1 if not found.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} input - The string to search within.
|
|
94
|
+
* @param {string} searchString - The substring to search for.
|
|
95
|
+
* @param {number} [fromIndex] - Optional index to start searching backward from.
|
|
96
|
+
* @returns {number} The index of the last occurrence, or -1.
|
|
97
|
+
* @example
|
|
98
|
+
* ```yaml
|
|
99
|
+
* last_quick_index:
|
|
100
|
+
* "@pipe":
|
|
101
|
+
* - ["{a.output.data.sentence}", "quick"]
|
|
102
|
+
* - ["{@string.lastIndexOf}"]
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
7
105
|
lastIndexOf(input: string, searchString: string, fromIndex?: number): number;
|
|
106
|
+
/**
|
|
107
|
+
* Extracts a section of a string and returns it as a new string, without
|
|
108
|
+
* modifying the original.
|
|
109
|
+
*
|
|
110
|
+
* @param {string} input - The string to extract from.
|
|
111
|
+
* @param {number} [start] - The zero-based start index (inclusive).
|
|
112
|
+
* @param {number} [end] - The zero-based end index (exclusive).
|
|
113
|
+
* @returns {string} The extracted substring.
|
|
114
|
+
* @example
|
|
115
|
+
* ```yaml
|
|
116
|
+
* substring:
|
|
117
|
+
* "@pipe":
|
|
118
|
+
* - ["{a.output.data.sentence}", 4, 9]
|
|
119
|
+
* - ["{@string.slice}"]
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
8
122
|
slice(input: string, start?: number, end?: number): string;
|
|
123
|
+
/**
|
|
124
|
+
* Converts all characters in a string to lowercase.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} input - The string to convert.
|
|
127
|
+
* @returns {string} The lowercase string.
|
|
128
|
+
* @example
|
|
129
|
+
* ```yaml
|
|
130
|
+
* lowercase_sentence:
|
|
131
|
+
* "@pipe":
|
|
132
|
+
* - ["{a.output.data.sentence}"]
|
|
133
|
+
* - ["{@string.toLowerCase}"]
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
9
136
|
toLowerCase(input: string): string;
|
|
137
|
+
/**
|
|
138
|
+
* Converts all characters in a string to uppercase.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} input - The string to convert.
|
|
141
|
+
* @returns {string} The uppercase string.
|
|
142
|
+
* @example
|
|
143
|
+
* ```yaml
|
|
144
|
+
* uppercase_sentence:
|
|
145
|
+
* "@pipe":
|
|
146
|
+
* - ["{a.output.data.sentence}"]
|
|
147
|
+
* - ["{@string.toUpperCase}"]
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
10
150
|
toUpperCase(input: string): string;
|
|
151
|
+
/**
|
|
152
|
+
* Removes whitespace from both ends of a string.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} input - The string to trim.
|
|
155
|
+
* @returns {string} The trimmed string.
|
|
156
|
+
* @example
|
|
157
|
+
* ```yaml
|
|
158
|
+
* trimmed_text:
|
|
159
|
+
* "@pipe":
|
|
160
|
+
* - ["{a.output.data.text}"]
|
|
161
|
+
* - ["{@string.trim}"]
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
11
164
|
trim(input: string): string;
|
|
165
|
+
/**
|
|
166
|
+
* Removes whitespace from the beginning of a string.
|
|
167
|
+
*
|
|
168
|
+
* @param {string} input - The string to trim.
|
|
169
|
+
* @returns {string} The string with leading whitespace removed.
|
|
170
|
+
* @example
|
|
171
|
+
* ```yaml
|
|
172
|
+
* trimmed_start_text:
|
|
173
|
+
* "@pipe":
|
|
174
|
+
* - ["{a.output.data.text}"]
|
|
175
|
+
* - ["{@string.trimStart}"]
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
12
178
|
trimStart(input: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Removes whitespace from the end of a string.
|
|
181
|
+
*
|
|
182
|
+
* @param {string} input - The string to trim.
|
|
183
|
+
* @returns {string} The string with trailing whitespace removed.
|
|
184
|
+
* @example
|
|
185
|
+
* ```yaml
|
|
186
|
+
* trimmed_end_text:
|
|
187
|
+
* "@pipe":
|
|
188
|
+
* - ["{a.output.data.text}"]
|
|
189
|
+
* - ["{@string.trimEnd}"]
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
13
192
|
trimEnd(input: string): string;
|
|
193
|
+
/**
|
|
194
|
+
* Pads the start of a string with a given pad string (repeated if needed)
|
|
195
|
+
* until the resulting string reaches the specified maximum length.
|
|
196
|
+
*
|
|
197
|
+
* @param {string} input - The string to pad.
|
|
198
|
+
* @param {number} maxLength - The target length of the resulting string.
|
|
199
|
+
* @param {string} [padString] - The string to pad with (defaults to spaces).
|
|
200
|
+
* @returns {string} The padded string.
|
|
201
|
+
* @example
|
|
202
|
+
* ```yaml
|
|
203
|
+
* padded:
|
|
204
|
+
* "@pipe":
|
|
205
|
+
* - ["{a.output.data.value}", 5, "0"]
|
|
206
|
+
* - ["{@string.padStart}"]
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
14
209
|
padStart(input: string, maxLength: number, padString?: string): string;
|
|
210
|
+
/**
|
|
211
|
+
* Pads the end of a string with a given pad string (repeated if needed)
|
|
212
|
+
* until the resulting string reaches the specified maximum length.
|
|
213
|
+
*
|
|
214
|
+
* @param {string} input - The string to pad.
|
|
215
|
+
* @param {number} maxLength - The target length of the resulting string.
|
|
216
|
+
* @param {string} [padString] - The string to pad with (defaults to spaces).
|
|
217
|
+
* @returns {string} The padded string.
|
|
218
|
+
* @example
|
|
219
|
+
* ```yaml
|
|
220
|
+
* padded:
|
|
221
|
+
* "@pipe":
|
|
222
|
+
* - ["{a.output.data.value}", 10, "."]
|
|
223
|
+
* - ["{@string.padEnd}"]
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
15
226
|
padEnd(input: string, maxLength: number, padString?: string): string;
|
|
227
|
+
/**
|
|
228
|
+
* Replaces the first occurrence of a search value (string or RegExp) in a
|
|
229
|
+
* string with a replacement string.
|
|
230
|
+
*
|
|
231
|
+
* @param {string} input - The string to search within.
|
|
232
|
+
* @param {string | RegExp} searchValue - The value to search for.
|
|
233
|
+
* @param {string} replaceValue - The replacement string.
|
|
234
|
+
* @returns {string} The string with the first match replaced.
|
|
235
|
+
* @example
|
|
236
|
+
* ```yaml
|
|
237
|
+
* replaced:
|
|
238
|
+
* "@pipe":
|
|
239
|
+
* - ["{a.output.data.text}", "old", "new"]
|
|
240
|
+
* - ["{@string.replace}"]
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
16
243
|
replace(input: string, searchValue: string | RegExp, replaceValue: string): string;
|
|
244
|
+
/**
|
|
245
|
+
* Searches a string for a match against a regular expression and returns
|
|
246
|
+
* the index of the first match, or -1 if no match is found.
|
|
247
|
+
*
|
|
248
|
+
* @param {string} input - The string to search within.
|
|
249
|
+
* @param {RegExp} regexp - The regular expression to search for.
|
|
250
|
+
* @returns {number} The index of the first match, or -1.
|
|
251
|
+
* @example
|
|
252
|
+
* ```yaml
|
|
253
|
+
* match_index:
|
|
254
|
+
* "@pipe":
|
|
255
|
+
* - ["{a.output.data.text}", "/\\d+/"]
|
|
256
|
+
* - ["{@string.search}"]
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
17
259
|
search(input: string, regexp: RegExp): number;
|
|
260
|
+
/**
|
|
261
|
+
* Returns a portion of a string between the specified start and end
|
|
262
|
+
* indices. Unlike `slice`, negative indices are treated as 0 and arguments
|
|
263
|
+
* are swapped if start is greater than end.
|
|
264
|
+
*
|
|
265
|
+
* @param {string} input - The string to extract from.
|
|
266
|
+
* @param {number} start - The start index (inclusive).
|
|
267
|
+
* @param {number} [end] - The end index (exclusive).
|
|
268
|
+
* @returns {string} The extracted substring.
|
|
269
|
+
* @example
|
|
270
|
+
* ```yaml
|
|
271
|
+
* substring:
|
|
272
|
+
* "@pipe":
|
|
273
|
+
* - ["{a.output.data.sentence}", 4, 9]
|
|
274
|
+
* - ["{@string.substring}"]
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
18
277
|
substring(input: string, start: number, end?: number): string;
|
|
278
|
+
/**
|
|
279
|
+
* Determines whether a string begins with the characters of a specified
|
|
280
|
+
* string, optionally starting the check at a given position.
|
|
281
|
+
*
|
|
282
|
+
* @param {string} str - The string to check.
|
|
283
|
+
* @param {string} searchString - The characters to search for at the start.
|
|
284
|
+
* @param {number} [position] - Optional position to begin searching from.
|
|
285
|
+
* @returns {boolean} `true` if the string starts with the search string, `false` otherwise.
|
|
286
|
+
* @example
|
|
287
|
+
* ```yaml
|
|
288
|
+
* starts_with_the:
|
|
289
|
+
* "@pipe":
|
|
290
|
+
* - ["{a.output.data.sentence}", "The"]
|
|
291
|
+
* - ["{@string.startsWith}"]
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
19
294
|
startsWith(str: string, searchString: string, position?: number): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Determines whether a string ends with the characters of a specified
|
|
297
|
+
* string, optionally limiting the check to the first N characters.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} str - The string to check.
|
|
300
|
+
* @param {string} searchString - The characters to search for at the end.
|
|
301
|
+
* @param {number} [length] - Optional length of the string to consider.
|
|
302
|
+
* @returns {boolean} `true` if the string ends with the search string, `false` otherwise.
|
|
303
|
+
* @example
|
|
304
|
+
* ```yaml
|
|
305
|
+
* ends_with_dot:
|
|
306
|
+
* "@pipe":
|
|
307
|
+
* - ["{a.output.data.sentence}", "."]
|
|
308
|
+
* - ["{@string.endsWith}"]
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
20
311
|
endsWith(str: string, searchString: string, length?: number): boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Creates a new string by repeating the given string a specified number of
|
|
314
|
+
* times. The count must be a non-negative finite number.
|
|
315
|
+
*
|
|
316
|
+
* @param {string} str - The string to repeat.
|
|
317
|
+
* @param {number} count - The number of times to repeat (must be >= 0 and finite).
|
|
318
|
+
* @returns {string} The repeated string.
|
|
319
|
+
* @example
|
|
320
|
+
* ```yaml
|
|
321
|
+
* repeated_text:
|
|
322
|
+
* "@pipe":
|
|
323
|
+
* - ["{a.output.data.text}", 3]
|
|
324
|
+
* - ["{@string.repeat}"]
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
21
327
|
repeat(str: string, count: number): string;
|
|
22
328
|
}
|
|
23
329
|
export { StringHandler };
|
|
@@ -1,64 +1,370 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Provides string manipulation functions for use in HotMesh mapping rules.
|
|
6
|
+
* Although inspired by JavaScript's String API, these methods follow a
|
|
7
|
+
* functional approach where each transformation expects one or more input
|
|
8
|
+
* parameters from the prior row in the `@pipe` structure.
|
|
9
|
+
*
|
|
10
|
+
* @remarks Methods are invoked with the syntax `{@string.<method>}`, e.g., `{@string.trim}` or `{@string.toUpperCase}`.
|
|
11
|
+
*/
|
|
4
12
|
class StringHandler {
|
|
13
|
+
/**
|
|
14
|
+
* Splits a string into an array of substrings based on a specified
|
|
15
|
+
* delimiter.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} input - The string to split.
|
|
18
|
+
* @param {string} delimiter - The delimiter to split on.
|
|
19
|
+
* @returns {string[]} An array of substrings.
|
|
20
|
+
* @example
|
|
21
|
+
* ```yaml
|
|
22
|
+
* words:
|
|
23
|
+
* "@pipe":
|
|
24
|
+
* - ["{a.output.data.sentence}", " "]
|
|
25
|
+
* - ["{@string.split}"]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
5
28
|
split(input, delimiter) {
|
|
6
29
|
return input.split(delimiter);
|
|
7
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the character at a specified index in a string.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} input - The string to retrieve the character from.
|
|
35
|
+
* @param {number} index - The zero-based index of the character.
|
|
36
|
+
* @returns {string} The character at the specified index.
|
|
37
|
+
* @example
|
|
38
|
+
* ```yaml
|
|
39
|
+
* first_letter:
|
|
40
|
+
* "@pipe":
|
|
41
|
+
* - ["{a.output.data.word}", 0]
|
|
42
|
+
* - ["{@string.charAt}"]
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
8
45
|
charAt(input, index) {
|
|
9
46
|
return input.charAt(index);
|
|
10
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Concatenates two or more strings into a single string.
|
|
50
|
+
*
|
|
51
|
+
* @param {...string[]} strings - The strings to concatenate.
|
|
52
|
+
* @returns {string} The concatenated result.
|
|
53
|
+
* @example
|
|
54
|
+
* ```yaml
|
|
55
|
+
* full_name:
|
|
56
|
+
* "@pipe":
|
|
57
|
+
* - ["{a.output.data.first_name}", " ", "{a.output.data.last_name}"]
|
|
58
|
+
* - ["{@string.concat}"]
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
11
61
|
concat(...strings) {
|
|
12
62
|
return strings.join('');
|
|
13
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Checks if a string contains a specified substring, optionally starting
|
|
66
|
+
* the search at a given position.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} input - The string to search within.
|
|
69
|
+
* @param {string} searchString - The substring to search for.
|
|
70
|
+
* @param {number} [position] - Optional position to start searching from.
|
|
71
|
+
* @returns {boolean} `true` if the substring is found, `false` otherwise.
|
|
72
|
+
* @example
|
|
73
|
+
* ```yaml
|
|
74
|
+
* contains_fox:
|
|
75
|
+
* "@pipe":
|
|
76
|
+
* - ["{a.output.data.sentence}", "fox"]
|
|
77
|
+
* - ["{@string.includes}"]
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
14
80
|
includes(input, searchString, position) {
|
|
15
81
|
return input.includes(searchString, position);
|
|
16
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the index of the first occurrence of a specified substring in a
|
|
85
|
+
* string, or -1 if not found.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} input - The string to search within.
|
|
88
|
+
* @param {string} searchString - The substring to search for.
|
|
89
|
+
* @param {number} [fromIndex] - Optional index to start searching from.
|
|
90
|
+
* @returns {number} The index of the first occurrence, or -1.
|
|
91
|
+
* @example
|
|
92
|
+
* ```yaml
|
|
93
|
+
* fox_index:
|
|
94
|
+
* "@pipe":
|
|
95
|
+
* - ["{a.output.data.sentence}", "fox"]
|
|
96
|
+
* - ["{@string.indexOf}"]
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
17
99
|
indexOf(input, searchString, fromIndex) {
|
|
18
100
|
return input.indexOf(searchString, fromIndex);
|
|
19
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the index of the last occurrence of a specified substring in a
|
|
104
|
+
* string, or -1 if not found.
|
|
105
|
+
*
|
|
106
|
+
* @param {string} input - The string to search within.
|
|
107
|
+
* @param {string} searchString - The substring to search for.
|
|
108
|
+
* @param {number} [fromIndex] - Optional index to start searching backward from.
|
|
109
|
+
* @returns {number} The index of the last occurrence, or -1.
|
|
110
|
+
* @example
|
|
111
|
+
* ```yaml
|
|
112
|
+
* last_quick_index:
|
|
113
|
+
* "@pipe":
|
|
114
|
+
* - ["{a.output.data.sentence}", "quick"]
|
|
115
|
+
* - ["{@string.lastIndexOf}"]
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
20
118
|
lastIndexOf(input, searchString, fromIndex) {
|
|
21
119
|
return input.lastIndexOf(searchString, fromIndex);
|
|
22
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Extracts a section of a string and returns it as a new string, without
|
|
123
|
+
* modifying the original.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} input - The string to extract from.
|
|
126
|
+
* @param {number} [start] - The zero-based start index (inclusive).
|
|
127
|
+
* @param {number} [end] - The zero-based end index (exclusive).
|
|
128
|
+
* @returns {string} The extracted substring.
|
|
129
|
+
* @example
|
|
130
|
+
* ```yaml
|
|
131
|
+
* substring:
|
|
132
|
+
* "@pipe":
|
|
133
|
+
* - ["{a.output.data.sentence}", 4, 9]
|
|
134
|
+
* - ["{@string.slice}"]
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
23
137
|
slice(input, start, end) {
|
|
24
138
|
return input.slice(start, end);
|
|
25
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Converts all characters in a string to lowercase.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} input - The string to convert.
|
|
144
|
+
* @returns {string} The lowercase string.
|
|
145
|
+
* @example
|
|
146
|
+
* ```yaml
|
|
147
|
+
* lowercase_sentence:
|
|
148
|
+
* "@pipe":
|
|
149
|
+
* - ["{a.output.data.sentence}"]
|
|
150
|
+
* - ["{@string.toLowerCase}"]
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
26
153
|
toLowerCase(input) {
|
|
27
154
|
return input.toLowerCase();
|
|
28
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Converts all characters in a string to uppercase.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} input - The string to convert.
|
|
160
|
+
* @returns {string} The uppercase string.
|
|
161
|
+
* @example
|
|
162
|
+
* ```yaml
|
|
163
|
+
* uppercase_sentence:
|
|
164
|
+
* "@pipe":
|
|
165
|
+
* - ["{a.output.data.sentence}"]
|
|
166
|
+
* - ["{@string.toUpperCase}"]
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
29
169
|
toUpperCase(input) {
|
|
30
170
|
return input.toUpperCase();
|
|
31
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Removes whitespace from both ends of a string.
|
|
174
|
+
*
|
|
175
|
+
* @param {string} input - The string to trim.
|
|
176
|
+
* @returns {string} The trimmed string.
|
|
177
|
+
* @example
|
|
178
|
+
* ```yaml
|
|
179
|
+
* trimmed_text:
|
|
180
|
+
* "@pipe":
|
|
181
|
+
* - ["{a.output.data.text}"]
|
|
182
|
+
* - ["{@string.trim}"]
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
32
185
|
trim(input) {
|
|
33
186
|
return input.trim();
|
|
34
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Removes whitespace from the beginning of a string.
|
|
190
|
+
*
|
|
191
|
+
* @param {string} input - The string to trim.
|
|
192
|
+
* @returns {string} The string with leading whitespace removed.
|
|
193
|
+
* @example
|
|
194
|
+
* ```yaml
|
|
195
|
+
* trimmed_start_text:
|
|
196
|
+
* "@pipe":
|
|
197
|
+
* - ["{a.output.data.text}"]
|
|
198
|
+
* - ["{@string.trimStart}"]
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
35
201
|
trimStart(input) {
|
|
36
202
|
return input.trimStart();
|
|
37
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Removes whitespace from the end of a string.
|
|
206
|
+
*
|
|
207
|
+
* @param {string} input - The string to trim.
|
|
208
|
+
* @returns {string} The string with trailing whitespace removed.
|
|
209
|
+
* @example
|
|
210
|
+
* ```yaml
|
|
211
|
+
* trimmed_end_text:
|
|
212
|
+
* "@pipe":
|
|
213
|
+
* - ["{a.output.data.text}"]
|
|
214
|
+
* - ["{@string.trimEnd}"]
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
38
217
|
trimEnd(input) {
|
|
39
218
|
return input.trimEnd();
|
|
40
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Pads the start of a string with a given pad string (repeated if needed)
|
|
222
|
+
* until the resulting string reaches the specified maximum length.
|
|
223
|
+
*
|
|
224
|
+
* @param {string} input - The string to pad.
|
|
225
|
+
* @param {number} maxLength - The target length of the resulting string.
|
|
226
|
+
* @param {string} [padString] - The string to pad with (defaults to spaces).
|
|
227
|
+
* @returns {string} The padded string.
|
|
228
|
+
* @example
|
|
229
|
+
* ```yaml
|
|
230
|
+
* padded:
|
|
231
|
+
* "@pipe":
|
|
232
|
+
* - ["{a.output.data.value}", 5, "0"]
|
|
233
|
+
* - ["{@string.padStart}"]
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
41
236
|
padStart(input, maxLength, padString) {
|
|
42
237
|
return input.padStart(maxLength, padString);
|
|
43
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Pads the end of a string with a given pad string (repeated if needed)
|
|
241
|
+
* until the resulting string reaches the specified maximum length.
|
|
242
|
+
*
|
|
243
|
+
* @param {string} input - The string to pad.
|
|
244
|
+
* @param {number} maxLength - The target length of the resulting string.
|
|
245
|
+
* @param {string} [padString] - The string to pad with (defaults to spaces).
|
|
246
|
+
* @returns {string} The padded string.
|
|
247
|
+
* @example
|
|
248
|
+
* ```yaml
|
|
249
|
+
* padded:
|
|
250
|
+
* "@pipe":
|
|
251
|
+
* - ["{a.output.data.value}", 10, "."]
|
|
252
|
+
* - ["{@string.padEnd}"]
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
44
255
|
padEnd(input, maxLength, padString) {
|
|
45
256
|
return input.padEnd(maxLength, padString);
|
|
46
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Replaces the first occurrence of a search value (string or RegExp) in a
|
|
260
|
+
* string with a replacement string.
|
|
261
|
+
*
|
|
262
|
+
* @param {string} input - The string to search within.
|
|
263
|
+
* @param {string | RegExp} searchValue - The value to search for.
|
|
264
|
+
* @param {string} replaceValue - The replacement string.
|
|
265
|
+
* @returns {string} The string with the first match replaced.
|
|
266
|
+
* @example
|
|
267
|
+
* ```yaml
|
|
268
|
+
* replaced:
|
|
269
|
+
* "@pipe":
|
|
270
|
+
* - ["{a.output.data.text}", "old", "new"]
|
|
271
|
+
* - ["{@string.replace}"]
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
47
274
|
replace(input, searchValue, replaceValue) {
|
|
48
275
|
return input.replace(searchValue, replaceValue);
|
|
49
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Searches a string for a match against a regular expression and returns
|
|
279
|
+
* the index of the first match, or -1 if no match is found.
|
|
280
|
+
*
|
|
281
|
+
* @param {string} input - The string to search within.
|
|
282
|
+
* @param {RegExp} regexp - The regular expression to search for.
|
|
283
|
+
* @returns {number} The index of the first match, or -1.
|
|
284
|
+
* @example
|
|
285
|
+
* ```yaml
|
|
286
|
+
* match_index:
|
|
287
|
+
* "@pipe":
|
|
288
|
+
* - ["{a.output.data.text}", "/\\d+/"]
|
|
289
|
+
* - ["{@string.search}"]
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
50
292
|
search(input, regexp) {
|
|
51
293
|
return input.search(regexp);
|
|
52
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns a portion of a string between the specified start and end
|
|
297
|
+
* indices. Unlike `slice`, negative indices are treated as 0 and arguments
|
|
298
|
+
* are swapped if start is greater than end.
|
|
299
|
+
*
|
|
300
|
+
* @param {string} input - The string to extract from.
|
|
301
|
+
* @param {number} start - The start index (inclusive).
|
|
302
|
+
* @param {number} [end] - The end index (exclusive).
|
|
303
|
+
* @returns {string} The extracted substring.
|
|
304
|
+
* @example
|
|
305
|
+
* ```yaml
|
|
306
|
+
* substring:
|
|
307
|
+
* "@pipe":
|
|
308
|
+
* - ["{a.output.data.sentence}", 4, 9]
|
|
309
|
+
* - ["{@string.substring}"]
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
53
312
|
substring(input, start, end) {
|
|
54
313
|
return input.substring(start, end);
|
|
55
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Determines whether a string begins with the characters of a specified
|
|
317
|
+
* string, optionally starting the check at a given position.
|
|
318
|
+
*
|
|
319
|
+
* @param {string} str - The string to check.
|
|
320
|
+
* @param {string} searchString - The characters to search for at the start.
|
|
321
|
+
* @param {number} [position] - Optional position to begin searching from.
|
|
322
|
+
* @returns {boolean} `true` if the string starts with the search string, `false` otherwise.
|
|
323
|
+
* @example
|
|
324
|
+
* ```yaml
|
|
325
|
+
* starts_with_the:
|
|
326
|
+
* "@pipe":
|
|
327
|
+
* - ["{a.output.data.sentence}", "The"]
|
|
328
|
+
* - ["{@string.startsWith}"]
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
56
331
|
startsWith(str, searchString, position) {
|
|
57
332
|
return str.startsWith(searchString, position);
|
|
58
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Determines whether a string ends with the characters of a specified
|
|
336
|
+
* string, optionally limiting the check to the first N characters.
|
|
337
|
+
*
|
|
338
|
+
* @param {string} str - The string to check.
|
|
339
|
+
* @param {string} searchString - The characters to search for at the end.
|
|
340
|
+
* @param {number} [length] - Optional length of the string to consider.
|
|
341
|
+
* @returns {boolean} `true` if the string ends with the search string, `false` otherwise.
|
|
342
|
+
* @example
|
|
343
|
+
* ```yaml
|
|
344
|
+
* ends_with_dot:
|
|
345
|
+
* "@pipe":
|
|
346
|
+
* - ["{a.output.data.sentence}", "."]
|
|
347
|
+
* - ["{@string.endsWith}"]
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
59
350
|
endsWith(str, searchString, length) {
|
|
60
351
|
return str.endsWith(searchString, length);
|
|
61
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Creates a new string by repeating the given string a specified number of
|
|
355
|
+
* times. The count must be a non-negative finite number.
|
|
356
|
+
*
|
|
357
|
+
* @param {string} str - The string to repeat.
|
|
358
|
+
* @param {number} count - The number of times to repeat (must be >= 0 and finite).
|
|
359
|
+
* @returns {string} The repeated string.
|
|
360
|
+
* @example
|
|
361
|
+
* ```yaml
|
|
362
|
+
* repeated_text:
|
|
363
|
+
* "@pipe":
|
|
364
|
+
* - ["{a.output.data.text}", 3]
|
|
365
|
+
* - ["{@string.repeat}"]
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
62
368
|
repeat(str, count) {
|
|
63
369
|
if (count < 0 || count === Infinity) {
|
|
64
370
|
throw new RangeError('Invalid repeat count. Must be a positive finite number.');
|