@tolki/str 1.0.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/dist/ascii/index.d.ts +25 -0
  4. package/dist/ascii/index.d.ts.map +1 -0
  5. package/dist/ascii/index.js +46 -0
  6. package/dist/base64/index.d.ts +23 -0
  7. package/dist/base64/index.d.ts.map +1 -0
  8. package/dist/base64/index.js +124 -0
  9. package/dist/convertcase/index.d.ts +48 -0
  10. package/dist/convertcase/index.d.ts.map +1 -0
  11. package/dist/convertcase/index.js +49 -0
  12. package/dist/index.d.ts +14 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +138 -0
  15. package/dist/markdown/index.d.ts +49 -0
  16. package/dist/markdown/index.d.ts.map +1 -0
  17. package/dist/markdown/index.js +32 -0
  18. package/dist/pluralizer/index.d.ts +100 -0
  19. package/dist/pluralizer/index.d.ts.map +1 -0
  20. package/dist/pluralizer/index.js +99 -0
  21. package/dist/random/index.d.ts +28 -0
  22. package/dist/random/index.d.ts.map +1 -0
  23. package/dist/random/index.js +45 -0
  24. package/dist/replacer/index.d.ts +31 -0
  25. package/dist/replacer/index.d.ts.map +1 -0
  26. package/dist/replacer/index.js +42 -0
  27. package/dist/str.d.ts +968 -0
  28. package/dist/str.d.ts.map +1 -0
  29. package/dist/str.js +939 -0
  30. package/dist/stringable/index.d.ts +952 -0
  31. package/dist/stringable/index.d.ts.map +1 -0
  32. package/dist/stringable/index.js +1249 -0
  33. package/dist/transliterate/index.d.ts +14 -0
  34. package/dist/transliterate/index.d.ts.map +1 -0
  35. package/dist/transliterate/index.js +7 -0
  36. package/dist/trimmer/index.d.ts +25 -0
  37. package/dist/trimmer/index.d.ts.map +1 -0
  38. package/dist/trimmer/index.js +128 -0
  39. package/dist/ulid/index.d.ts +79 -0
  40. package/dist/ulid/index.d.ts.map +1 -0
  41. package/dist/ulid/index.js +58 -0
  42. package/dist/uuid/index.d.ts +92 -0
  43. package/dist/uuid/index.d.ts.map +1 -0
  44. package/dist/uuid/index.js +50 -0
  45. package/package.json +126 -0
