@tolki/str 1.7.0 → 1.8.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.
@@ -1,1337 +1,470 @@
1
- import { isInteger as v, isFunction as a } from "@tolki/utils";
2
- import { ascii as p, slug as d } from "../ascii/index.js";
3
- import { toBase64 as m, fromBase64 as f } from "../base64/index.js";
4
- import { convertCase as _, upper as E, title as y } from "../convertcase/index.js";
5
- import { markdown as A, inlineMarkdown as W } from "../markdown/index.js";
6
- import { counted as x, plural as k, pluralStudly as I, pluralPascal as N, singular as U } from "../pluralizer/index.js";
7
- import { substr as C, substrCount as L, substrReplace as M } from "../replacer/index.js";
8
- import { after as F, afterLast as R, before as B, beforeLast as j, between as T, betweenFirst as D, camel as q, charAt as O, chopStart as P, chopEnd as $, contains as J, containsAll as V, doesntContain as z, deduplicate as G, endsWith as X, doesntEndWith as H, excerpt as K, finish as Q, is as Y, isAscii as Z, isJson as g, isUrl as b, kebab as S, length as ee, limit as te, lower as o, mask as re, match as se, isMatch as ne, matchAll as ue, numbers as ie, padBoth as he, padLeft as le, padRight as ae, position as oe, remove as we, reverse as ce, repeat as ve, replace as pe, replaceArray as de, replaceFirst as me, replaceStart as fe, replaceLast as _e, replaceEnd as Ee, replaceMatches as ye, squish as Ae, start as We, stripTags as xe, headline as ke, initials as Ie, apa as Ne, snake as Ue, startsWith as Ce, doesntStartWith as Le, studly as Me, pascal as Fe, swap as Re, take as Be, lcfirst as je, ucfirst as Te, ucsplit as De, ucwords as qe, words as Oe, wordCount as Pe, wordWrap as $e, wrap as Je, unwrap as Ve } from "../str.js";
1
+ import { convertCase as e, title as t, upper as n } from "../convertcase/index.js";
2
+ import { fromBase64 as r, toBase64 as i } from "../base64/index.js";
3
+ import { substr as ee, substrCount as a, substrReplace as te } from "../replacer/index.js";
4
+ import { ltrim as ne, rtrim as re, trim as o } from "../trimmer/index.js";
5
+ import { isUlid as ie } from "../ulid/index.js";
6
+ import { isUuid as ae } from "../uuid/index.js";
7
+ import { after as s, afterLast as c, apa as l, before as u, beforeLast as d, between as f, betweenFirst as p, camel as m, charAt as h, chopEnd as g, chopStart as _, contains as v, containsAll as y, deduplicate as b, doesntContain as x, doesntEndWith as S, doesntStartWith as C, endsWith as w, excerpt as T, finish as E, headline as D, initials as O, is as k, isAscii as A, isJson as j, isMatch as M, isUrl as N, kebab as P, lcfirst as F, length as I, limit as L, lower as R, mask as z, match as B, matchAll as V, numbers as H, padBoth as U, padLeft as W, padRight as G, pascal as K, position as q, remove as J, repeat as oe, replace as se, replaceArray as ce, replaceEnd as le, replaceFirst as ue, replaceLast as de, replaceMatches as fe, replaceStart as pe, reverse as me, snake as he, squish as ge, start as _e, startsWith as ve, stripTags as ye, studly as be, swap as xe, take as Se, ucfirst as Ce, ucsplit as we, ucwords as Te, unwrap as Ee, wordCount as De, wordWrap as Oe, words as ke, wrap as Ae } from "../str.js";
8
+ import { ascii as je, slug as Me } from "../ascii/index.js";
9
+ import { inlineMarkdown as Ne, markdown as Pe } from "../markdown/index.js";
10
+ import { counted as Fe, plural as Ie, pluralPascal as Le, pluralStudly as Re, singular as Y } from "../pluralizer/index.js";
9
11
  import { transliterate as ze } from "../transliterate/index.js";
