@synstack/str 1.1.2 → 1.2.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/README.md +142 -1
- package/dist/str.index.cjs +305 -44
- package/dist/str.index.cjs.map +1 -1
- package/dist/str.index.d.cts +528 -72
- package/dist/str.index.d.ts +528 -72
- package/dist/str.index.js +303 -44
- package/dist/str.index.js.map +1 -1
- package/package.json +6 -6
- package/src/str.chainable.ts +325 -44
- package/src/str.lib.ts +230 -27
package/dist/str.index.d.cts
CHANGED
@@ -8,258 +8,714 @@ type Stringable = {
|
|
8
8
|
toString(): string;
|
9
9
|
};
|
10
10
|
|
11
|
+
/**
|
12
|
+
* A chainable string manipulation class that extends Pipeable
|
13
|
+
* Provides a fluent interface for string operations with full TypeScript support
|
14
|
+
*
|
15
|
+
* @example
|
16
|
+
* ```typescript
|
17
|
+
* import { str } from '@synstack/str'
|
18
|
+
*
|
19
|
+
* // Basic chaining
|
20
|
+
* const result = str('Hello World')
|
21
|
+
* .trim()
|
22
|
+
* .split(' ')
|
23
|
+
* .at(0)
|
24
|
+
* .$
|
25
|
+
*
|
26
|
+
* // Advanced chaining with Pipeable methods
|
27
|
+
* const modified = str('hello-world')
|
28
|
+
* ._((s) => s.camelCase())
|
29
|
+
* ._$((value) => value.toUpperCase())
|
30
|
+
* .$
|
31
|
+
* ```
|
32
|
+
*/
|
11
33
|
declare class Str extends Pipeable<Str, string> {
|
12
34
|
private readonly text;
|
35
|
+
/**
|
36
|
+
* Create a new Str instance
|
37
|
+
* @param text - The input string to wrap
|
38
|
+
* @example
|
39
|
+
* ```typescript
|
40
|
+
* const s = new Str('Hello World')
|
41
|
+
* // or use the convenience function
|
42
|
+
* const s = str('Hello World')
|
43
|
+
* ```
|
44
|
+
*/
|
13
45
|
constructor(text: string);
|
46
|
+
/**
|
47
|
+
* Get the underlying string value
|
48
|
+
* @returns The wrapped string value
|
49
|
+
*/
|
14
50
|
valueOf(): string;
|
51
|
+
/**
|
52
|
+
* Convert the Str instance to a string
|
53
|
+
* @returns The wrapped string value
|
54
|
+
*/
|
15
55
|
toString(): string;
|
56
|
+
/**
|
57
|
+
* Get the current Str instance
|
58
|
+
* @returns The current Str instance
|
59
|
+
* @internal Used by Pipeable
|
60
|
+
*/
|
16
61
|
instanceOf(): Str;
|
17
62
|
/**
|
18
|
-
* Remove empty lines at the start of the text
|
63
|
+
* Remove empty lines at the start of the text
|
64
|
+
* @returns A new Str instance with empty lines removed from the start
|
65
|
+
* @example
|
66
|
+
* ```typescript
|
67
|
+
* str('\n\n Hello').chopEmptyLinesStart().$ // ' Hello'
|
68
|
+
* ```
|
19
69
|
*/
|
20
70
|
chopEmptyLinesStart(): Str;
|
21
71
|
/**
|
22
|
-
* Remove empty lines at the end of the text
|
72
|
+
* Remove empty lines at the end of the text
|
73
|
+
* @returns A new Str instance with empty lines removed from the end
|
74
|
+
* @example
|
75
|
+
* ```typescript
|
76
|
+
* str('Hello\n\n').chopEmptyLinesEnd().$ // 'Hello'
|
77
|
+
* ```
|
23
78
|
*/
|
24
79
|
chopEmptyLinesEnd(): Str;
|
25
80
|
/**
|
26
|
-
* Remove
|
81
|
+
* Remove whitespace from empty lines
|
82
|
+
* @returns A new Str instance with whitespace removed from empty lines
|
83
|
+
* @example
|
84
|
+
* ```typescript
|
85
|
+
* str('Hello\n \nWorld').trimEmptyLines().$ // 'Hello\n\nWorld'
|
86
|
+
* ```
|
27
87
|
*/
|
28
88
|
trimEmptyLines(): Str;
|
29
89
|
/**
|
30
|
-
* Remove
|
90
|
+
* Remove trailing spaces from all lines
|
91
|
+
* @returns A new Str instance with trailing spaces removed from all lines
|
92
|
+
* @example
|
93
|
+
* ```typescript
|
94
|
+
* str('Hello \nWorld ').trimLinesTrailingSpaces().$ // 'Hello\nWorld'
|
95
|
+
* ```
|
31
96
|
*/
|
32
97
|
trimLinesTrailingSpaces(): Str;
|
33
98
|
/**
|
34
|
-
*
|
99
|
+
* Remove leading and trailing whitespace
|
100
|
+
* @returns A new Str instance with whitespace removed from both ends
|
101
|
+
* @example
|
102
|
+
* ```typescript
|
103
|
+
* str(' Hello ').trim().$ // 'Hello'
|
104
|
+
* ```
|
35
105
|
*/
|
36
106
|
trim(): Str;
|
37
107
|
/**
|
38
|
-
*
|
108
|
+
* Remove leading whitespace
|
109
|
+
* @returns A new Str instance with leading whitespace removed
|
110
|
+
* @example
|
111
|
+
* ```typescript
|
112
|
+
* str(' Hello ').trimStart().$ // 'Hello '
|
113
|
+
* ```
|
39
114
|
*/
|
40
115
|
trimStart(): Str;
|
41
116
|
/**
|
42
|
-
*
|
117
|
+
* Remove trailing whitespace
|
118
|
+
* @returns A new Str instance with trailing whitespace removed
|
119
|
+
* @example
|
120
|
+
* ```typescript
|
121
|
+
* str(' Hello ').trimEnd().$ // ' Hello'
|
122
|
+
* ```
|
43
123
|
*/
|
44
124
|
trimEnd(): Str;
|
45
125
|
/**
|
46
|
-
* Split
|
126
|
+
* Split the string into an array of Str instances
|
127
|
+
* @param separator - String or RegExp to split on
|
128
|
+
* @param limit - Maximum number of splits to perform
|
129
|
+
* @returns Array of Str instances
|
130
|
+
* @example
|
131
|
+
* ```typescript
|
132
|
+
* str('a,b,c').split(',') // [Str('a'), Str('b'), Str('c')]
|
133
|
+
* str('a b c').split(' ', 2) // [Str('a'), Str('b')]
|
134
|
+
* ```
|
47
135
|
*/
|
48
136
|
split(separator: string | RegExp, limit?: number): Str[];
|
49
137
|
/**
|
50
|
-
* Add line numbers to
|
51
|
-
* @param separator
|
52
|
-
*
|
138
|
+
* Add line numbers to each line
|
139
|
+
* @param separator - String to separate line numbers from content
|
140
|
+
* @returns A new Str instance with line numbers added
|
141
|
+
* @example
|
142
|
+
* ```typescript
|
143
|
+
* str('A\nB').addLineNumbers().$ // '0:A\n1:B'
|
144
|
+
* str('A\nB').addLineNumbers(' -> ').$ // '0 -> A\n1 -> B'
|
145
|
+
* ```
|
53
146
|
*/
|
54
147
|
addLineNumbers(separator?: string): Str;
|
55
148
|
/**
|
56
|
-
*
|
57
|
-
* @
|
149
|
+
* Get the character at a specific index
|
150
|
+
* @param index - Zero-based position in the string
|
151
|
+
* @returns The character at the index, or undefined if out of bounds
|
152
|
+
* @example
|
153
|
+
* ```typescript
|
154
|
+
* str('Hello').at(0) // 'H'
|
155
|
+
* str('Hello').at(-1) // 'o'
|
156
|
+
* ```
|
58
157
|
*/
|
59
158
|
at(index: number): string | undefined;
|
60
159
|
/**
|
61
|
-
*
|
160
|
+
* Get the length of the string
|
161
|
+
* @returns The number of characters in the string
|
162
|
+
* @example
|
163
|
+
* ```typescript
|
164
|
+
* str('Hello').length() // 5
|
165
|
+
* str('').length() // 0
|
166
|
+
* ```
|
62
167
|
*/
|
63
168
|
length(): number;
|
64
169
|
/**
|
65
|
-
* Indent
|
66
|
-
* @param size
|
67
|
-
* @param char
|
170
|
+
* Indent each line by a specified number of spaces
|
171
|
+
* @param size - Number of spaces to add
|
172
|
+
* @param char - Character to use for indentation
|
173
|
+
* @returns A new Str instance with added indentation
|
174
|
+
* @example
|
175
|
+
* ```typescript
|
176
|
+
* str('Hello\nWorld').indent(2).$ // ' Hello\n World'
|
177
|
+
* str('A\nB').indent(2, '-').$ // '--A\n--B'
|
178
|
+
* ```
|
68
179
|
*/
|
69
180
|
indent(size: number, char?: string): Str;
|
70
181
|
/**
|
71
|
-
*
|
72
|
-
* @param indentation
|
73
|
-
*
|
182
|
+
* Remove indentation from each line
|
183
|
+
* @param indentation - Optional number of spaces to remove
|
184
|
+
* @returns A new Str instance with indentation removed
|
185
|
+
* @example
|
186
|
+
* ```typescript
|
187
|
+
* str(' Hello\n World').dedent().$ // 'Hello\n World'
|
188
|
+
* str(' A\n B').dedent(2).$ // ' A\nB'
|
189
|
+
* ```
|
74
190
|
*/
|
75
191
|
dedent(indentation?: number): Str;
|
76
192
|
/**
|
77
|
-
*
|
193
|
+
* Remove characters from the start of the string
|
194
|
+
* @param count - Number of characters to remove
|
195
|
+
* @returns A new Str instance with characters removed from the start
|
196
|
+
* @example
|
197
|
+
* ```typescript
|
198
|
+
* str('Hello').chopStart(2).$ // 'llo'
|
199
|
+
* ```
|
78
200
|
*/
|
79
201
|
chopStart(count: number): Str;
|
80
202
|
/**
|
81
|
-
*
|
203
|
+
* Remove characters from the end of the string
|
204
|
+
* @param count - Number of characters to remove
|
205
|
+
* @returns A new Str instance with characters removed from the end
|
206
|
+
* @example
|
207
|
+
* ```typescript
|
208
|
+
* str('Hello').chopEnd(2).$ // 'Hel'
|
209
|
+
* ```
|
82
210
|
*/
|
83
211
|
chopEnd(count: number): Str;
|
84
212
|
/**
|
85
|
-
*
|
86
|
-
* @param maxRepeat
|
213
|
+
* Limit consecutive newlines to a maximum count
|
214
|
+
* @param maxRepeat - Maximum number of consecutive newlines to allow
|
215
|
+
* @returns A new Str instance with limited consecutive newlines
|
216
|
+
* @example
|
217
|
+
* ```typescript
|
218
|
+
* str('A\n\n\nB').chopRepeatNewlines(1).$ // 'A\nB'
|
219
|
+
* str('A\n\n\nB').chopRepeatNewlines(2).$ // 'A\n\nB'
|
220
|
+
* ```
|
87
221
|
*/
|
88
222
|
chopRepeatNewlines(maxRepeat: number): Str;
|
89
223
|
/**
|
90
|
-
* Take
|
224
|
+
* Take characters from the start of the string
|
225
|
+
* @param count - Number of characters to take
|
226
|
+
* @returns A new Str instance with the first n characters
|
227
|
+
* @example
|
228
|
+
* ```typescript
|
229
|
+
* str('Hello').takeStart(2).$ // 'He'
|
230
|
+
* ```
|
91
231
|
*/
|
92
232
|
takeStart(count: number): Str;
|
93
233
|
/**
|
94
|
-
* Take
|
234
|
+
* Take characters from the end of the string
|
235
|
+
* @param count - Number of characters to take
|
236
|
+
* @returns A new Str instance with the last n characters
|
237
|
+
* @example
|
238
|
+
* ```typescript
|
239
|
+
* str('Hello').takeEnd(2).$ // 'lo'
|
240
|
+
* ```
|
95
241
|
*/
|
96
242
|
takeEnd(count: number): Str;
|
97
243
|
/**
|
98
|
-
*
|
244
|
+
* Get the last line of the string
|
245
|
+
* @returns A new Str instance containing the last line
|
246
|
+
* @example
|
247
|
+
* ```typescript
|
248
|
+
* str('Hello\nWorld').lastLine().$ // 'World'
|
249
|
+
* ```
|
99
250
|
*/
|
100
251
|
lastLine(): Str;
|
101
252
|
/**
|
102
|
-
*
|
253
|
+
* Get the first line of the string
|
254
|
+
* @returns A new Str instance containing the first line
|
255
|
+
* @example
|
256
|
+
* ```typescript
|
257
|
+
* str('Hello\nWorld').firstLine().$ // 'Hello'
|
258
|
+
* ```
|
103
259
|
*/
|
104
260
|
firstLine(): Str;
|
105
261
|
/**
|
106
|
-
*
|
262
|
+
* Count leading space characters
|
263
|
+
* @returns The number of leading space characters
|
264
|
+
* @example
|
265
|
+
* ```typescript
|
266
|
+
* str(' Hello').leadingSpacesCount() // 2
|
267
|
+
* str('Hello').leadingSpacesCount() // 0
|
268
|
+
* ```
|
107
269
|
*/
|
108
270
|
leadingSpacesCount(): number;
|
109
271
|
/**
|
110
|
-
*
|
272
|
+
* Get the minimum indentation level of non-empty lines
|
273
|
+
* @returns The number of spaces in the minimum indentation
|
274
|
+
* @example
|
275
|
+
* ```typescript
|
276
|
+
* str(' Hello\n World').indentation() // 2
|
277
|
+
* str('Hello\n World').indentation() // 0
|
278
|
+
* ```
|
111
279
|
*/
|
112
280
|
indentation(): number;
|
113
281
|
/**
|
114
|
-
*
|
282
|
+
* Check if the string is empty or contains only whitespace
|
283
|
+
* @returns True if empty or whitespace-only, false otherwise
|
284
|
+
* @example
|
285
|
+
* ```typescript
|
286
|
+
* str('').isEmpty() // true
|
287
|
+
* str(' \n').isEmpty() // true
|
288
|
+
* str('Hello').isEmpty() // false
|
289
|
+
* ```
|
115
290
|
*/
|
116
291
|
isEmpty(): boolean;
|
117
292
|
/**
|
118
|
-
*
|
293
|
+
* Replace the first occurrence of a substring or pattern
|
294
|
+
* @param searchValue - The string or pattern to search for
|
295
|
+
* @param replaceValue - The string to replace the match with
|
296
|
+
* @returns A new Str instance with the first match replaced
|
297
|
+
* @example
|
298
|
+
* ```typescript
|
299
|
+
* str('Hello World').replace('o', '0').$ // 'Hell0 World'
|
300
|
+
* str('abc abc').replace(/[a-z]/, 'X').$ // 'Xbc abc'
|
301
|
+
* ```
|
302
|
+
*/
|
303
|
+
replace(searchValue: string | RegExp, replaceValue: string): Str;
|
304
|
+
/**
|
305
|
+
* Replace all occurrences of a substring or pattern
|
306
|
+
* @param searchValue - The string or pattern to search for
|
307
|
+
* @param replaceValue - The string to replace the matches with
|
308
|
+
* @returns A new Str instance with all matches replaced
|
309
|
+
* @example
|
310
|
+
* ```typescript
|
311
|
+
* str('Hello World').replaceAll('o', '0').$ // 'Hell0 W0rld'
|
312
|
+
* str('abc abc').replaceAll(/[a-z]/g, 'X').$ // 'XXX XXX'
|
313
|
+
* ```
|
314
|
+
*/
|
315
|
+
replaceAll(searchValue: string | RegExp, replaceValue: string): Str;
|
316
|
+
/**
|
317
|
+
* Convert string to camelCase
|
318
|
+
* @returns A new Str instance in camelCase
|
319
|
+
* @example
|
320
|
+
* ```typescript
|
321
|
+
* str('hello-world').camelCase().$ // 'helloWorld'
|
322
|
+
* ```
|
119
323
|
*/
|
120
324
|
camelCase(): Str;
|
121
325
|
/**
|
122
|
-
*
|
326
|
+
* Convert string to Capital Case
|
327
|
+
* @returns A new Str instance in Capital Case
|
328
|
+
* @example
|
329
|
+
* ```typescript
|
330
|
+
* str('hello-world').capitalCase().$ // 'Hello World'
|
331
|
+
* ```
|
123
332
|
*/
|
124
333
|
capitalCase(): Str;
|
125
334
|
/**
|
126
|
-
*
|
335
|
+
* Convert string to CONSTANT_CASE
|
336
|
+
* @returns A new Str instance in CONSTANT_CASE
|
337
|
+
* @example
|
338
|
+
* ```typescript
|
339
|
+
* str('hello-world').constantCase().$ // 'HELLO_WORLD'
|
340
|
+
* ```
|
127
341
|
*/
|
128
342
|
constantCase(): Str;
|
129
343
|
/**
|
130
|
-
*
|
344
|
+
* Convert string to dot.case
|
345
|
+
* @returns A new Str instance in dot.case
|
346
|
+
* @example
|
347
|
+
* ```typescript
|
348
|
+
* str('hello-world').dotCase().$ // 'hello.world'
|
349
|
+
* ```
|
131
350
|
*/
|
132
351
|
dotCase(): Str;
|
133
352
|
/**
|
134
|
-
*
|
353
|
+
* Convert string to kebab-case
|
354
|
+
* @returns A new Str instance in kebab-case
|
355
|
+
* @example
|
356
|
+
* ```typescript
|
357
|
+
* str('helloWorld').kebabCase().$ // 'hello-world'
|
358
|
+
* ```
|
135
359
|
*/
|
136
360
|
kebabCase(): Str;
|
137
361
|
/**
|
138
|
-
*
|
362
|
+
* Convert string to no case
|
363
|
+
* @returns A new Str instance with no case
|
364
|
+
* @example
|
365
|
+
* ```typescript
|
366
|
+
* str('helloWorld').noCase().$ // 'hello world'
|
367
|
+
* ```
|
139
368
|
*/
|
140
369
|
noCase(): Str;
|
141
370
|
/**
|
142
|
-
*
|
371
|
+
* Convert string to PascalCase
|
372
|
+
* @returns A new Str instance in PascalCase
|
373
|
+
* @example
|
374
|
+
* ```typescript
|
375
|
+
* str('hello-world').pascalCase().$ // 'HelloWorld'
|
376
|
+
* ```
|
143
377
|
*/
|
144
378
|
pascalCase(): Str;
|
145
379
|
/**
|
146
|
-
*
|
380
|
+
* Convert string to Pascal_Snake_Case
|
381
|
+
* @returns A new Str instance in Pascal_Snake_Case
|
382
|
+
* @example
|
383
|
+
* ```typescript
|
384
|
+
* str('hello-world').pascalSnakeCase().$ // 'Hello_World'
|
385
|
+
* ```
|
147
386
|
*/
|
148
387
|
pascalSnakeCase(): Str;
|
149
388
|
/**
|
150
|
-
*
|
389
|
+
* Convert string to path/case
|
390
|
+
* @returns A new Str instance in path/case
|
391
|
+
* @example
|
392
|
+
* ```typescript
|
393
|
+
* str('hello-world').pathCase().$ // 'hello/world'
|
394
|
+
* ```
|
151
395
|
*/
|
152
396
|
pathCase(): Str;
|
153
397
|
/**
|
154
|
-
*
|
398
|
+
* Convert string to Sentence case
|
399
|
+
* @returns A new Str instance in Sentence case
|
400
|
+
* @example
|
401
|
+
* ```typescript
|
402
|
+
* str('hello-world').sentenceCase().$ // 'Hello world'
|
403
|
+
* ```
|
155
404
|
*/
|
156
405
|
sentenceCase(): Str;
|
157
406
|
/**
|
158
|
-
*
|
407
|
+
* Convert string to snake_case
|
408
|
+
* @returns A new Str instance in snake_case
|
409
|
+
* @example
|
410
|
+
* ```typescript
|
411
|
+
* str('helloWorld').snakeCase().$ // 'hello_world'
|
412
|
+
* ```
|
159
413
|
*/
|
160
414
|
snakeCase(): Str;
|
161
415
|
/**
|
162
|
-
*
|
416
|
+
* Convert string to Train-Case
|
417
|
+
* @returns A new Str instance in Train-Case
|
418
|
+
* @example
|
419
|
+
* ```typescript
|
420
|
+
* str('hello-world').trainCase().$ // 'Hello-World'
|
421
|
+
* ```
|
163
422
|
*/
|
164
423
|
trainCase(): Str;
|
165
424
|
/**
|
166
|
-
*
|
425
|
+
* Get the underlying string value
|
426
|
+
* @returns The wrapped string value
|
427
|
+
* @example
|
428
|
+
* ```typescript
|
429
|
+
* str('hello').str // 'hello'
|
430
|
+
* ```
|
167
431
|
*/
|
168
432
|
get str(): string;
|
169
433
|
}
|
434
|
+
/**
|
435
|
+
* Create a new Str instance from any stringable value
|
436
|
+
* @param text - Any value that can be converted to a string
|
437
|
+
* @returns A new Str instance wrapping the string value
|
438
|
+
* @example
|
439
|
+
* ```typescript
|
440
|
+
* str('hello') // from string
|
441
|
+
* str(123) // from number
|
442
|
+
* str({ toString() }) // from object with toString
|
443
|
+
* ```
|
444
|
+
*/
|
170
445
|
declare const str: (text: Stringable) => Str;
|
171
446
|
|
172
447
|
/**
|
173
448
|
* Remove empty lines at the start of the text but leave whitespace on the first line with content
|
449
|
+
* @param text - The input string to process
|
450
|
+
* @returns The string with empty lines removed from the start
|
451
|
+
* @example
|
452
|
+
* ```typescript
|
453
|
+
* chopEmptyLinesStart("\n\n \n Hello") // " Hello"
|
454
|
+
* chopEmptyLinesStart(" Hello") // " Hello"
|
455
|
+
* ```
|
174
456
|
*/
|
175
457
|
declare const chopEmptyLinesStart: (text: string) => string;
|
176
458
|
/**
|
177
459
|
* Remove empty lines at the end of the text but leave whitespace on the last line with content
|
460
|
+
* @param text - The input string to process
|
461
|
+
* @returns The string with empty lines removed from the end
|
462
|
+
* @example
|
463
|
+
* ```typescript
|
464
|
+
* chopEmptyLinesEnd("Hello\n\n \n") // "Hello"
|
465
|
+
* chopEmptyLinesEnd("Hello ") // "Hello "
|
466
|
+
* ```
|
178
467
|
*/
|
179
468
|
declare const chopEmptyLinesEnd: (text: string) => string;
|
180
469
|
/**
|
181
|
-
* Remove all space
|
470
|
+
* Remove all space characters in lines that contain no content
|
471
|
+
* @param text - The input string to process
|
472
|
+
* @returns The string with whitespace removed from empty lines
|
473
|
+
* @example
|
474
|
+
* ```typescript
|
475
|
+
* trimEmptyLines("Hello\n \nWorld") // "Hello\n\nWorld"
|
476
|
+
* trimEmptyLines(" \n \n ") // "\n\n"
|
477
|
+
* ```
|
182
478
|
*/
|
183
479
|
declare const trimEmptyLines: (text: string) => string;
|
184
480
|
/**
|
185
|
-
* Remove all space
|
481
|
+
* Remove all space characters at the end of each line
|
482
|
+
* @param text - The input string to process
|
483
|
+
* @returns The string with trailing spaces removed from all lines
|
484
|
+
* @example
|
485
|
+
* ```typescript
|
486
|
+
* trimLinesTrailingSpaces("Hello \nWorld ") // "Hello\nWorld"
|
487
|
+
* trimLinesTrailingSpaces("Hello ") // "Hello"
|
488
|
+
* ```
|
186
489
|
*/
|
187
490
|
declare const trimLinesTrailingSpaces: (text: string) => string;
|
188
491
|
/**
|
189
|
-
*
|
492
|
+
* Remove leading and trailing whitespace and line terminator characters
|
493
|
+
* @param text - The input string to process
|
494
|
+
* @returns The trimmed string
|
495
|
+
* @example
|
496
|
+
* ```typescript
|
497
|
+
* trim(" Hello World ") // "Hello World"
|
498
|
+
* trim("\n Hello \n") // "Hello"
|
499
|
+
* ```
|
190
500
|
*/
|
191
501
|
declare const trim: (text: string) => string;
|
192
502
|
/**
|
193
|
-
*
|
503
|
+
* Remove leading whitespace and line terminator characters
|
504
|
+
* @param text - The input string to process
|
505
|
+
* @returns The string with leading whitespace removed
|
506
|
+
* @example
|
507
|
+
* ```typescript
|
508
|
+
* trimStart(" Hello World ") // "Hello World "
|
509
|
+
* trimStart("\n Hello") // "Hello"
|
510
|
+
* ```
|
194
511
|
*/
|
195
512
|
declare const trimStart: (text: string) => string;
|
196
513
|
/**
|
197
|
-
*
|
514
|
+
* Remove trailing whitespace and line terminator characters
|
515
|
+
* @param text - The input string to process
|
516
|
+
* @returns The string with trailing whitespace removed
|
517
|
+
* @example
|
518
|
+
* ```typescript
|
519
|
+
* trimEnd(" Hello World ") // " Hello World"
|
520
|
+
* trimEnd("Hello \n") // "Hello"
|
521
|
+
* ```
|
198
522
|
*/
|
199
523
|
declare const trimEnd: (text: string) => string;
|
200
524
|
/**
|
201
|
-
* Split a string into substrings using the specified separator
|
525
|
+
* Split a string into substrings using the specified separator
|
526
|
+
* @param text - The input string to split
|
527
|
+
* @param separator - The string or regular expression to use for splitting
|
528
|
+
* @param limit - Optional limit on the number of splits to perform
|
529
|
+
* @returns An array of substrings
|
530
|
+
* @example
|
531
|
+
* ```typescript
|
532
|
+
* split("Hello World", " ") // ["Hello", "World"]
|
533
|
+
* split("a,b,c", ",", 2) // ["a", "b"]
|
534
|
+
* split("a.b-c", /[.-]/) // ["a", "b", "c"]
|
535
|
+
* ```
|
202
536
|
*/
|
203
537
|
declare const split: (text: string, separator: string | RegExp, limit?: number) => string[];
|
204
538
|
/**
|
205
|
-
* Add line numbers to a string
|
206
|
-
* @param text The string to add line numbers to
|
207
|
-
* @param separator The separator
|
208
|
-
*
|
539
|
+
* Add line numbers to each line in a string
|
540
|
+
* @param text - The string to add line numbers to
|
541
|
+
* @param separator - The separator between line number and content (defaults to ":")
|
542
|
+
* @returns The string with line numbers added
|
543
|
+
* @example
|
544
|
+
* ```typescript
|
545
|
+
* addLineNumbers("Hello\nWorld") // "0:Hello\n1:World"
|
546
|
+
* addLineNumbers("A\nB\nC", " -> ") // "0 -> A\n1 -> B\n2 -> C"
|
547
|
+
* ```
|
209
548
|
*/
|
210
549
|
declare const addLineNumbers: (text: string, separator?: string) => string;
|
211
550
|
/**
|
212
|
-
*
|
551
|
+
* Calculate the minimum indentation level of non-empty lines in the string
|
552
|
+
* @param text - The input string to analyze
|
553
|
+
* @returns The number of spaces in the minimum indentation level, or 0 if no indentation found
|
554
|
+
* @example
|
555
|
+
* ```typescript
|
556
|
+
* indentation(" Hello\n World") // 2
|
557
|
+
* indentation("Hello\n World") // 0
|
558
|
+
* indentation(" \n Hello") // 4
|
559
|
+
* ```
|
213
560
|
*/
|
214
561
|
declare const indentation: (text: string) => number;
|
215
562
|
/**
|
216
|
-
* Indent the string by
|
217
|
-
* @param
|
218
|
-
* @param
|
563
|
+
* Indent each line of the string by a specified number of spaces
|
564
|
+
* @param text - The input string to indent
|
565
|
+
* @param size - The number of spaces to add at the start of each line
|
566
|
+
* @param char - The character to use for indentation (defaults to space)
|
567
|
+
* @returns The indented string
|
568
|
+
* @example
|
569
|
+
* ```typescript
|
570
|
+
* indent("Hello\nWorld", 2) // " Hello\n World"
|
571
|
+
* indent("A\nB", 3, "-") // "---A\n---B"
|
572
|
+
* ```
|
219
573
|
*/
|
220
574
|
declare const indent: (text: string, size: number, char?: string) => string;
|
221
575
|
/**
|
222
|
-
*
|
223
|
-
* @param
|
224
|
-
*
|
576
|
+
* Remove indentation from each line of the string
|
577
|
+
* @param text - The input string to dedent
|
578
|
+
* @param size - Optional number of spaces to remove. If not provided, removes the minimum common indentation
|
579
|
+
* @returns The dedented string
|
580
|
+
* @example
|
581
|
+
* ```typescript
|
582
|
+
* dedent(" Hello\n World") // "Hello\n World"
|
583
|
+
* dedent(" A\n B", 2) // " A\nB"
|
584
|
+
* ```
|
225
585
|
*/
|
226
586
|
declare const dedent: (text: string, size?: number) => string;
|
227
587
|
/**
|
228
|
-
*
|
588
|
+
* Remove a specified number of characters from the end of the string
|
589
|
+
* @param text - The input string to process
|
590
|
+
* @param count - The number of characters to remove
|
591
|
+
* @returns The string with characters removed from the end
|
592
|
+
* @example
|
593
|
+
* ```typescript
|
594
|
+
* chopEnd("Hello World", 6) // "Hello"
|
595
|
+
* chopEnd("Hello", 0) // "Hello"
|
596
|
+
* ```
|
229
597
|
*/
|
230
598
|
declare const chopEnd: (text: string, count: number) => string;
|
231
599
|
/**
|
232
|
-
*
|
600
|
+
* Remove a specified number of characters from the start of the string
|
601
|
+
* @param text - The input string to process
|
602
|
+
* @param count - The number of characters to remove
|
603
|
+
* @returns The string with characters removed from the start
|
604
|
+
* @example
|
605
|
+
* ```typescript
|
606
|
+
* chopStart("Hello World", 6) // "World"
|
607
|
+
* chopStart("Hello", 0) // "Hello"
|
608
|
+
* ```
|
233
609
|
*/
|
234
610
|
declare const chopStart: (text: string, count: number) => string;
|
235
611
|
/**
|
236
|
-
*
|
237
|
-
* @param
|
612
|
+
* Limit the number of consecutive newlines in the string
|
613
|
+
* @param text - The input string to process
|
614
|
+
* @param maxRepeat - The maximum number of consecutive newlines to allow
|
615
|
+
* @returns The string with consecutive newlines limited
|
616
|
+
* @example
|
617
|
+
* ```typescript
|
618
|
+
* chopRepeatNewlines("A\n\n\n\nB", 2) // "A\n\nB"
|
619
|
+
* chopRepeatNewlines("A\n\nB", 1) // "A\nB"
|
620
|
+
* ```
|
238
621
|
*/
|
239
622
|
declare const chopRepeatNewlines: (text: string, maxRepeat: number) => string;
|
240
623
|
/**
|
241
|
-
*
|
624
|
+
* Extract a specified number of characters from the start of the string
|
625
|
+
* @param text - The input string to process
|
626
|
+
* @param count - The number of characters to take
|
627
|
+
* @returns The extracted substring from the start
|
628
|
+
* @example
|
629
|
+
* ```typescript
|
630
|
+
* takeStart("Hello World", 5) // "Hello"
|
631
|
+
* takeStart("Hi", 5) // "Hi"
|
632
|
+
* ```
|
242
633
|
*/
|
243
634
|
declare const takeStart: (text: string, count: number) => string;
|
244
635
|
/**
|
245
|
-
*
|
636
|
+
* Extract a specified number of characters from the end of the string
|
637
|
+
* @param text - The input string to process
|
638
|
+
* @param count - The number of characters to take
|
639
|
+
* @returns The extracted substring from the end
|
640
|
+
* @example
|
641
|
+
* ```typescript
|
642
|
+
* takeEnd("Hello World", 5) // "World"
|
643
|
+
* takeEnd("Hi", 5) // "Hi"
|
644
|
+
* ```
|
246
645
|
*/
|
247
646
|
declare const takeEnd: (text: string, count: number) => string;
|
248
647
|
/**
|
249
|
-
*
|
648
|
+
* Get the last line of a multi-line string
|
649
|
+
* @param text - The input string to process
|
650
|
+
* @returns The last line of the string, or empty string if input is empty
|
651
|
+
* @example
|
652
|
+
* ```typescript
|
653
|
+
* lastLine("Hello\nWorld") // "World"
|
654
|
+
* lastLine("Hello") // "Hello"
|
655
|
+
* lastLine("") // ""
|
656
|
+
* ```
|
250
657
|
*/
|
251
658
|
declare const lastLine: (text: string) => string;
|
252
659
|
/**
|
253
|
-
*
|
660
|
+
* Get the first line of a multi-line string
|
661
|
+
* @param text - The input string to process
|
662
|
+
* @returns The first line of the string, or empty string if input is empty
|
663
|
+
* @example
|
664
|
+
* ```typescript
|
665
|
+
* firstLine("Hello\nWorld") // "Hello"
|
666
|
+
* firstLine("Hello") // "Hello"
|
667
|
+
* firstLine("") // ""
|
668
|
+
* ```
|
254
669
|
*/
|
255
670
|
declare const firstLine: (text: string) => string;
|
256
671
|
/**
|
257
|
-
*
|
672
|
+
* Count the number of leading space characters in a string
|
673
|
+
* @param text - The input string to analyze
|
674
|
+
* @returns The number of leading space characters
|
675
|
+
* @example
|
676
|
+
* ```typescript
|
677
|
+
* leadingSpacesCount(" Hello") // 2
|
678
|
+
* leadingSpacesCount("Hello") // 0
|
679
|
+
* ```
|
258
680
|
*/
|
259
681
|
declare const leadingSpacesCount: (text: string) => number;
|
260
682
|
/**
|
261
|
-
*
|
683
|
+
* Check if a string is empty or contains only whitespace
|
684
|
+
* @param text - The input string to check
|
685
|
+
* @returns True if the string is empty or contains only whitespace, false otherwise
|
686
|
+
* @example
|
687
|
+
* ```typescript
|
688
|
+
* isEmpty("") // true
|
689
|
+
* isEmpty(" \n ") // true
|
690
|
+
* isEmpty("Hello") // false
|
691
|
+
* ```
|
262
692
|
*/
|
263
693
|
declare const isEmpty: (text: string) => boolean;
|
694
|
+
/**
|
695
|
+
* Replace the first occurrence of a substring or pattern in the string
|
696
|
+
* @param text - The input string to process
|
697
|
+
* @param searchValue - The string or pattern to search for
|
698
|
+
* @param replaceValue - The string to replace the match with
|
699
|
+
* @returns The string with the first match replaced
|
700
|
+
* @example
|
701
|
+
* ```typescript
|
702
|
+
* replace("Hello World", "o", "0") // "Hell0 World"
|
703
|
+
* replace("abc abc", /[a-z]/, "X") // "Xbc abc"
|
704
|
+
* ```
|
705
|
+
*/
|
706
|
+
declare const replace: (text: string, searchValue: string | RegExp, replaceValue: string) => string;
|
707
|
+
/**
|
708
|
+
* Replace all occurrences of a substring or pattern in the string
|
709
|
+
* @param text - The input string to process
|
710
|
+
* @param searchValue - The string or pattern to search for
|
711
|
+
* @param replaceValue - The string to replace the matches with
|
712
|
+
* @returns The string with all matches replaced
|
713
|
+
* @example
|
714
|
+
* ```typescript
|
715
|
+
* replaceAll("Hello World", "o", "0") // "Hell0 W0rld"
|
716
|
+
* replaceAll("abc abc", /[a-z]/g, "X") // "XXX XXX"
|
717
|
+
* ```
|
718
|
+
*/
|
719
|
+
declare const replaceAll: (text: string, searchValue: string | RegExp, replaceValue: string) => string;
|
264
720
|
|
265
|
-
export { Str, addLineNumbers, chopEmptyLinesEnd, chopEmptyLinesStart, chopEnd, chopRepeatNewlines, chopStart, dedent, firstLine, indent, indentation, isEmpty, lastLine, leadingSpacesCount, split, str, takeEnd, takeStart, trim, trimEmptyLines, trimEnd, trimLinesTrailingSpaces, trimStart };
|
721
|
+
export { Str, addLineNumbers, chopEmptyLinesEnd, chopEmptyLinesStart, chopEnd, chopRepeatNewlines, chopStart, dedent, firstLine, indent, indentation, isEmpty, lastLine, leadingSpacesCount, replace, replaceAll, split, str, takeEnd, takeStart, trim, trimEmptyLines, trimEnd, trimLinesTrailingSpaces, trimStart };
|