package/dist/str.d.ts ADDED
@@ -0,0 +1,968 @@
1
+ /**
2
+ * Return the remainder of a string after the last occurrence of a given value.
3
+ *
4
+ * @param subject - The string to search in
5
+ * @param search - The value to search for
6
+ * @returns The portion of the string after the last occurrence of the search value
7
+ *
8
+ * @see https://tolki.abe.dev/strings/string-utilities-list.html#after
9
+ *
10
+ * @example
11
+ *
12
+ * after('A house on a lake', 'house '); -> 'on a lake'
13
+ */
14
+ export declare function after(subject: string, search: string | number): string;
15
+ /**
16
+ * Return the remainder of a string after the last occurrence of a given value.
17
+ *
18
+ * @param subject - The string to search in
19
+ * @param search - The value to search for
20
+ * @returns The portion of the string after the last occurrence of the search value
21
+ *
22
+ * @see https://tolki.abe.dev/strings/string-utilities-list.html#afterLast
23
+ */
24
+ export declare function afterLast(subject: string, search: string | number): string;
25
+ /**
26
+ * Get the portion of a string before the first occurrence of a given value.
27
+ *
28
+ * @param subject - The string to search in
29
+ * @param search - The value to search for
30
+ * @returns The portion of the string before the first occurrence of the search value
31
+ */
32
+ export declare function before(subject: string, search: string | number): string;
33
+ /**
34
+ * Get the portion of a string before the last occurrence of a given value.
35
+ *
36
+ * @param subject - The string to search in
37
+ * @param search - The value to search for
38
+ * @returns The portion of the string before the last occurrence of the search value
39
+ *
40
+ * @example
41
+ *
42
+ * beforeLast('yvette', 'tte'); -> 'yve'
43
+ */
44
+ export declare function beforeLast(subject: string, search: string | number): string;
45
+ /**
46
+ * Get the portion of a string between two given values.
47
+ *
48
+ * @param subject - The string to search in
49
+ * @param from - The starting value
50
+ * @param to - The ending value
51
+ * @returns The portion of the string between the two given values
52
+ *
53
+ * @example
54
+ *
55
+ * between('foofoobar', 'foo', 'bar'); -> 'foo'
56
+ */
57
+ export declare function between(subject: string, from: string | number, to: string | number): string;
58
+ /**
59
+ * Get the smallest possible portion of a string between two given values.
60
+ *
61
+ * @param subject - The string to search in
62
+ * @param from - The starting value
63
+ * @param to - The ending value
64
+ * @returns The smallest portion of the string between the two given values
65
+ *
66
+ * @example
67
+ *
68
+ * betweenFirst('foofoobar', 'foo', 'bar'); -> 'foo'
69
+ */
70
+ export declare function betweenFirst(subject: string, from: string | number, to: string | number): string;
71
+ /**
72
+ * Convert a value to camel case.
73
+ *
74
+ * @param value - The string to convert
75
+ * @returns The camel-cased string
76
+ *
77
+ * @example
78
+ *
79
+ * camel('foo_bar'); -> 'fooBar'
80
+ */
81
+ export declare function camel(value: string): string;
82
+ /**
83
+ * Get the character at the specified index.
84
+ *
85
+ * @param subject - The string to get the character from
86
+ * @param index - The index of the character to get
87
+ * @returns The character at the specified index, or false if the index is out of bounds
88
+ *
89
+ * @example
90
+ *
91
+ * charAt('hello', 1); -> 'e'
92
+ */
93
+ export declare function charAt(subject: string, index: number): string | false;
94
+ /**
95
+ * Remove the given string(s) if it exists at the start of the haystack.
96
+ *
97
+ * @param subject - The string to chop from
98
+ * @param needle - The string or strings to remove
99
+ * @returns The string with the given string(s) removed from the start
100
+ *
101
+ * @example
102
+ *
103
+ * chopStart('foobar', 'foo'); -> 'bar'
104
+ */
105
+ export declare function chopStart(subject: string, needle: string | string[]): string;
106
+ /**
107
+ * Remove the given string(s) if it exists at the end of the haystack.
108
+ *
109
+ * @param subject - The string to chop from
110
+ * @param needle - The string or strings to remove
111
+ * @returns The string with the given string(s) removed from the end
112
+ *
113
+ * @example
114
+ *
115
+ * chopEnd('foobar', 'bar'); -> 'foo'
116
+ */
117
+ export declare function chopEnd(subject: string, needle: string | string[]): string;
118
+ /**
119
+ * Determine if a given string contains a given substring.
120
+ *
121
+ * @param haystack - The string to search in
122
+ * @param needles - The substring or substrings to search for
123
+ * @param ignoreCase - Whether to ignore case when searching
124
+ *
125
+ * @example
126
+ *
127
+ * contains('Minion', 'ni'); -> true
128
+ * contains('Minion', 'Ni', true); -> true
129
+ * contains('Minion', 'Ni', false); -> false
130
+ */
131
+ export declare function contains(haystack: string, needles: string | Iterable<string>, ignoreCase?: boolean): boolean;
132
+ /**
133
+ * Extracts an excerpt from text that matches the first instance of a phrase.
134
+ *
135
+ * @param text - The text to extract the excerpt from
136
+ * @param phrase - The phrase to search for
137
+ * @param options - Additional options for excerpt extraction
138
+ * @returns The extracted excerpt, or null if the phrase is not found
139
+ *
140
+ * @example
141
+ * excerpt('The quick brown fox', 'brown', { radius: 5 });
142
+ */
143
+ export declare function excerpt(text: string | null, phrase?: string | null, options?: {
144
+ radius?: number;
145
+ omission?: string;
146
+ }): string | null;
147
+ /**
148
+ * Determine if a given string contains all array values.
149
+ *
150
+ * @param haystack - The string to search in
151
+ * @param needles - The substrings to search for
152
+ * @param ignoreCase - Whether to ignore case when searching
153
+ * @returns True if all substrings are found, false otherwise
154
+ *
155
+ * @example
156
+ *
157
+ * containsAll('Taylor Otwell', ['taylor', 'otwell'], false); -> true
158
+ * containsAll('Taylor Otwell', ['taylor', 'xxx'], true); -> false
159
+ */
160
+ export declare function containsAll(haystack: string, needles: Iterable<string>, ignoreCase?: boolean): boolean;
161
+ /**
162
+ * Determine if a given string doesn't contain a given substring.
163
+ *
164
+ * @param haystack - The string to search in
165
+ * @param needles - The substring or substrings to search for
166
+ * @param ignoreCase - Whether to ignore case when searching
167
+ * @returns True if the substring is not found, false otherwise
168
+ *
169
+ * @example
170
+ *
171
+ * doesntContain('Minion', 'ni'); -> false
172
+ * doesntContain('Minion', 'Ni', true); -> false
173
+ * doesntContain('Minion', 'Ni', false); -> true
174
+ */
175
+ export declare function doesntContain(haystack: string, needles: string | Iterable<string>, ignoreCase?: boolean): boolean;
176
+ /**
177
+ * Replace consecutive instances of a given character with a single character in the given string.
178
+ *
179
+ * @param value - The string to process
180
+ * @param character - The character or characters to deduplicate
181
+ * @returns The string with consecutive instances of the character(s) replaced by a single instance
182
+ *
183
+ * @example
184
+ *
185
+ * deduplicate('hello world'); -> 'hello world'
186
+ * deduplicate('hello---world', '-'); -> 'hello-world'
187
+ * deduplicate('hello___world', '_'); -> 'hello-world'
188
+ * deduplicate('hello world', ' '); -> 'hello world'
189
+ */
190
+ export declare function deduplicate(value: string, character?: string | string[]): string;
191
+ /**
192
+ * Determine if a given string ends with a given substring.
193
+ *
194
+ * @param haystack - The string to search in
195
+ * @param needles - The substring or substrings to search for
196
+ * @returns True if the string ends with any of the substrings, false otherwise
197
+ *
198
+ * @example
199
+ *
200
+ * endsWith("Jason", "on"); -> true
201
+ * endsWith("Jason", "ON"); -> false
202
+ */
203
+ export declare function endsWith(haystack: string | number | null, needles: string | number | Iterable<string>): boolean;
204
+ /**
205
+ * Determine if a given string doesn't end with a given substring.
206
+ *
207
+ * @param haystack - The string to search in
208
+ * @param needles - The substring or substrings to search for
209
+ * @returns True if the string does not end with any of the substrings, false otherwise
210
+ *
211
+ * @example
212
+ *
213
+ * doesntEndWith("Jason", "on"); -> false
214
+ * doesntEndWith("Jason", "ON"); -> true
215
+ */
216
+ export declare function doesntEndWith(haystack: string | number | null, needles: string | number | Iterable<string>): boolean;
217
+ /**
218
+ * Cap a string with a single instance of a given value.
219
+ *
220
+ * @param value - The string to cap
221
+ * @param cap - The string to cap with
222
+ * @returns The capped string
223
+ *
224
+ * @example
225
+ *
226
+ * finish('hello', '!'); -> 'hello!'
227
+ */
228
+ export declare function finish(value: string, cap: string): string;
229
+ /**
230
+ * Wrap the string with the given strings.
231
+ *
232
+ * @param value - The string to wrap
233
+ * @param before - The string to prepend
234
+ * @param after - The string to append (if null, use the 'before' string)
235
+ * @returns The wrapped string
236
+ *
237
+ * @example
238
+ *
239
+ * wrap('hello', '[', ']'); -> '[hello]'
240
+ */
241
+ export declare function wrap(value: string, before: string, after?: string | null): string;
242
+ /**
243
+ * Unwrap the string with the given strings.
244
+ *
245
+ * @param value - The string to unwrap
246
+ * @param before - The string to remove from the start
247
+ * @param after - The string to remove from the end (if null, use the 'before' string)
248
+ * @returns The unwrapped string
249
+ *
250
+ * @example
251
+ *
252
+ * unwrap('[hello]', '[', ']'); -> 'hello'
253
+ */
254
+ export declare function unwrap(value: string, before: string, after?: string | null): string;
255
+ /**
256
+ * Determine if a given string matches a given pattern.
257
+ *
258
+ * @param pattern - The pattern or patterns to match against
259
+ * @param value - The string or number to check
260
+ * @param ignoreCase - Whether to ignore case when matching
261
+ * @return True if the string matches the pattern, false otherwise
262
+ *
263
+ * @example
264
+ *
265
+ * is('hello', 'hello'); -> true
266
+ * is('hello', 'Hello', true); -> true
267
+ * is('hello', 'world'); -> false
268
+ */
269
+ export declare function is(pattern: string | Iterable<string>, value: string | number, ignoreCase?: boolean): boolean;
270
+ /**
271
+ * Determine if a given string is 7 bit ASCII.
272
+ *
273
+ * @param value - The string to check
274
+ * @returns True if the string is ASCII, false otherwise
275
+ *
276
+ * @example
277
+ *
278
+ * isAscii("Hello World"); -> true
279
+ * isAscii("こんにちは"); -> false
280
+ * isAscii("12345"); -> true
281
+ * isAscii("!@#$%"); -> true
282
+ * isAscii("Hello こんにちは"); -> false
283
+ */
284
+ export declare function isAscii(value: string): boolean;
285
+ /**
286
+ * Determine if a given value is valid JSON.
287
+ *
288
+ * @param value - The value to check if it's JSON
289
+ * @returns True if the value is valid JSON, false otherwise
290
+ *
291
+ * @example
292
+ *
293
+ * isJson('{"name": "John", "age": 30}'); -> true
294
+ * isJson('{"name": "John", "age": 30'); -> false
295
+ * isJson('Hello World'); -> false
296
+ */
297
+ export declare function isJson(value: unknown): boolean;
298
+ /**
299
+ * Determine if a given value is a valid URL.
300
+ *
301
+ * @param value - The value to check if it's URL
302
+ * @param protocols - An optional array of allowed protocols (e.g., ['http', 'https'])
303
+ * @return True if the value is a valid URL, false otherwise
304
+ *
305
+ * @example
306
+ *
307
+ * isUrl('https://laravel.com'); -> true
308
+ * isUrl('http://localhost'); -> true
309
+ * isUrl('invalid url'); -> false
310
+ */
311
+ export declare function isUrl(value: string | unknown, protocols?: string[]): boolean;
312
+ /**
313
+ * Convert a string to kebab case.
314
+ *
315
+ * @param value - The string to convert
316
+ * @returns The kebab-cased string
317
+ *
318
+ * @example
319
+ *
320
+ * kebab("Laravel PHP Framework"); -> "laravel-php-framework"
321
+ */
322
+ export declare function kebab(value: string): string;
323
+ /**
324
+ * Return the length of the given string.
325
+ *
326
+ * @param value - The string to measure
327
+ * @returns The length of the string
328
+ *
329
+ * @example
330
+ *
331
+ * length("Hello World"); -> 11
332
+ */
333
+ export declare function length(value: string): number;
334
+ /**
335
+ * Limit the number of characters in a string.
336
+ *
337
+ * @param value - The string to limit
338
+ * @param limit - The maximum number of characters
339
+ * @param end - The string to append if the value is truncated
340
+ * @param preserveWords - Whether to preserve whole words when truncating
341
+ * @returns The limited string
342
+ */
343
+ export declare function limit(value: string, limit?: number, end?: string, preserveWords?: boolean): string;
344
+ /**
345
+ * Convert the given string to lower-case.
346
+ *
347
+ * @param value - The string to convert
348
+ * @returns The lower-cased string
349
+ *
350
+ * @example
351
+ *
352
+ * lower("Hello World"); -> "hello world"
353
+ */
354
+ export declare function lower(value: string): string;
355
+ /**
356
+ * Limit the number of words in a string.
357
+ *
358
+ * @param value - The string to limit
359
+ * @param words - The maximum number of words
360
+ * @param end - The string to append if the value is truncated
361
+ * @returns The limited string
362
+ *
363
+ * @example
364
+ *
365
+ * words("Laravel PHP Framework", 2); -> "Laravel PHP Framework"
366
+ * words("Laravel PHP Framework", 1); -> "Laravel..."
367
+ */
368
+ export declare function words(value: string, words?: number, end?: string): string;
369
+ /**
370
+ * Masks a portion of a string with a repeated character.
371
+ *
372
+ * @param value - The string to mask
373
+ * @param character - The character to use for masking
374
+ * @param index - The starting index to begin masking (can be negative)
375
+ * @param length - The number of characters to mask (if null, mask to the end of the string)
376
+ * @returns The masked string
377
+ *
378
+ * @example
379
+ *
380
+ * mask("taylor@email.com", "*", 3); -> "tay*************"
381
+ * mask("taylor@email.com", "*", 0, 6); -> "******@email.com"
382
+ * mask("taylor@email.com", "*", -13); -> "tay*************"
383
+ * mask("taylor@email.com", "*", -13, 3); -> "tay***@email.com"
384
+ */
385
+ export declare function mask(value: string, character: string, index: number, length?: number | null): string;
386
+ /**
387
+ * Get the string matching the given pattern.
388
+ *
389
+ * @param pattern - The regex pattern to match
390
+ * @param subject - The string to search within
391
+ * @returns The matched string or an empty string if no match
392
+ */
393
+ export declare function match(pattern: string, subject: string): string;
394
+ /**
395
+ * Determine if a given string matches a given pattern.
396
+ *
397
+ * @param pattern - The pattern or patterns to match against
398
+ * @param value - The string to check
399
+ * @return True if the string matches the pattern, false otherwise
400
+ *
401
+ * @example
402
+ *
403
+ * Str::isMatch('/foo/', 'foo bar'); // true
404
+ * Str::isMatch('/bar/', 'foo bar'); // false
405
+ */
406
+ export declare function isMatch(pattern: string | Iterable<string>, value: string): boolean;
407
+ /**
408
+ * Get the string matching the given pattern.
409
+ *
410
+ * @param pattern - The regex pattern to match
411
+ * @param subject - The string to search within
412
+ * @returns An array of all matched strings
413
+ *
414
+ * @example
415
+ *
416
+ * matchAll("/foo (.*)/", "foo bar baz"); -> ["foo bar baz"]
417
+ */
418
+ export declare function matchAll(pattern: string, subject: string): string[];
419
+ /**
420
+ * Remove all non-numeric characters from a string.
421
+ *
422
+ * @param value - The string or array of strings to process
423
+ * @returns The numeric-only string or array of strings
424
+ *
425
+ * @example
426
+ *
427
+ * numbers("foo123bar"); -> "123"
428
+ * numbers(["foo123bar", "abc456"]); -> ["123", "456"]
429
+ */
430
+ export declare function numbers(value: string | string[]): string | string[];
431
+ /**
432
+ * Pad both sides of a string with another.
433
+ *
434
+ * @param value - The string to pad
435
+ * @param length - The desired total length after padding
436
+ * @param pad - The string to use for padding
437
+ * @returns The padded string
438
+ */
439
+ export declare function padBoth(value: string, length: number, pad?: string): string;
440
+ /**
441
+ * Pad the left side of a string with another.
442
+ *
443
+ * @param value - The string to pad
444
+ * @param length - The desired total length after padding
445
+ * @param pad - The string to use for padding
446
+ * @returns The padded string
447
+ *
448
+ * @example
449
+ *
450
+ * padLeft("Alien", 10, "-="); -> "-=-=-Alien"
451
+ * padLeft("Alien", 10); -> " Alien"
452
+ * padLeft("❤MultiByte☆", 16); -> " ❤MultiByte☆"
453
+ * padLeft("❤MultiByte☆", 16, "❤☆"); -> "❤☆❤☆❤❤MultiByte☆"
454
+ */
455
+ export declare function padLeft(value: string, length: number, pad?: string): string;
456
+ /**
457
+ * Pad the right side of a string with another.
458
+ *
459
+ * @param value - The string to pad
460
+ * @param length - The desired total length after padding
461
+ * @param pad - The string to use for padding
462
+ * @returns The padded string
463
+ *
464
+ * @example
465
+ *
466
+ * padRight("Alien", 10, "-="); -> "Alien-=-="
467
+ * padRight("Alien", 10); -> "Alien "
468
+ * padRight("❤MultiByte☆", 16); -> "❤MultiByte☆ "
469
+ * padRight("❤MultiByte☆", 16, "❤☆"); -> "❤MultiByte☆❤☆❤☆"
470
+ */
471
+ export declare function padRight(value: string, length: number, pad?: string): string;
472
+ /**
473
+ * Create a padding string.
474
+ *
475
+ * @param padStr - The string to use for padding
476
+ * @param needed - The total length of padding needed
477
+ * @returns The generated padding string
478
+ *
479
+ * @example
480
+ *
481
+ * makePad(" ", 5); -> " "
482
+ * makePad("-", 5); -> "-----"
483
+ * makePad("❤", 5); -> "❤❤❤❤❤"
484
+ */
485
+ export declare function makePad(padStr: string, needed: number): string;
486
+ /**
487
+ * Generate a random, secure password.
488
+ *
489
+ * Mirrors Laravel's Str::password behavior:
490
+ * - Ensures at least one character from each enabled set
491
+ * - Uses a combined pool for remaining characters
492
+ * - Shuffles result and returns a string of requested length
493
+ *
494
+ * @param length The desired length of the password (default: 32)
495
+ * @param letters Whether to include letters (default: true)
496
+ * @param numbers Whether to include numbers (default: true)
497
+ * @param symbols Whether to include symbols (default: true)
498
+ * @param spaces Whether to include spaces (default: false)
499
+ * @return The generated password string
500
+ */
501
+ export declare function password(length?: number, letters?: boolean, numbers?: boolean, symbols?: boolean, spaces?: boolean): string;
502
+ /**
503
+ * Find the multi-byte safe position of the first occurrence of a given substring in a string.
504
+ *
505
+ * @param haystack - The string to search within
506
+ * @param needle - The substring to search for
507
+ * @param offset - The position to start searching from (can be negative)
508
+ * @returns The position of the first occurrence or false if not found
509
+ *
510
+ * @example
511
+ *
512
+ * position('Hello, World!', 'World!'); -> 7
513
+ * position('Hello, World!', 'world!', 0); -> false
514
+ */
515
+ export declare function position(haystack: string, needle: string, offset?: number): number | false;
516
+ /**
517
+ * Generate a more truly "random" alpha-numeric string.
518
+ *
519
+ * @param length - The desired length of the random string (default: 16)
520
+ * @returns The generated random string
521
+ *
522
+ * @example
523
+ *
524
+ * random(); -> "a1b2c3d4e5f6g7h8"
525
+ */
526
+ export declare function random(length?: number): string;
527
+ /**
528
+ * Set the callable that will be used to generate random strings.
529
+ *
530
+ * @param factory - The factory function to generate random strings
531
+ * @returns void
532
+ *
533
+ * @example
534
+ *
535
+ * createRandomStringsUsing((length) => "x".repeat(length));
536
+ */
537
+ export declare function createRandomStringsUsing(factory: ((length: number) => string) | null): void;
538
+ /**
539
+ * Set the sequence that will be used to generate random strings.
540
+ *
541
+ * @param sequence - An array of strings to use in sequence
542
+ * @param whenMissing - An optional callable to generate strings when the sequence is exhausted
543
+ * @returns void
544
+ *
545
+ * @example
546
+ *
547
+ * createRandomStringsUsingSequence(['a', 'b', 'c']);
548
+ * createRandomStringsUsingSequence(['x', 'y', 'z'], (length) => "z".repeat(length));
549
+ */
550
+ export declare function createRandomStringsUsingSequence(sequence: string[], whenMissing?: (length: number) => string): void;
551
+ /**
552
+ * Indicate that random strings should be created normally and not using a custom factory.
553
+ *
554
+ * @returns void
555
+ *
556
+ * @example
557
+ *
558
+ * createRandomStringsNormally();
559
+ */
560
+ export declare function createRandomStringsNormally(): void;
561
+ /**
562
+ * Repeat the given string.
563
+ *
564
+ * @param string - The string to repeat
565
+ * @param times - The number of times to repeat the string
566
+ * @returns The repeated string
567
+ *
568
+ * @example
569
+ *
570
+ * repeat("foo", 3); -> "foofoofoo"
571
+ */
572
+ export declare function repeat(string: string, times: number): string;
573
+ /**
574
+ * Replace a given value in the string sequentially with an array.
575
+ *
576
+ * @param search - The value to search for
577
+ * @param replace - The array or record of replacements
578
+ * @param subject - The string to perform replacements on
579
+ * @returns The resulting string after replacements
580
+ *
581
+ * @example
582
+ *
583
+ * replaceArray('?', ['foo', 'bar', 'baz'], '?/?/?'); -> 'foo/bar/baz'
584
+ * replaceArray('?', ['foo', 'bar', 'baz'], '?/?/?/?'); -> 'foo/bar/baz/?'
585
+ * replaceArray('?', {'x' => 'foo', 'y' => 'bar'}, '?/?'); -> 'foo/bar'
586
+ */
587
+ export declare function replaceArray(search: string, replace: Record<string, string> | Iterable<string>, subject: string): string;
588
+ /**
589
+ * Convert the given value to a string or return the given fallback on failure.
590
+ *
591
+ * @param value - The value to convert
592
+ * @param fallback - The fallback string to return on failure
593
+ * @returns The converted string or the fallback
594
+ *
595
+ * @example
596
+ *
597
+ * toStringOr(123);
598
+ */
599
+ export declare function toStringOr(value: unknown, fallback: string): string;
600
+ /**
601
+ * Replace the given value in the given string.
602
+ *
603
+ * @param search - The value or values to search for
604
+ * @param replacement - The value or values to replace with
605
+ * @param subject - The string or array of strings to perform replacements on
606
+ * @param caseSensitive - Whether the search should be case-sensitive (default: true)
607
+ * @returns The resulting string or array of strings after replacements
608
+ *
609
+ * @example
610
+ *
611
+ * replace("foo", "bar", "foo baz"); -> "bar baz"
612
+ */
613
+ export declare function replace<T extends string | Iterable<string>>(search: string | Iterable<string>, replacement: string | Iterable<string>, subject: T, caseSensitive?: boolean): T extends string ? string : string[];
614
+ /**
615
+ * Replace the first occurrence of a given value in the string.
616
+ *
617
+ * @param search - The value to search for
618
+ * @param replace - The value to replace with
619
+ * @param subject - The string to perform the replacement on
620
+ * @returns The resulting string after replacement
621
+ *
622
+ * @example
623
+ *
624
+ * replaceFirst('bar', 'qux', 'foobar foobar'); -> 'fooqux foobar'
625
+ */
626
+ export declare function replaceFirst(search: string | number, replace: string, subject: string): string;
627
+ /**
628
+ * Replace the first occurrence of the given value if it appears at the start of the string.
629
+ *
630
+ * @param search - The value to search for
631
+ * @param replace - The value to replace with
632
+ * @param subject - The string to perform the replacement on
633
+ * @returns The resulting string after replacement
634
+ */
635
+ export declare function replaceStart(search: string | number, replace: string, subject: string): string;
636
+ /**
637
+ * Replace the last occurrence of a given value in the string.
638
+ *
639
+ * @param search - The value to search for
640
+ * @param replace - The value to replace with
641
+ * @param subject - The string to perform the replacement on
642
+ * @returns The resulting string after replacement
643
+ *
644
+ * @example
645
+ *
646
+ * replaceLast('bar', 'qux', 'foobar foobar'); -> 'foobar foobarqux'
647
+ */
648
+ export declare function replaceLast(search: string | number, replace: string, subject: string): string;
649
+ /**
650
+ * Replace the last occurrence of a given value if it appears at the end of the string.
651
+ *
652
+ * @param search - The value to search for
653
+ * @param replace - The value to replace with
654
+ * @param subject - The string to perform the replacement on
655
+ * @returns The resulting string after replacement
656
+ *
657
+ * @example
658
+ *
659
+ * replaceEnd('bar', 'qux', 'foobar foobar'); -> 'foobar fooqux'
660
+ */
661
+ export declare function replaceEnd(search: string | number, replace: string, subject: string): string;
662
+ /**
663
+ * Replace the patterns matching the given regular expression.
664
+ *
665
+ * @param pattern - The regex pattern or patterns to search for
666
+ * @param replace - The replacement string, array of strings, or function
667
+ * @param subject - The string or array of strings to perform replacements on
668
+ * @param limit - The maximum number of replacements per pattern (-1 for no limit)
669
+ * @returns The resulting string, array of strings, or null on error
670
+ *
671
+ * @example
672
+ *
673
+ * replaceMatches(/foo/, 'bar', 'foobar'); -> 'barbar'
674
+ * replaceMatches(/foo/, ['bar', 'baz'], 'foobar'); -> ['barbar', 'foobaz']
675
+ * replaceMatches(/foo/, (match) => match[1]!.toUpperCase(), 'foobar'); -> 'Bar'
676
+ */
677
+ export declare function replaceMatches(pattern: string | string[] | RegExp | RegExp[], replace: string | string[] | ((match: string[]) => string), subject: string | string[], limit?: number): string | string[] | null;
678
+ /**
679
+ * Strip HTML tags from a string.
680
+ *
681
+ * @param value - The string to process
682
+ * @returns The string with HTML tags removed
683
+ *
684
+ * @example
685
+ *
686
+ * stripTags("<p>Hello World</p>"); -> "Hello World"
687
+ */
688
+ export declare function stripTags(value: string): string;
689
+ /**
690
+ * Remove any occurrence of the given string in the subject.
691
+ *
692
+ * @param search - The string or strings to remove
693
+ * @param subject - The string or strings to process
694
+ * @param caseSensitive - Whether the search should be case-sensitive (default: true)
695
+ * @returns The resulting string or array of strings after removal
696
+ *
697
+ * @example
698
+ *
699
+ * remove("foo", "foobar"); -> "bar"
700
+ * remove(["foo", "bar"], "foobar"); -> ""
701
+ */
702
+ export declare function remove(search: string | Iterable<string>, subject: string | Iterable<string>, caseSensitive?: boolean): string | string[];
703
+ /**
704
+ * Reverse the given string.
705
+ *
706
+ * @param value - The string to reverse
707
+ * @returns The reversed string
708
+ *
709
+ * @example
710
+ *
711
+ * reverse("hello"); -> "olleh"
712
+ * reverse("world"); -> "dlrow"
713
+ * reverse(""); -> ""
714
+ */
715
+ export declare function reverse(value: string): string;
716
+ /**
717
+ * Begin a string with a single instance of a given value.
718
+ *
719
+ * @param value - The string to process
720
+ * @param prefix - The prefix to ensure at the start
721
+ * @returns The resulting string starting with the prefix
722
+ *
723
+ * @example
724
+ *
725
+ * start("test/string", "/"); -> "/test/string"
726
+ * start("/test/string", "/"); -> "/test/string"
727
+ * start("//test/string", "/"); -> "/test/string"
728
+ */
729
+ export declare function start(value: string, prefix: string): string;
730
+ /**
731
+ * Convert the given string to proper case for each word.
732
+ *
733
+ * @param value - The string to convert
734
+ * @returns The converted string in headline case
735
+ *
736
+ * @example
737
+ *
738
+ * headline("foo bar baz"); -> "Foo Bar Baz"
739
+ * headline("foO bAr BaZ"); -> "Foo Bar Baz"
740
+ */
741
+ export declare function headline(value: string): string;
742
+ /**
743
+ * Convert the given string to APA-style title case.
744
+ *
745
+ * @param value - The string to convert
746
+ * @returns The converted string in APA title case
747
+ *
748
+ * @see https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case
749
+ *
750
+ * @example
751
+ *
752
+ * apa("foo bar baz"); -> "Foo Bar Baz"
753
+ * apa("foO bAr BaZ"); -> "Foo Bar Baz"
754
+ */
755
+ export declare function apa(value: string): string;
756
+ /**
757
+ * Convert a string to snake case.
758
+ *
759
+ * @param value - The string to convert
760
+ * @param delimiter - The word delimiter to use (default: "_")
761
+ * @returns The converted string in snake case
762
+ */
763
+ export declare function snake(value: string, delimiter?: string): string;
764
+ /**
765
+ * Remove all "extra" blank space from the given string.
766
+ *
767
+ * @param value - The string to process
768
+ * @returns The resulting string with extra spaces removed
769
+ *
770
+ * @example
771
+ *
772
+ * squish(`
773
+ foo
774
+ bar
775
+ `); -> "foo bar"
776
+ */
777
+ export declare function squish(value: string): string;
778
+ /**
779
+ * Determine if a given string starts with a given substring.
780
+ *
781
+ * @param haystack - The string to search in
782
+ * @param needles - The substring or substrings to search for
783
+ * @returns True if the haystack starts with any of the needles, false otherwise
784
+ *
785
+ * @example
786
+ *
787
+ * startsWith("hello world", "hello"); -> true
788
+ * startsWith("hello world", "world"); -> false
789
+ */
790
+ export declare function startsWith(haystack: string | number | null, needles: string | number | null | Iterable<string | number | null>): boolean;
791
+ /**
792
+ * Determine if a given string doesn't start with a given substring.
793
+ *
794
+ * @param haystack - The string to search in
795
+ * @param needles - The substring or substrings to search for
796
+ * @returns True if the haystack doesn't start with any of the needles, false otherwise
797
+ *
798
+ * @example
799
+ *
800
+ * expect(doesntStartWith("jason", ["day"])).toBe(true);
801
+ */
802
+ export declare function doesntStartWith(haystack: string | number | null, needles: string | number | null | Iterable<string | number | null>): boolean;
803
+ /**
804
+ * Convert a value to studly caps case.
805
+ *
806
+ * @param value - The string to convert
807
+ * @returns The converted string in studly caps case
808
+ *
809
+ * @example
810
+ *
811
+ * studly("fooBar"); -> "FooBar"
812
+ * studly("foo_bar"); -> "FooBar"
813
+ * studly("foo-barBaz"); -> "FooBarBaz"
814
+ */
815
+ export declare function studly(value: string): string;
816
+ /**
817
+ * Convert a value to Pascal case.
818
+ *
819
+ * @param value - The string to convert
820
+ * @returns The converted string in Pascal case
821
+ */
822
+ export declare function pascal(value: string): string;
823
+ /**
824
+ * Swap multiple keywords in a string with other keywords.
825
+ *
826
+ * @param map - The record of replacements
827
+ * @param subject - The string to perform replacements on
828
+ * @returns The resulting string after replacements
829
+ *
830
+ * @example
831
+ *
832
+ * swap(
833
+ * {
834
+ * 'foo': 'bar',
835
+ * 'baz': 'qux',
836
+ * },
837
+ * 'foo baz'
838
+ * ); -> 'bar qux'
839
+ */
840
+ export declare function swap(map: Record<string, string>, subject: string): string;
841
+ /**
842
+ * Take the first or last {$limit} characters of a string.
843
+ *
844
+ * @param value - The string to process
845
+ * @param limit - The number of characters to take (negative for from end)
846
+ * @returns The resulting substring
847
+ *
848
+ * @example
849
+ *
850
+ * take("hello world", 5); -> "hello"
851
+ * take("hello world", -5); -> "world"
852
+ */
853
+ export declare function take(value: string, limit: number): string;
854
+ /**
855
+ * Make a string's first character lowercase.
856
+ *
857
+ * @param value - The string to process
858
+ * @returns The resulting string with the first character in lowercase
859
+ *
860
+ * @example
861
+ *
862
+ * lcfirst('Hello World'); -> 'hello World'
863
+ */
864
+ export declare function lcfirst(value: string): string;
865
+ /**
866
+ * Make a string's first character uppercase.
867
+ *
868
+ * @param value - The string to process
869
+ * @returns The resulting string with the first character in uppercase
870
+ *
871
+ * @example
872
+ *
873
+ * ucfirst('hello world'); -> 'Hello world'
874
+ */
875
+ export declare function ucfirst(value: string): string;
876
+ /**
877
+ * Split a string into pieces by uppercase characters.
878
+ *
879
+ * @param value - The string to split
880
+ * @returns An array of string segments split at uppercase characters
881
+ *
882
+ * @example
883
+ *
884
+ * ucsplit('laravelPHPFramework'); -> ['laravel', 'P', 'H', 'P', 'Framework']
885
+ * ucsplit('Laravel-phP-framework'); -> ['Laravel-ph', 'P-framework']
886
+ * ucsplit('ÖffentlicheÜberraschungen'); -> ['Öffentliche', 'Überraschungen']
887
+ */
888
+ export declare function ucsplit(value: string): string[];
889
+ /**
890
+ * Uppercase the first letter of each word in a string.
891
+ *
892
+ * @param value - The string to process
893
+ * @param separators - The word separators to use (default: whitespace characters)
894
+ * @returns The resulting string with each word capitalized
895
+ *
896
+ * @example
897
+ *
898
+ * ucwords('hello world'); -> 'Hello World'
899
+ * ucwords('laravel php framework'); -> 'Laravel Php Framework'
900
+ * ucwords('Öffentliche Überraschungen'); -> 'Öffentliche Überraschungen'
901
+ */
902
+ export declare function ucwords(value: string, separators?: string | string[]): string;
903
+ /**
904
+ * Get the number of words a string contains.
905
+ *
906
+ * @param value - The string to analyze
907
+ * @param characters - Additional characters to consider as part of words
908
+ * @returns The word count in the string
909
+ *
910
+ * @example
911
+ *
912
+ * wordCount('Hello, world!'); -> 2
913
+ * wordCount('мама мыла раму'); -> 3
914
+ */
915
+ export declare function wordCount(value: string, characters?: string | null): number;
916
+ /**
917
+ * Wrap a string to a given number of characters.
918
+ *
919
+ * @param value - The string to wrap
920
+ * @param characters - The maximum number of characters per line (default: 75)
921
+ * @param breakStr - The string to insert as a line break (default: "\n")
922
+ * @param cutLongWords - Whether to cut words longer than the limit (default: false)
923
+ * @returns The resulting wrapped string
924
+ *
925
+ * @example
926
+ *
927
+ * wordWrap("Hello World", 3, "<br />"); -> "Hello<br />World"
928
+ * wordWrap("Hello World", 3, "<br />", true); -> "Hel<br />lo<br />Wor<br />ld"
929
+ * wordWrap("❤Multi Byte☆❤☆❤☆❤", 3, "<br />"); -> "❤Multi<br />Byte☆❤☆❤☆❤"
930
+ */
931
+ export declare function wordWrap(value: string, characters?: number, breakStr?: string, cutLongWords?: boolean): string;
932
+ /**
933
+ * Get the size of the snake cache.
934
+ *
935
+ * @returns The size of the snake cache
936
+ *
937
+ * @example
938
+ *
939
+ * snakeCacheSize();
940
+ */
941
+ export declare function snakeCacheSize(): number;
942
+ /**
943
+ * Get the size of the camel cache.
944
+ *
945
+ * @returns The size of the camel cache
946
+ *
947
+ * @example
948
+ *
949
+ * camelCacheSize();
950
+ */
951
+ export declare function camelCacheSize(): number;
952
+ /**
953
+ * Get the size of the studly cache.
954
+ *
955
+ * @returns The size of the studly cache
956
+ *
957
+ * @example
958
+ *
959
+ * studlyCacheSize();
960
+ */
961
+ export declare function studlyCacheSize(): number;
962
+ /**
963
+ * Remove all strings from the casing caches.
964
+ *
965
+ * @returns void
966
+ */
967
+ export declare function flushCache(): void;
968
+ //# sourceMappingURL=str.d.ts.map