10
- import { trim as w, ltrim as Ge, rtrim as Xe } from "../trimmer/index.js";
11
- import { isUlid as He } from "../ulid/index.js";
12
- import { isUuid as Ke } from "../uuid/index.js";
13
- function at(i = "") {
14
- return new r(i);
12
+ import { isFunction as X, isInteger as Be } from "@tolki/utils";
13
+ // src/stringable/index.ts
14
+ function Z(e = "") {
15
+ return new $(e);
15
16
  }
16
- function ot(i = "") {
17
- return new r(i);
17
+ function Ve(e = "") {
18
+ return new $(e);
18
19
  }
19
- function Qe(i, e) {
20
- const t = l(i, 0), s = t.slice(t.lastIndexOf("/") + 1);
21
- return e !== "" && s !== e && s.endsWith(e) ? s.slice(0, -e.length) : s;
20
+ function He(e, t) {
21
+ let n = Q(e, 0), r = n.slice(n.lastIndexOf("/") + 1);
22
+ return t !== "" && r !== t && r.endsWith(t) ? r.slice(0, -t.length) : r;
22
23
  }
23
- function Ye(i, e) {
24
- if (e < 1)
25
- throw new RangeError(
26
- "dirname(): Argument #2 ($levels) must be greater than or equal to 1"
27
- );
28
- let t = i;
29
- for (let s = 0; s < e; s += 1) {
30
- const n = Ze(t);
31
- if (n === t)
32
- return n;
33
- t = n;
34
- }
35
- return t;
24
+ function Ue(e, t) {
25
+ if (t < 1) throw RangeError("dirname(): Argument #2 ($levels) must be greater than or equal to 1");
26
+ let n = e;
27
+ for (let e = 0; e < t; e += 1) {
28
+ let e = We(n);
29
+ if (e === n) return e;
30
+ n = e;
31
+ }
32
+ return n;
36
33
  }
37
- function Ze(i) {
38
- if (i === "")
39
- return "";
40
- const e = l(i, 1);
41
- if (e === "/")
42
- return "/";
43
- const t = e.lastIndexOf("/");
44
- if (t === -1)
45
- return ".";
46
- const s = l(e.slice(0, t), 1);
47
- return s === "" ? "/" : s;
34
+ function We(e) {
35
+ if (e === "") return "";
36
+ let t = Q(e, 1);
37
+ if (t === "/") return "/";
38
+ let n = t.lastIndexOf("/");
39
+ if (n === -1) return ".";
40
+ let r = Q(t.slice(0, n), 1);
41
+ return r === "" ? "/" : r;
48
42
  }
49
- function l(i, e) {
50
- let t = i.length;
51
- for (; t > e && i[t - 1] === "/"; )
52
- t -= 1;
53
- return i.slice(0, t);
43
+ function Q(e, t) {
44
+ let n = e.length;
45
+ for (; n > t && e[n - 1] === "/";) --n;
46
+ return e.slice(0, n);
54
47
  }
55
- class r {
56
- /**
57
- * Create a new instance of the class.
58
- *
59
- * @param _value - The initial string value. Defaults to an empty string.
60
- */
61
- constructor(e = "") {
62
- this._value = e;
63
- }
64
- _value;
65
- /**
66
- * Return the remainder of a string after the first occurrence of a given value.
67
- *
68
- * @param search - The substring to search for.
69
- * @returns The portion of the string after the first occurrence of the search value.
70
- */
71
- after(e) {
72
- return new r(F(this._value, e));
73
- }
74
- /**
75
- * Return the remainder of a string after the last occurrence of a given value
76
- *
77
- * @param search - The substring to search for.
78
- * @returns The portion of the string after the last occurrence of the search value.
79
- */
80
- afterLast(e) {
81
- return new r(R(this._value, e));
82
- }
83
- /**
84
- * Append the given values to the string.
85
- *
86
- * @param values - The values to append to the string.
87
- * @returns The updated Stringable instance.
88
- */
89
- append(...e) {
90
- return new r(this._value + e.map(String).join(""));
91
- }
92
- /**
93
- * Append a new line to the string.
94
- *
95
- * @param count - The number of new lines to append. Defaults to 1.
96
- * @returns The updated Stringable instance.
97
- */
98
- newLine(e = 1) {
99
- return this.append(`
100
- `.repeat(Math.max(0, e)));
101
- }
102
- /**
103
- * Transliterate a UTF-8 value to ASCII.
104
- *
105
- * @returns The transliterated string as a new Stringable instance.
106
- */
107
- ascii() {
108
- return new r(p(this._value));
109
- }
110
- /**
111
- * Get the trailing name component of the path.
112
- *
113
- * @param suffix - Removed from the end of the name unless it is the whole name.
114
- * @returns The trailing name component as a new Stringable instance.
115
- */
116
- basename(e = "") {
117
- return new r(Qe(this._value, e));
118
- }
119
- /**
120
- * Get the portion of a string before the first occurrence of a given value.
121
- *
122
- * @param search - The substring to search for.
123
- * @returns The portion of the string before the first occurrence of the search value.
124
- */
125
- before(e) {
126
- return new r(B(this._value, e));
127
- }
128
- /**
129
- * Get the portion of a string before the last occurrence of a given value.
130
- *
131
- * @param search - The substring to search for.
132
- * @returns The portion of the string before the last occurrence of the search value.
133
- */
134
- beforeLast(e) {
135
- return new r(j(this._value, e));
136
- }
137
- /**
138
- * Get the portion of a string between two given values.
139
- *
140
- * @param from - The starting substring.
141
- * @param to - The ending substring.
142
- * @returns The portion of the string between the two given values.
143
- */
144
- between(e, t) {
145
- return new r(T(this._value, e, t));
146
- }
147
- /**
148
- * Get the smallest possible portion of a string between two given values.
149
- *
150
- * @param from - The starting substring.
151
- * @param to - The ending substring.
152
- * @returns The smallest possible portion of the string between the two given values.
153
- */
154
- betweenFirst(e, t) {
155
- return new r(D(this._value, e, t));
156
- }
157
- /**
158
- * Convert a value to camel case.
159
- *
160
- * @returns The camel-cased string as a new Stringable instance.
161
- */
162
- camel() {
163
- return new r(q(this._value));
164
- }
165
- /**
166
- * Get the character at the specified index.
167
- *
168
- * @param index - The index of the character to retrieve.
169
- * @returns The character at the specified index, or false if the index is out of bounds.
170
- */
171
- charAt(e) {
172
- return O(this._value, e);
173
- }
174
- /**
175
- * Remove the given string if it exists at the start of the current string.
176
- *
177
- * @param needle - The string or array of strings to remove from the start.
178
- * @returns The updated Stringable instance.
179
- */
180
- chopStart(e) {
181
- return new r(P(this._value, e));
182
- }
183
- /**
184
- * Remove the given string if it exists at the end of the current string.
185
- *
186
- * @param needle - The string or array of strings to remove from the end.
187
- * @returns The updated Stringable instance.
188
- */
189
- chopEnd(e) {
190
- return new r($(this._value, e));
191
- }
192
- /**
193
- * Determine if a given string contains a given substring.
194
- *
195
- * @param needles - The substring(s) to search for
196
- * @param ignoreCase - Whether the search should be case-insensitive
197
- * @returns boolean - True if the substring(s) are found, false otherwise
198
- */
199
- contains(e, t = !1) {
200
- return J(this._value, e, t);
201
- }
202
- /**
203
- * Determine if a given string contains all array values.
204
- *
205
- * @param needles - The substring(s) to search for
206
- * @param ignoreCase - Whether the search should be case-insensitive
207
- * @returns boolean - True if all substring(s) are found, false otherwise
208
- */
209
- containsAll(e, t = !1) {
210
- return V(this._value, e, t);
211
- }
212
- /**
213
- * Determine if a given string doesn't contain a given substring.
214
- *
215
- * @param needles - The substring(s) to search for
216
- * @param ignoreCase - Whether the search should be case-insensitive
217
- * @returns boolean - True if the substring(s) are not found, false otherwise
218
- */
219
- doesntContain(e, t = !1) {
220
- return z(this._value, e, t);
221
- }
222
- /**
223
- * Convert the case of a string.
224
- *
225
- * @param mode - The case conversion mode to apply.
226
- * @returns The converted string as a new Stringable instance.
227
- */
228
- convertCase(e) {
229
- return new r(_(this._value, e));
230
- }
231
- /**
232
- * Get the plural form of an English word with the count prepended.
233
- *
234
- * @param count - The count to determine pluralization. Arrays are counted by length.
235
- * @returns The pluralized string with the formatted count prepended, as a new Stringable instance.
236
- */
237
- counted(e) {
238
- return new r(x(this._value, e));
239
- }
240
- /**
241
- * Replace consecutive instances of a given character with a single character.
242
- *
243
- * @param character - The character or array of characters to deduplicate. Defaults to a space.
244
- * @returns The updated Stringable instance.
245
- */
246
- deduplicate(e = " ") {
247
- return new r(G(this._value, e));
248
- }
249
- /**
250
- * Get the parent directory's path.
251
- *
252
- * @param levels - How many parent directories to go up. Defaults to 1.
253
- * @returns The parent directory's path as a new Stringable instance.
254
- */
255
- dirname(e = 1) {
256
- return new r(Ye(this._value, e));
257
- }
258
- /**
259
- * Determine if a given string ends with a given substring.
260
- *
261
- * @param needles - The substring(s) to search for
262
- * @returns boolean - True if the substring(s) are found, false otherwise
263
- */
264
- endsWith(e) {
265
- return X(this._value, e);
266
- }
267
- /**
268
- * Determine if a given string doesn't end with a given substring.
269
- *
270
- * @param needles - The substring(s) to search for
271
- * @returns boolean - True if the substring(s) are not found, false otherwise
272
- */
273
- doesntEndWith(e) {
274
- return H(this._value, e);
275
- }
276
- /**
277
- * Determine if the string is an exact match with the given value.
278
- *
279
- * @param value - The value to compare against.
280
- * @returns True if the strings are exactly the same, false otherwise.
281
- */
282
- exactly(e) {
283
- const t = e instanceof r ? e.toString() : String(e);
284
- return this._value === t;
285
- }
286
- /**
287
- * Extracts an excerpt from text that matches the first instance of a phrase.
288
- *
289
- * @param phrase - The phrase to search for within the text.
290
- * @param options - Options to customize the excerpt extraction, including radius and omission string.
291
- * @returns The extracted excerpt or null if the phrase is not found.
292
- */
293
- excerpt(e = "", t = {}) {
294
- return K(this._value, e, t);
295
- }
296
- /**
297
- * Explode the string into an array
298
- *
299
- * @param delimiter - The delimiter string to split the string by.
300
- * @param limit - The maximum number of elements to return. Defaults to Number.MAX_SAFE_INTEGER.
301
- * @returns An array of strings obtained by splitting the original string.
302
- */
303
- explode(e, t = Number.MAX_SAFE_INTEGER) {
304
- const s = this._value.split(e);
305
- if (t > 0 && s.length > t) {
306
- const n = s.slice(0, t - 1);
307
- return n.push(s.slice(t - 1).join(e)), n;
308
- } else if (t < 0)
309
- return s.slice(0, t);
310
- return s;
311
- }
312
- /**
313
- * Split a string using a regular expression or by length.
314
- *
315
- * @param pattern - The regex pattern or length to split the string by.
316
- * @param limit - The maximum number of splits to perform. Defaults to null (no limit).
317
- * @returns An array of strings obtained by splitting the original string.
318
- */
319
- split(e, t = null) {
320
- if (v(e)) {
321
- const n = Number(e), h = [];
322
- for (let u = 0; u < this._value.length; u += n)
323
- h.push(this._value.substr(u, n));
324
- return h;
325
- }
326
- return this._value.split(
327
- new RegExp(String(e)),
328
- t ?? void 0
329
- );
330
- }
331
- /**
332
- * Cap a string with a single instance of a given value.
333
- *
334
- * @param cap - The string to cap the original string with.
335
- * @returns The updated Stringable instance.
336
- */
337
- finish(e) {
338
- return new r(Q(this._value, e));
339
- }
340
- /**
341
- * Determine if a given string matches a given pattern.
342
- *
343
- * @param pattern - The pattern(s) to match against
344
- * @returns boolean - True if the pattern(s) match, false otherwise
345
- */
346
- is(e, t = !1) {
347
- return Y(e, this._value, t);
348
- }
349
- /**
350
- * Determine if a given string is 7 bit ASCII.
351
- *
352
- * @returns True if the string is ASCII, false otherwise.
353
- */
354
- isAscii() {
355
- return Z(this._value);
356
- }
357
- /**
358
- * Determine if a given string is valid JSON.
359
- *
360
- * @returns True if the string is valid JSON, false otherwise.
361
- */
362
- isJson() {
363
- return g(this._value);
364
- }
365
- /**
366
- * Determine if a given value is a valid URL.
367
- *
368
- * @param protocols - An array of allowed protocols (e.g., ['http', 'https']).
369
- * @returns True if the string is a valid URL, false otherwise.
370
- */
371
- isUrl(e = []) {
372
- return b(this._value, e);
373
- }
374
- /**
375
- * Determine if a given string is a valid UUID.
376
- *
377
- * @param version - The UUID version to validate against (1-5), "nil", "max", or null for any version.
378
- * @returns True if the string is a valid UUID, false otherwise.
379
- */
380
- isUuid(e = null) {
381
- return Ke(this._value, e);
382
- }
383
- /**
384
- * Determine if a given string is a valid ULID.
385
- *
386
- * @return True if the string is a valid ULID, false otherwise.
387
- */
388
- isUlid() {
389
- return He(this._value);
390
- }
391
- /**
392
- * Determine if the given string is empty.
393
- *
394
- * @return True if the string is empty, false otherwise.
395
- */
396
- isEmpty() {
397
- return this._value === "";
398
- }
399
- /**
400
- * Determine if the given string is not empty.
401
- *
402
- * @return True if the string is not empty, false otherwise.
403
- */
404
- isNotEmpty() {
405
- return !this.isEmpty();
406
- }
407
- /**
408
- * Convert a string to kebab case.
409
- *
410
- * @returns The kebab-cased string as a new Stringable instance.
411
- */
412
- kebab() {
413
- return new r(S(this._value));
414
- }
415
- /**
416
- * Return the length of the given string.
417
- *
418
- * @returns The length of the string.
419
- */
420
- length() {
421
- return ee(this._value);
422
- }
423
- /**
424
- * Limit the number of characters in a string.
425
- *
426
- * @param limitValue - The maximum number of characters allowed.
427
- * @param end - The string to append if the original string exceeds the limit.
428
- * @param preserveWords - Whether to avoid cutting off in the middle of a word.
429
- * @returns A new Stringable instance with the limited string.
430
- */
431
- limit(e = 100, t = "...", s = !1) {
432
- return new r(
433
- te(this._value, e, t, s)
434
- );
435
- }
436
- /**
437
- * Convert the given string to lower-case.
438
- *
439
- * @returns The lower-cased string as a new Stringable instance.
440
- */
441
- lower() {
442
- return new r(o(this._value));
443
- }
444
- /**
445
- * Convert GitHub flavored Markdown into HTML.
446
- *
447
- * @param options - Options to customize the markdown rendering. Defaults to GFM enabled and no anchors.
448
- * @param extensions - An array of markdown-it extensions to apply during rendering.
449
- * @returns The resulting HTML string as a new Stringable instance.
450
- */
451
- markdown(e = { gfm: !0, anchors: !1 }, t = []) {
452
- return new r(A(this._value, e, t));
453
- }
454
- /**
455
- * Convert inline Markdown into HTML.
456
- *
457
- * @param options - Options to customize the markdown rendering. Defaults to GFM enabled.
458
- * @param extensions - An array of markdown-it extensions to apply during rendering.
459
- * @returns The resulting HTML string as a new Stringable instance.
460
- */
461
- inlineMarkdown(e = { gfm: !0 }, t = []) {
462
- return new r(W(this._value, e, t));
463
- }
464
- /**
465
- * Masks a portion of a string with a repeated character.
466
- *
467
- * @param character - The character to use for masking.
468
- * @param index - The starting index to begin masking.
469
- * @param length - The number of characters to mask. If null, masks to the end of the string.
470
- * @returns The masked string as a new Stringable instance.
471
- */
472
- mask(e, t, s = null) {
473
- return new r(re(this._value, e, t, s));
474
- }
475
- /**
476
- * Get the string matching the given pattern.
477
- *
478
- * @param pattern - The pattern to match against.
479
- * @returns A new Stringable instance containing the matched string.
480
- */
481
- match(e) {
482
- return new r(se(e, this._value));
483
- }
484
- /**
485
- * Determine if a given string matches a given pattern.
486
- *
487
- * @param pattern - The pattern(s) to match against
488
- * @returns boolean - True if the pattern(s) match, false otherwise
489
- */
490
- isMatch(e) {
491
- return ne(e, this._value);
492
- }
493
- /**
494
- * Get the string matching the given pattern.
495
- *
496
- * @param pattern - The pattern to match against.
497
- * @returns An array of all matched strings.
498
- */
499
- matchAll(e) {
500
- return ue(e, this._value);
501
- }
502
- /**
503
- * Determine if the string matches the given pattern.
504
- *
505
- * @param pattern - The pattern(s) to match against
506
- * @returns boolean - True if the pattern(s) match, false otherwise
507
- */
508
- test(e) {
509
- return this.isMatch(e);
510
- }
511
- /**
512
- * Remove all non-numeric characters from a string.
513
- *
514
- * @returns The numeric string as a new Stringable instance.
515
- */
516
- numbers() {
517
- return new r(ie(this._value));
518
- }
519
- /**
520
- * Pad both sides of the string with another.
521
- *
522
- * @param length - The desired total length of the string after padding.
523
- * @param pad - The string to use for padding. Defaults to a space.
524
- * @returns The padded string as a new Stringable instance.
525
- */
526
- padBoth(e, t = " ") {
527
- return new r(he(this._value, e, t));
528
- }
529
- /**
530
- * Pad the left side of the string with another.
531
- *
532
- * @param length - The desired total length of the string after padding.
533
- * @param pad - The string to use for padding. Defaults to a space.
534
- * @returns The padded string as a new Stringable instance.
535
- */
536
- padLeft(e, t = " ") {
537
- return new r(le(this._value, e, t));
538
- }
539
- /**
540
- * Pad the right side of the string with another.
541
- *
542
- * @param length - The desired total length of the string after padding.
543
- * @param pad - The string to use for padding. Defaults to a space.
544
- * @returns The padded string as a new Stringable instance.
545
- */
546
- padRight(e, t = " ") {
547
- return new r(ae(this._value, e, t));
548
- }
549
- /**
550
- * Call the given callback and return a new string.
551
- *
552
- * @param callback - The callback function to process the string.
553
- * @returns The processed string as a new Stringable instance.
554
- */
555
- pipe(e) {
556
- const t = e(this);
557
- return t instanceof r ? t : new r(String(t));
558
- }
559
- /**
560
- * Get the plural form of an English word.
561
- *
562
- * @param count - The count to determine singular or plural form. Arrays are counted by length. Defaults to 2.
563
- * @param prependCount - Whether to prepend the count to the result. Defaults to false.
564
- * @returns The pluralized string as a new Stringable instance.
565
- */
566
- plural(e = 2, t = !1) {
567
- return new r(k(this._value, e, t));
568
- }
569
- /**
570
- * Pluralize the last word of an English, studly caps case string.
571
- *
572
- * @param count - The count to determine singular or plural form. Defaults to 2.
573
- * @returns The pluralized string as a new Stringable instance.
574
- */
575
- pluralStudly(e = 2) {
576
- return new r(I(this._value, e));
577
- }
578
- /**
579
- * Pluralize the last word of an English, Pascal caps case string.
580
- *
581
- * @param count - The count to determine singular or plural form. Defaults to 2.
582
- * @returns The pluralized string as a new Stringable instance.
583
- */
584
- pluralPascal(e = 2) {
585
- return new r(N(this._value, e));
586
- }
587
- /**
588
- * Find the multi-byte safe position of the first occurrence of the given substring.
589
- *
590
- * @param needle - The substring to search for.
591
- * @param offset - The offset from which to start the search. Defaults to 0.
592
- * @returns The position of the first occurrence of the substring, or false if not found.
593
- */
594
- position(e, t = 0) {
595
- return oe(this._value, e, t);
596
- }
597
- /**
598
- * Prepend the given values to the string.
599
- *
600
- * @param values - The values to prepend to the string.
601
- * @returns The updated Stringable instance.
602
- */
603
- prepend(...e) {
604
- return new r(e.map(String).join("") + this._value);
605
- }
606
- /**
607
- * Remove any occurrence of the given string in the subject.
608
- *
609
- * @param search - The string or iterable of strings to remove.
610
- * @param caseSensitive - Whether the search should be case-sensitive. Defaults to true.
611
- * @returns The updated Stringable instance.
612
- */
613
- remove(e, t = !0) {
614
- return new r(
615
- we(e, this._value, t)
616
- );
617
- }
618
- /**
619
- * Reverse the string.
620
- *
621
- * @returns The reversed string as a new Stringable instance.
622
- */
623
- reverse() {
624
- return new r(ce(this._value));
625
- }
626
- /**
627
- * Repeat the string.
628
- *
629
- * @param times - The number of times to repeat the string.
630
- * @returns The repeated string as a new Stringable instance.
631
- */
632
- repeat(e) {
633
- return new r(ve(this._value, e));
634
- }
635
- /**
636
- * Replace the given value in the given string.
637
- *
638
- * @param search - The value or iterable of values to search for.
639
- * @param replacement - The replacement value or iterable of values.
640
- * @param caseSensitive - Whether the search should be case-sensitive. Defaults to true.
641
- * @returns The updated Stringable instance.
642
- */
643
- replace(e, t, s = !0) {
644
- return new r(
645
- pe(e, t, this._value, s)
646
- );
647
- }
648
- /**
649
- * Replace a given value in the string sequentially with an array.
650
- *
651
- * @param search - The value to search for.
652
- * @param replace - The array or record of replacements.
653
- * @returns The updated Stringable instance.
654
- */
655
- replaceArray(e, t) {
656
- return new r(de(e, t, this._value));
657
- }
658
- /**
659
- * Replace the first occurrence of a given value in the string.
660
- *
661
- * @param search - The value to search for.
662
- * @param replace - The replacement value.
663
- * @returns The updated Stringable instance.
664
- */
665
- replaceFirst(e, t) {
666
- return new r(me(e, t, this._value));
667
- }
668
- /**
669
- * Replace the first occurrence of the given value if it appears at the start of the string.
670
- *
671
- * @param search - The value to search for.
672
- * @param replace - The replacement value.
673
- * @returns The updated Stringable instance.
674
- */
675
- replaceStart(e, t) {
676
- return new r(fe(e, t, this._value));
677
- }
678
- /**
679
- * Replace the last occurrence of a given value in the string.
680
- *
681
- * @param search - The value to search for.
682
- * @param replace - The replacement value.
683
- * @returns The updated Stringable instance.
684
- */
685
- replaceLast(e, t) {
686
- return new r(_e(e, t, this._value));
687
- }
688
- /**
689
- * Replace the last occurrence of a given value if it appears at the end of the string.
690
- *
691
- * @param search - The value to search for.
692
- * @param replace - The replacement value.
693
- * @returns The updated Stringable instance.
694
- */
695
- replaceEnd(e, t) {
696
- return new r(Ee(e, t, this._value));
697
- }
698
- /**
699
- * Replace the patterns matching the given regular expression.
700
- *
701
- * @param pattern - The pattern(s) to search for.
702
- * @param replace - The replacement string(s) or a callback function.
703
- * @param limit - The maximum number of replacements to perform. Defaults to -1 (no limit).
704
- * @returns The updated Stringable instance.
705
- */
706
- replaceMatches(e, t, s = -1) {
707
- const n = ye(e, t, this._value, s);
708
- return new r(n);
709
- }
710
- /**
711
- * Parse input from a string to an array, according to a format.
712
- *
713
- * @param format - A format string like "%d", "%s", "%[^,],%s", etc.
714
- * @returns Array of parsed values according to the format
715
- *
716
- * @example
717
- *
718
- * Str.of("SN/123456").scan("SN/%d") -> ["123456"]
719
- * Str.of("Otwell, Taylor").scan("%[^,],%s") -> ["Otwell", "Taylor"]
720
- * Str.of("filename.jpg").scan("%[^.].%s") -> ["filename", "jpg"]
721
- */
722
- scan(e) {
723
- let t = "", s = 0;
724
- for (; s < e.length; )
725
- if (e[s] === "%")
726
- if (e[s + 1] === "[") {
727
- let u = s + 2;
728
- for (; u < e.length && e[u] !== "]"; )
729
- u++;
730
- const c = e.substring(s + 2, u);
731
- t += "([" + c + "]+)", s = u + 1;
732
- } else e[s + 1] === "d" ? (t += "\\s*(-?\\d+)", s += 2) : e[s + 1] === "s" ? (t += "\\s*(\\S+)", s += 2) : (t += e[s], s++);
733
- else {
734
- const u = e[s];
735
- u && /[.+?^${}()|\\]/.test(u) ? t += "\\" + u : t += u, s++;
736
- }
737
- const n = new RegExp("^" + t + "$"), h = this._value.match(n);
738
- return h ? h.slice(1).filter((u) => u !== void 0) : [];
739
- }
740
- /**
741
- * Remove all "extra" blank space from the given string.
742
- *
743
- * @returns The updated Stringable instance.
744
- */
745
- squish() {
746
- return new r(Ae(this._value));
747
- }
748
- /**
749
- * Begin a string with a single instance of a given value.
750
- *
751
- * @param prefix - The string to start the original string with.
752
- * @returns The updated Stringable instance.
753
- */
754
- start(e) {
755
- return new r(We(this._value, e));
756
- }
757
- /**
758
- * Strip HTML and PHP tags from the given string.
759
- *
760
- * @returns The updated Stringable instance.
761
- */
762
- stripTags() {
763
- return new r(xe(this._value));
764
- }
765
- /**
766
- * Convert the given string to upper-case.
767
- *
768
- * @returns The upper-cased string as a new Stringable instance.
769
- */
770
- upper() {
771
- return new r(E(this._value));
772
- }
773
- /**
774
- * Convert the given string to proper case.
775
- *
776
- * @returns The title-cased string as a new Stringable instance.
777
- */
778
- title() {
779
- return new r(y(this._value));
780
- }
781
- /**
782
- * Convert the given string to proper case for each word.
783
- *
784
- * @returns The headline-cased string as a new Stringable instance.
785
- */
786
- headline() {
787
- return new r(ke(this._value));
788
- }
789
- /**
790
- * Convert the given string to only its initials.
791
- *
792
- * @param capitalize - Whether to capitalize the initials.
793
- * @returns The initials of the string as a new Stringable instance.
794
- */
795
- initials(e = !1) {
796
- return new r(Ie(this._value, e));
797
- }
798
- /**
799
- * Convert the given string to APA-style title case.
800
- *
801
- * @returns The APA title-cased string as a new Stringable instance.
802
- */
803
- apa() {
804
- return new r(Ne(this._value));
805
- }
806
- /**
807
- * Transliterate a string to its closest ASCII representation.
808
- *
809
- * @returns The transliterated string as a new Stringable instance.
810
- */
811
- transliterate() {
812
- return new r(ze(this._value));
813
- }
814
- /**
815
- * Get the singular form of an English word.
816
- *
817
- * @returns The singularized string as a new Stringable instance.
818
- */
819
- singular() {
820
- return new r(U(this._value));
821
- }
822
- /**
823
- * Generate a URL friendly "slug" from a given string.
824
- *
825
- * @param separator - The separator to use in the slug. Defaults to "-".
826
- * @param dictionary - A dictionary of characters to replace. Defaults to { "@": "at" }.
827
- * @returns The slugified string as a new Stringable instance.
828
- */
829
- slug(e = "-", t = { "@": "at" }) {
830
- return new r(d(this._value, e, t));
831
- }
832
- /**
833
- * Convert a string to snake case.
834
- *
835
- * @param delimiter - The delimiter to use in the snake case. Defaults to "_".
836
- * @returns The snake-cased string as a new Stringable instance.
837
- */
838
- snake(e = "_") {
839
- return new r(Ue(this._value, e));
840
- }
841
- /**
842
- * Determine if a given string starts with a given substring.
843
- *
844
- * @param needles - The substring(s) to search for
845
- * @returns boolean - True if the substring(s) are found, false otherwise
846
- */
847
- startsWith(e) {
848
- return Ce(this._value, e);
849
- }
850
- /**
851
- * Determine if a given string doesn't start with a given substring.
852
- *
853
- * @param needles - The substring(s) to search for
854
- * @returns boolean - True if the substring(s) are not found, false otherwise
855
- */
856
- doesntStartWith(e) {
857
- return Le(this._value, e);
858
- }
859
- /**
860
- * Convert a value to studly caps case.
861
- *
862
- * @param normalize - When true, all-uppercase words (e.g. acronyms) are lowercased before conversion so "CBOR" becomes "Cbor" instead of "CBOR". Defaults to false.
863
- * @returns The studly-cased string as a new Stringable instance.
864
- */
865
- studly(e = !1) {
866
- return new r(Me(this._value, e));
867
- }
868
- /**
869
- * Convert the string to Pascal case.
870
- *
871
- * @param normalize - When true, all-uppercase words (e.g. acronyms) are lowercased before conversion so "CBOR" becomes "Cbor" instead of "CBOR". Defaults to false.
872
- * @returns The pascal-cased string as a new Stringable instance.
873
- */
874
- pascal(e = !1) {
875
- return new r(Fe(this._value, e));
876
- }
877
- /**
878
- * Returns the portion of the string specified by the start and length parameters.
879
- *
880
- * @param start - The starting position of the substring.
881
- * @param length - The length of the substring. If null, extracts to the end of the string.
882
- * @returns The extracted substring as a new Stringable instance.
883
- */
884
- substr(e, t = null) {
885
- return new r(C(this._value, e, t));
886
- }
887
- /**
888
- * Returns the number of substring occurrences.
889
- *
890
- * @param needle - The substring to search for.
891
- * @param offset - The offset to start searching from. Defaults to 0.
892
- * @param length - The length of the string to search within. If null, searches to the end of the string.
893
- * @returns The number of occurrences of the substring.
894
- */
895
- substrCount(e, t = 0, s = null) {
896
- return L(this._value, e, t, s);
897
- }
898
- /**
899
- * Replace text within a portion of a string.
900
- *
901
- * @param replace - The replacement string, or an array of replacements from which the first value is used.
902
- * @param offset - The starting position to begin replacing. If negative, it starts that many characters from the end of the string.
903
- * @param length - The number of characters to replace. If null, replaces to the end of the string. If negative, omits that many characters from the end.
904
- * @returns The updated Stringable instance.
905
- */
906
- substrReplace(e, t = 0, s = null) {
907
- return new r(
908
- M(this._value, e, t, s)
909
- );
910
- }
911
- /**
912
- * Swap multiple keywords in a string with other keywords.
913
- *
914
- * @param map - A record of keywords to swap (key: search, value: replacement).
915
- * @returns The updated Stringable instance.
916
- */
917
- swap(e) {
918
- return new r(Re(e, this._value));
919
- }
920
- /**
921
- * Take the first or last {$limit} characters.
922
- *
923
- * @param limit - The number of characters to take. Positive for start, negative for end.
924
- * @returns The resulting substring as a new Stringable instance.
925
- */
926
- take(e) {
927
- return new r(Be(this._value, e));
928
- }
929
- /**
930
- * Trim the string of the given characters.
931
- *
932
- * @param charlist - The characters to trim from the string. If null, trims whitespace; an empty string
933
- * trims nothing.
934
- * @returns The trimmed string as a new Stringable instance.
935
- */
936
- trim(e = null) {
937
- return new r(w(this._value, e));
938
- }
939
- /**
940
- * Left trim the string of the given characters.
941
- *
942
- * @param charlist - The characters to trim from the start of the string. If null, trims whitespace; an empty string
943
- * trims nothing.
944
- * @returns The left-trimmed string as a new Stringable instance.
945
- */
946
- ltrim(e = null) {
947
- return new r(Ge(this._value, e));
948
- }
949
- /**
950
- * Right trim the string of the given characters.
951
- *
952
- * @param charlist - The characters to trim from the end of the string. If null, trims whitespace; an empty string
953
- * trims nothing.
954
- * @returns The right-trimmed string as a new Stringable instance.
955
- */
956
- rtrim(e = null) {
957
- return new r(Xe(this._value, e));
958
- }
959
- /**
960
- * Make a string's first character lowercase.
961
- *
962
- * @returns The updated Stringable instance.
963
- */
964
- lcfirst() {
965
- return new r(je(this._value));
966
- }
967
- /**
968
- * Make a string's first character uppercase.
969
- *
970
- * @returns The updated Stringable instance.
971
- */
972
- ucfirst() {
973
- return new r(Te(this._value));
974
- }
975
- /**
976
- * Split a string by uppercase characters.
977
- *
978
- * @returns An array of substrings split at uppercase characters.
979
- */
980
- ucsplit() {
981
- return De(this._value);
982
- }
983
- /**
984
- * Uppercase the first character of each word in a string.
985
- *
986
- * @returns The updated Stringable instance.
987
- */
988
- ucwords() {
989
- return new r(qe(this._value));
990
- }
991
- /**
992
- * Apply the callback if the given "value" is (or resolves to) truthy.
993
- *
994
- * @param value - The value to evaluate or a closure that returns the value
995
- * @param callback - The callback to execute if the value is truthy
996
- * @param defaultCallback - The callback to execute if the value is falsy
997
- * @returns Stringable - The current instance or the result of the callback
998
- *
999
- * @example
1000
- *
1001
- * ```typescript
1002
- * const str = new Stringable('hello world');
1003
- *
1004
- * Using a direct value
1005
- * str.when(true, s => s.upper()); // Returns 'HELLO WORLD'
1006
- * str.when(false, s => s.upper(), s => s.lower()); // Returns 'hello world'
1007
- *
1008
- * Using a closure to determine the value
1009
- * str.when(s => s.contains('world'), s => s.upper()); // Returns 'HELLO WORLD'
1010
- * str.when(s => s.contains('foo'), s => s.upper(), s => s.lower()); // Returns 'hello world'
1011
- * ```
1012
- */
1013
- when(e, t = null, s = null) {
1014
- const n = a(e) ? e(this) : e;
1015
- return n ? t?.(this, n) ?? this : s ? s(this, n) ?? this : this;
1016
- }
1017
- /**
1018
- * Apply the callback if the given "value" is (or resolves to) falsy.
1019
- *
1020
- * @param value - The value to evaluate or a closure that returns the value
1021
- * @param callback - The callback to execute if the value is falsy
1022
- * @param defaultCallback - The callback to execute if the value is truthy
1023
- * @returns Stringable - The current instance or the result of the callback
1024
- *
1025
- * @example
1026
- *
1027
- * const str = new Stringable('hello world');
1028
- * str.unless(true, s => s.upper()); // Returns 'hello world'
1029
- * str.unless(false, s => s.upper(), s => s.lower()); // Returns 'HELLO WORLD'
1030
- */
1031
- unless(e, t = null, s = null) {
1032
- const n = a(e) ? e(this) : e;
1033
- if (n) {
1034
- if (s)
1035
- return s(this, n) ?? this;
1036
- } else return t?.(this, n) ?? this;
1037
- return this;
1038
- }
1039
- /**
1040
- * Execute the given callback if the string contains a given substring.
1041
- *
1042
- * @param needles - The substring(s) to search for
1043
- * @param callback - The callback to execute if the substring(s) are found
1044
- * @param defaultCallback - The callback to execute if the substring(s) are not found
1045
- * @returns Stringable - The current instance or the result of the callback
1046
- */
1047
- whenContains(e, t, s = null) {
1048
- return this.when(this.contains(e), t, s);
1049
- }
1050
- /**
1051
- * Execute the given callback if the string contains all array values.
1052
- *
1053
- * @param needles - The substring(s) to search for
1054
- * @param callback - The callback to execute if all substring(s) are found
1055
- * @param defaultCallback - The callback to execute if not all substring(s) are found
1056
- * @returns Stringable - The current instance or the result of the callback
1057
- */
1058
- whenContainsAll(e, t, s = null) {
1059
- return this.when(this.containsAll(e), t, s);
1060
- }
1061
- /**
1062
- * Execute the given callback if the string is empty.
1063
- *
1064
- * @param callback - The callback to execute if the string is empty
1065
- * @param defaultCallback - The callback to execute if the string is not empty
1066
- * @returns Stringable - The current instance or the result of the callback
1067
- */
1068
- whenEmpty(e, t = null) {
1069
- return this.when(this.isEmpty(), e, t);
1070
- }
1071
- /**
1072
- * Execute the given callback if the string is not empty.
1073
- *
1074
- * @param callback - The callback to execute if the string is not empty
1075
- * @param defaultCallback - The callback to execute if the string is empty
1076
- * @returns Stringable - The current instance or the result of the callback
1077
- */
1078
- whenNotEmpty(e, t = null) {
1079
- return this.when(this.isNotEmpty(), e, t);
1080
- }
1081
- /**
1082
- * Execute the given callback if the string ends with a given substring.
1083
- *
1084
- * @param needles - The substring(s) to search for
1085
- * @param callback - The callback to execute if the substring(s) are found
1086
- * @param defaultCallback - The callback to execute if the substring(s) are not found
1087
- * @returns Stringable - The current instance or the result of the callback
1088
- */
1089
- whenEndsWith(e, t, s = null) {
1090
- return this.when(this.endsWith(e), t, s);
1091
- }
1092
- /**
1093
- * Execute the given callback if the string doesn't end with a given substring.
1094
- *
1095
- * @param needles - The substring(s) to search for
1096
- * @param callback - The callback to execute if the substring(s) are not found
1097
- * @param defaultCallback - The callback to execute if the substring(s) are found
1098
- * @returns Stringable - The current instance or the result of the callback
1099
- */
1100
- whenDoesntEndWith(e, t, s = null) {
1101
- return this.when(
1102
- this.doesntEndWith(e),
1103
- t,
1104
- s
1105
- );
1106
- }
1107
- /**
1108
- * Execute the given callback if the string is an exact match with the given value.
1109
- *
1110
- * @param value - The value to compare against
1111
- * @param callback - The callback to execute if the string matches the value
1112
- * @param defaultCallback - The callback to execute if the string does not match the value
1113
- * @returns Stringable - The current instance or the result of the callback
1114
- */
1115
- whenExactly(e, t, s = null) {
1116
- return this.when(this.exactly(e), t, s);
1117
- }
1118
- /**
1119
- * Execute the given callback if the string is not an exact match with the given value.
1120
- *
1121
- * @param value - The value to compare against
1122
- * @param callback - The callback to execute if the string does not match the value
1123
- * @param defaultCallback - The callback to execute if the string matches the value
1124
- * @returns Stringable - The current instance or the result of the callback
1125
- */
1126
- whenNotExactly(e, t, s = null) {
1127
- return this.when(!this.exactly(e), t, s);
1128
- }
1129
- /**
1130
- * Execute the given callback if the string matches a given pattern.
1131
- *
1132
- * @param pattern - The pattern(s) to match against
1133
- * @param callback - The callback to execute if the pattern(s) match
1134
- * @param defaultCallback - The callback to execute if the pattern(s) do not match
1135
- * @returns Stringable - The current instance or the result of the callback
1136
- */
1137
- whenIs(e, t, s = null) {
1138
- return this.when(this.is(e), t, s);
1139
- }
1140
- /**
1141
- * Execute the given callback if the string is 7 bit ASCII.
1142
- *
1143
- * @param callback - The callback to execute if the string is ASCII
1144
- * @param defaultCallback - The callback to execute if the string is not ASCII
1145
- * @returns Stringable - The current instance or the result of the callback
1146
- */
1147
- whenIsAscii(e, t = null) {
1148
- return this.when(this.isAscii(), e, t);
1149
- }
1150
- /**
1151
- * Execute the given callback if the string is a valid UUID.
1152
- *
1153
- * @param callback - The callback to execute if the string is a UUID
1154
- * @param defaultCallback - The callback to execute if the string is not a UUID
1155
- * @returns Stringable - The current instance or the result of the callback
1156
- */
1157
- whenIsUuid(e, t = null) {
1158
- return this.when(this.isUuid(), e, t);
1159
- }
1160
- /**
1161
- * Execute the given callback if the string is a valid ULID.
1162
- *
1163
- * @param callback - The callback to execute if the string is a ULID
1164
- * @param defaultCallback - The callback to execute if the string is not a ULID
1165
- * @returns Stringable - The current instance or the result of the callback
1166
- */
1167
- whenIsUlid(e, t = null) {
1168
- return this.when(this.isUlid(), e, t);
1169
- }
1170
- /**
1171
- * Execute the given callback if the string starts with a given substring.
1172
- *
1173
- * @param needles - The substring(s) to search for
1174
- * @param callback - The callback to execute if the substring(s) are found
1175
- * @param defaultCallback - The callback to execute if the substring(s) are not found
1176
- * @returns Stringable - The current instance or the result of the callback
1177
- */
1178
- whenStartsWith(e, t, s = null) {
1179
- return this.when(this.startsWith(e), t, s);
1180
- }
1181
- /**
1182
- * Execute the given callback if the string matches the given pattern.
1183
- *
1184
- * @param pattern - The pattern(s) to match against
1185
- * @param callback - The callback to execute if the pattern(s) match
1186
- * @param defaultCallback - The callback to execute if the pattern(s) do not match
1187
- * @returns Stringable - The current instance or the result of the callback
1188
- */
1189
- whenTest(e, t, s = null) {
1190
- return this.when(this.test(e), t, s);
1191
- }
1192
- /**
1193
- * Limit the number of words in a string.
1194
- *
1195
- * @param wordsValue - The maximum number of words allowed. Defaults to 100.
1196
- * @param end - The string to append if the string is truncated. Defaults to "...".
1197
- * @returns The truncated string as a new Stringable instance.
1198
- */
1199
- words(e = 100, t = "...") {
1200
- return new r(Oe(this._value, e, t));
1201
- }
1202
- /**
1203
- * Get the number of words a string contains.
1204
- *
1205
- * @param characters - The characters to consider as word boundaries. If null, defaults to standard word boundaries.
1206
- * @returns The number of words in the string.
1207
- */
1208
- wordCount(e = null) {
1209
- return Pe(this._value, e);
1210
- }
1211
- /**
1212
- * Wrap a string to a given number of characters.
1213
- *
1214
- * @param characters - The number of characters at which to wrap the string. Defaults to 75.
1215
- * @param breakStr - The string to insert as a break. Defaults to "\n".
1216
- * @param cutLongWords - Whether to cut words longer than the specified length. Defaults to false.
1217
- * @returns The wrapped string as a new Stringable instance.
1218
- */
1219
- wordWrap(e = 75, t = `
1220
- `, s = !1) {
1221
- return new r(
1222
- $e(this._value, e, t, s)
1223
- );
1224
- }
1225
- /**
1226
- * Wrap the string with the given strings.
1227
- *
1228
- * @param before - The string to prepend
1229
- * @param after - The string to append. Defaults to the value of `before`
1230
- * @returns The wrapped string as a new Stringable instance.
1231
- */
1232
- wrap(e, t = null) {
1233
- return new r(Je(this._value, e, t));
1234
- }
1235
- /**
1236
- * Unwrap the string with the given strings.
1237
- *
1238
- * @param before - The string to remove from the start
1239
- * @param after - The string to remove from the end. Defaults to the value of `before`
1240
- * @returns The unwrapped string as a new Stringable instance.
1241
- */
1242
- unwrap(e, t = null) {
1243
- return new r(Ve(this._value, e, t));
1244
- }
1245
- /**
1246
- * Convert the string to Base64 encoding.
1247
- *
1248
- * @returns The Base64 encoded string as a new Stringable instance.
1249
- */
1250
- toBase64() {
1251
- return new r(m(this._value));
1252
- }
1253
- /**
1254
- * Decode the Base64 encoded string.
1255
- *
1256
- * @param strict - Whether to use strict decoding. Defaults to false.
1257
- * @returns The decoded string as a new Stringable instance, or false on failure.
1258
- */
1259
- fromBase64(e = !1) {
1260
- const t = f(this._value, e);
1261
- return t === !1 ? !1 : new r(t);
1262
- }
1263
- /**
1264
- * Dump the string and the given arguments to the console.
1265
- *
1266
- * @param args - Extra values to log alongside the string.
1267
- * @returns The current instance.
1268
- */
1269
- dump(...e) {
1270
- return console.log(this._value, ...e), this;
1271
- }
1272
- /**
1273
- * Get the underlying string value.
1274
- *
1275
- * @returns The string representation of the object.
1276
- */
1277
- toString() {
1278
- return this.value();
1279
- }
1280
- /**
1281
- * Get the underlying string value.
1282
- *
1283
- * @returns The string value.
1284
- */
1285
- value() {
1286
- return String(this._value);
1287
- }
1288
- /**
1289
- * Get the underlying string value as an integer.
1290
- *
1291
- * @param base - The base to use for conversion. Defaults to 10.
1292
- * @returns The integer value.
1293
- */
1294
- toInteger(e = 10) {
1295
- const t = Number(e) || 10;
1296
- return parseInt(this._value, t);
1297
- }
1298
- /**
1299
- * Get the underlying string value as a float.
1300
- *
1301
- * @returns The float value.
1302
- */
1303
- toFloat() {
1304
- return parseFloat(this._value);
1305
- }
1306
- /**
1307
- * Get the underlying string value as a boolean.
1308
- *
1309
- * @returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.
1310
- */
1311
- toBoolean() {
1312
- const e = o(w(this._value));
1313
- return e === "1" || e === "true" || e === "on" || e === "yes";
1314
- }
1315
- /**
1316
- * Get the underlying string value as a Date instance.
1317
- *
1318
- * @returns The Date instance or null if parsing fails.
1319
- */
1320
- toDate() {
1321
- const e = Date.parse(this._value);
1322
- return isNaN(e) ? null : new Date(e);
1323
- }
1324
- /**
1325
- * Convert the object to a string when JSON encoded.
1326
- *
1327
- * @returns The string representation of the object.
1328
- */
1329
- jsonSerialize() {
1330
- return this.toString();
1331
- }
1332
- }
1333
- export {
1334
- r as Stringable,
1335
- at as of,
1336
- ot as str
48
+ var $ = class Z {
49
+ _value;
50
+ constructor(e = "") {
51
+ this._value = e;
52
+ }
53
+ after(e) {
54
+ return new Z(s(this._value, e));
55
+ }
56
+ afterLast(e) {
57
+ return new Z(c(this._value, e));
58
+ }
59
+ append(...e) {
60
+ return new Z(this._value + e.map(String).join(""));
61
+ }
62
+ newLine(e = 1) {
63
+ return this.append("\n".repeat(Math.max(0, e)));
64
+ }
65
+ ascii() {
66
+ return new Z(je(this._value));
67
+ }
68
+ basename(e = "") {
69
+ return new Z(He(this._value, e));
70
+ }
71
+ before(e) {
72
+ return new Z(u(this._value, e));
73
+ }
74
+ beforeLast(e) {
75
+ return new Z(d(this._value, e));
76
+ }
77
+ between(e, t) {
78
+ return new Z(f(this._value, e, t));
79
+ }
80
+ betweenFirst(e, t) {
81
+ return new Z(p(this._value, e, t));
82
+ }
83
+ camel() {
84
+ return new Z(m(this._value));
85
+ }
86
+ charAt(e) {
87
+ return h(this._value, e);
88
+ }
89
+ chopStart(e) {
90
+ return new Z(_(this._value, e));
91
+ }
92
+ chopEnd(e) {
93
+ return new Z(g(this._value, e));
94
+ }
95
+ contains(e, t = !1) {
96
+ return v(this._value, e, t);
97
+ }
98
+ containsAll(e, t = !1) {
99
+ return y(this._value, e, t);
100
+ }
101
+ doesntContain(e, t = !1) {
102
+ return x(this._value, e, t);
103
+ }
104
+ convertCase(t) {
105
+ return new Z(e(this._value, t));
106
+ }
107
+ counted(e) {
108
+ return new Z(Fe(this._value, e));
109
+ }
110
+ deduplicate(e = " ") {
111
+ return new Z(b(this._value, e));
112
+ }
113
+ dirname(e = 1) {
114
+ return new Z(Ue(this._value, e));
115
+ }
116
+ endsWith(e) {
117
+ return w(this._value, e);
118
+ }
119
+ doesntEndWith(e) {
120
+ return S(this._value, e);
121
+ }
122
+ exactly(e) {
123
+ let t = e instanceof Z ? e.toString() : String(e);
124
+ return this._value === t;
125
+ }
126
+ excerpt(e = "", t = {}) {
127
+ return T(this._value, e, t);
128
+ }
129
+ explode(e, t = 2 ** 53 - 1) {
130
+ let n = this._value.split(e);
131
+ if (t > 0 && n.length > t) {
132
+ let r = n.slice(0, t - 1);
133
+ return r.push(n.slice(t - 1).join(e)), r;
134
+ }
135
+ return t < 0 ? n.slice(0, t) : n;
136
+ }
137
+ split(e, t = null) {
138
+ if (Be(e)) {
139
+ let t = Number(e), n = [];
140
+ for (let e = 0; e < this._value.length; e += t) n.push(this._value.substr(e, t));
141
+ return n;
142
+ }
143
+ return this._value.split(new RegExp(String(e)), t ?? void 0);
144
+ }
145
+ finish(e) {
146
+ return new Z(E(this._value, e));
147
+ }
148
+ is(e, t = !1) {
149
+ return k(e, this._value, t);
150
+ }
151
+ isAscii() {
152
+ return A(this._value);
153
+ }
154
+ isJson() {
155
+ return j(this._value);
156
+ }
157
+ isUrl(e = []) {
158
+ return N(this._value, e);
159
+ }
160
+ isUuid(e = null) {
161
+ return ae(this._value, e);
162
+ }
163
+ isUlid() {
164
+ return ie(this._value);
165
+ }
166
+ isEmpty() {
167
+ return this._value === "";
168
+ }
169
+ isNotEmpty() {
170
+ return !this.isEmpty();
171
+ }
172
+ kebab() {
173
+ return new Z(P(this._value));
174
+ }
175
+ length() {
176
+ return I(this._value);
177
+ }
178
+ limit(e = 100, t = "...", n = !1) {
179
+ return new Z(L(this._value, e, t, n));
180
+ }
181
+ lower() {
182
+ return new Z(R(this._value));
183
+ }
184
+ markdown(e = {
185
+ gfm: !0,
186
+ anchors: !1
187
+ }, t = []) {
188
+ return new Z(Pe(this._value, e, t));
189
+ }
190
+ inlineMarkdown(e = { gfm: !0 }, t = []) {
191
+ return new Z(Ne(this._value, e, t));
192
+ }
193
+ mask(e, t, n = null) {
194
+ return new Z(z(this._value, e, t, n));
195
+ }
196
+ match(e) {
197
+ return new Z(B(e, this._value));
198
+ }
199
+ isMatch(e) {
200
+ return M(e, this._value);
201
+ }
202
+ matchAll(e) {
203
+ return V(e, this._value);
204
+ }
205
+ test(e) {
206
+ return this.isMatch(e);
207
+ }
208
+ numbers() {
209
+ return new Z(H(this._value));
210
+ }
211
+ padBoth(e, t = " ") {
212
+ return new Z(U(this._value, e, t));
213
+ }
214
+ padLeft(e, t = " ") {
215
+ return new Z(W(this._value, e, t));
216
+ }
217
+ padRight(e, t = " ") {
218
+ return new Z(G(this._value, e, t));
219
+ }
220
+ pipe(e) {
221
+ let t = e(this);
222
+ return t instanceof Z ? t : new Z(String(t));
223
+ }
224
+ plural(e = 2, t = !1) {
225
+ return new Z(Ie(this._value, e, t));
226
+ }
227
+ pluralStudly(e = 2) {
228
+ return new Z(Re(this._value, e));
229
+ }
230
+ pluralPascal(e = 2) {
231
+ return new Z(Le(this._value, e));
232
+ }
233
+ position(e, t = 0) {
234
+ return q(this._value, e, t);
235
+ }
236
+ prepend(...e) {
237
+ return new Z(e.map(String).join("") + this._value);
238
+ }
239
+ remove(e, t = !0) {
240
+ return new Z(J(e, this._value, t));
241
+ }
242
+ reverse() {
243
+ return new Z(me(this._value));
244
+ }
245
+ repeat(e) {
246
+ return new Z(oe(this._value, e));
247
+ }
248
+ replace(e, t, n = !0) {
249
+ return new Z(se(e, t, this._value, n));
250
+ }
251
+ replaceArray(e, t) {
252
+ return new Z(ce(e, t, this._value));
253
+ }
254
+ replaceFirst(e, t) {
255
+ return new Z(ue(e, t, this._value));
256
+ }
257
+ replaceStart(e, t) {
258
+ return new Z(pe(e, t, this._value));
259
+ }
260
+ replaceLast(e, t) {
261
+ return new Z(de(e, t, this._value));
262
+ }
263
+ replaceEnd(e, t) {
264
+ return new Z(le(e, t, this._value));
265
+ }
266
+ replaceMatches(e, t, n = -1) {
267
+ let r = fe(e, t, this._value, n);
268
+ return new Z(r);
269
+ }
270
+ scan(e) {
271
+ let t = "", n = 0;
272
+ for (; n < e.length;) if (e[n] === "%") {
273
+ if (e[n + 1] === "[") {
274
+ let r = n + 2;
275
+ for (; r < e.length && e[r] !== "]";) r++;
276
+ let i = e.substring(n + 2, r);
277
+ t += "([" + i + "]+)", n = r + 1;
278
+ } else e[n + 1] === "d" ? (t += "\\s*(-?\\d+)", n += 2) : e[n + 1] === "s" ? (t += "\\s*(\\S+)", n += 2) : (t += e[n], n++);
279
+ } else {
280
+ let r = e[n];
281
+ r && /[.+?^${}()|\\]/.test(r) ? t += "\\" + r : t += r, n++;
282
+ }
283
+ let r = RegExp("^" + t + "$"), i = this._value.match(r);
284
+ return i ? i.slice(1).filter((e) => e !== void 0) : [];
285
+ }
286
+ squish() {
287
+ return new Z(ge(this._value));
288
+ }
289
+ start(e) {
290
+ return new Z(_e(this._value, e));
291
+ }
292
+ stripTags() {
293
+ return new Z(ye(this._value));
294
+ }
295
+ upper() {
296
+ return new Z(n(this._value));
297
+ }
298
+ title() {
299
+ return new Z(t(this._value));
300
+ }
301
+ headline() {
302
+ return new Z(D(this._value));
303
+ }
304
+ initials(e = !1) {
305
+ return new Z(O(this._value, e));
306
+ }
307
+ apa() {
308
+ return new Z(l(this._value));
309
+ }
310
+ transliterate() {
311
+ return new Z(ze(this._value));
312
+ }
313
+ singular() {
314
+ return new Z(Y(this._value));
315
+ }
316
+ slug(e = "-", t = { "@": "at" }) {
317
+ return new Z(Me(this._value, e, t));
318
+ }
319
+ snake(e = "_") {
320
+ return new Z(he(this._value, e));
321
+ }
322
+ startsWith(e) {
323
+ return ve(this._value, e);
324
+ }
325
+ doesntStartWith(e) {
326
+ return C(this._value, e);
327
+ }
328
+ studly(e = !1) {
329
+ return new Z(be(this._value, e));
330
+ }
331
+ pascal(e = !1) {
332
+ return new Z(K(this._value, e));
333
+ }
334
+ substr(e, t = null) {
335
+ return new Z(ee(this._value, e, t));
336
+ }
337
+ substrCount(e, t = 0, n = null) {
338
+ return a(this._value, e, t, n);
339
+ }
340
+ substrReplace(e, t = 0, n = null) {
341
+ return new Z(te(this._value, e, t, n));
342
+ }
343
+ swap(e) {
344
+ return new Z(xe(e, this._value));
345
+ }
346
+ take(e) {
347
+ return new Z(Se(this._value, e));
348
+ }
349
+ trim(e = null) {
350
+ return new Z(o(this._value, e));
351
+ }
352
+ ltrim(e = null) {
353
+ return new Z(ne(this._value, e));
354
+ }
355
+ rtrim(e = null) {
356
+ return new Z(re(this._value, e));
357
+ }
358
+ lcfirst() {
359
+ return new Z(F(this._value));
360
+ }
361
+ ucfirst() {
362
+ return new Z(Ce(this._value));
363
+ }
364
+ ucsplit() {
365
+ return we(this._value);
366
+ }
367
+ ucwords() {
368
+ return new Z(Te(this._value));
369
+ }
370
+ when(e, t = null, n = null) {
371
+ let r = X(e) ? e(this) : e;
372
+ return r ? t?.(this, r) ?? this : n ? n(this, r) ?? this : this;
373
+ }
374
+ unless(e, t = null, n = null) {
375
+ let r = X(e) ? e(this) : e;
376
+ return r ? n ? n(this, r) ?? this : this : t?.(this, r) ?? this;
377
+ }
378
+ whenContains(e, t, n = null) {
379
+ return this.when(this.contains(e), t, n);
380
+ }
381
+ whenContainsAll(e, t, n = null) {
382
+ return this.when(this.containsAll(e), t, n);
383
+ }
384
+ whenEmpty(e, t = null) {
385
+ return this.when(this.isEmpty(), e, t);
386
+ }
387
+ whenNotEmpty(e, t = null) {
388
+ return this.when(this.isNotEmpty(), e, t);
389
+ }
390
+ whenEndsWith(e, t, n = null) {
391
+ return this.when(this.endsWith(e), t, n);
392
+ }
393
+ whenDoesntEndWith(e, t, n = null) {
394
+ return this.when(this.doesntEndWith(e), t, n);
395
+ }
396
+ whenExactly(e, t, n = null) {
397
+ return this.when(this.exactly(e), t, n);
398
+ }
399
+ whenNotExactly(e, t, n = null) {
400
+ return this.when(!this.exactly(e), t, n);
401
+ }
402
+ whenIs(e, t, n = null) {
403
+ return this.when(this.is(e), t, n);
404
+ }
405
+ whenIsAscii(e, t = null) {
406
+ return this.when(this.isAscii(), e, t);
407
+ }
408
+ whenIsUuid(e, t = null) {
409
+ return this.when(this.isUuid(), e, t);
410
+ }
411
+ whenIsUlid(e, t = null) {
412
+ return this.when(this.isUlid(), e, t);
413
+ }
414
+ whenStartsWith(e, t, n = null) {
415
+ return this.when(this.startsWith(e), t, n);
416
+ }
417
+ whenTest(e, t, n = null) {
418
+ return this.when(this.test(e), t, n);
419
+ }
420
+ words(e = 100, t = "...") {
421
+ return new Z(ke(this._value, e, t));
422
+ }
423
+ wordCount(e = null) {
424
+ return De(this._value, e);
425
+ }
426
+ wordWrap(e = 75, t = "\n", n = !1) {
427
+ return new Z(Oe(this._value, e, t, n));
428
+ }
429
+ wrap(e, t = null) {
430
+ return new Z(Ae(this._value, e, t));
431
+ }
432
+ unwrap(e, t = null) {
433
+ return new Z(Ee(this._value, e, t));
434
+ }
435
+ toBase64() {
436
+ return new Z(i(this._value));
437
+ }
438
+ fromBase64(e = !1) {
439
+ let t = r(this._value, e);
440
+ return t !== !1 && new Z(t);
441
+ }
442
+ dump(...e) {
443
+ return console.log(this._value, ...e), this;
444
+ }
445
+ toString() {
446
+ return this.value();
447
+ }
448
+ value() {
449
+ return String(this._value);
450
+ }
451
+ toInteger(e = 10) {
452
+ let t = Number(e) || 10;
453
+ return parseInt(this._value, t);
454
+ }
455
+ toFloat() {
456
+ return parseFloat(this._value);
457
+ }
458
+ toBoolean() {
459
+ let e = R(o(this._value));
460
+ return e === "1" || e === "true" || e === "on" || e === "yes";
461
+ }
462
+ toDate() {
463
+ let e = Date.parse(this._value);
464
+ return isNaN(e) ? null : new Date(e);
465
+ }
466
+ jsonSerialize() {
467
+ return this.toString();
468
+ }
1337
469
  };
470
+ export { $ as Stringable, Z as of, Ve as str };