@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.
@@ -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 but leave whitespace on the first line with content
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 but leave whitespace on the last line with content
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 all space (\s) characters in lines without content
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 all spaces (\s) characters at the end of lines
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
- * Removes the leading and trailing white space and line terminator characters
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
- * Removes the leading white space and line terminator characters
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
- * Removes the trailing white space and line terminator characters
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 a string into substrings using the specified separator and return them as an array
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 a string
51
- * @param separator The separator to use between the line number and the line content.
52
- * Defaults to ":"
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
- * Returns the character at the specified index
57
- * @return string or undefined if the index is out of bounds
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
- * Returns the length of the string
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 the string by the specified number of spaces
66
- * @param size The number of spaces to indent by
67
- * @param char The character to use for indentation. Defaults to " "
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
- * Dedent the string by the specified number of spaces
72
- * @param indentation The number of spaces to dedent by.
73
- * If not provided, it will be calculated automatically based on the maximum indentation in the string.
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
- * Chop the string at the start by the specified number of characters
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
- * Chop the string at the end by the specified number of characters
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
- * Remove successive newlines of the specified repetition or more
86
- * @param maxRepeat the maximum number of newlines to allow
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 the first n characters of the string
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 the last n characters of the string
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
- * Returns the last line of the string
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
- * Returns the first line of the string
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
- * Returns the number of leading spaces in the string
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
- * Returns the indentation level of the string skipping empty lines in the process
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
- * Returns true if the string is empty or contains only whitespace
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
- * Converts the string to camel case
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
- * Converts the string to capital case
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
- * Converts the string to constant case
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
- * Converts the string to dot case
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
- * Converts the string to kebab case
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
- * Converts the string to no case
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
- * Converts the string to pascal case
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
- * Converts the string to pascal snake case
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
- * Converts the string to path case
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
- * Converts the string to sentence case
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
- * Converts the string to snake case
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
- * Converts the string to train case
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
- * Shorthand for `.toString()`
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 (\s) characters in lines without content
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 (\s) characters at the end of lines
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
- * Removes the leading and trailing white space and line terminator characters
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
- * Removes the leading white space and line terminator characters
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
- * Removes the trailing white space and line terminator characters
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 and return them as an array
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 to use between the line number and the line content.
208
- * Defaults to ":"
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
- * Returns the indentation level of the string skipping empty lines in the process
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 the specified number of spaces
217
- * @param size The number of spaces to indent by
218
- * @param char The character to use for indentation. Defaults to " "
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
- * Dedent the string by the specified number of spaces
223
- * @param indentation The number of spaces to dedent by.
224
- * If not provided, it will be calculated automatically based on the maximum indentation in the string.
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
- * Chop the string at the end by the specified number of characters
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
- * Chop the string at the start by the specified number of characters
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
- * Remove successive newlines of the specified repetition or more
237
- * @param maxRepeat the maximum number of newlines to allow
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
- * Take the first n characters of the string
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
- * Take the last n characters of the string
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
- * Returns the last line of the string
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
- * Returns the first line of the string
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
- * Returns the number of leading spaces in the string
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
- * Returns true if the string is empty or contains only whitespace
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 };