@tolki/str 1.6.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -5
- package/dist/ascii/index.js +24 -39
- package/dist/base64/index.js +90 -118
- package/dist/convertcase/index.js +29 -44
- package/dist/index.js +14 -141
- package/dist/markdown/index.js +29 -31
- package/dist/pluralizer/index.js +30 -93
- package/dist/random/index.js +30 -42
- package/dist/replacer/index.js +39 -60
- package/dist/str.d.ts.map +1 -1
- package/dist/str.js +692 -996
- package/dist/stringable/index.d.ts +6 -3
- package/dist/stringable/index.d.ts.map +1 -1
- package/dist/stringable/index.js +462 -1326
- package/dist/transliterate/index.js +5 -6
- package/dist/trimmer/index.d.ts +3 -3
- package/dist/trimmer/index.d.ts.map +1 -1
- package/dist/trimmer/index.js +85 -122
- package/dist/ulid/index.js +42 -52
- package/dist/uuid/index.js +33 -43
- package/package.json +35 -22
package/dist/stringable/index.js
CHANGED
|
@@ -1,1334 +1,470 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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 {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
17
|
-
|
|
17
|
+
function Ve(e = "") {
|
|
18
|
+
return new $(e);
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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.
|
|
933
|
-
* @returns The trimmed string as a new Stringable instance.
|
|
934
|
-
*/
|
|
935
|
-
trim(e = null) {
|
|
936
|
-
return new r(w(this._value, e));
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Left trim the string of the given characters.
|
|
940
|
-
*
|
|
941
|
-
* @param charlist - The characters to trim from the start of the string. If null, trims whitespace.
|
|
942
|
-
* @returns The left-trimmed string as a new Stringable instance.
|
|
943
|
-
*/
|
|
944
|
-
ltrim(e = null) {
|
|
945
|
-
return new r(Ge(this._value, e));
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Right trim the string of the given characters.
|
|
949
|
-
*
|
|
950
|
-
* @param charlist - The characters to trim from the end of the string. If null, trims whitespace.
|
|
951
|
-
* @returns The right-trimmed string as a new Stringable instance.
|
|
952
|
-
*/
|
|
953
|
-
rtrim(e = null) {
|
|
954
|
-
return new r(Xe(this._value, e));
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Make a string's first character lowercase.
|
|
958
|
-
*
|
|
959
|
-
* @returns The updated Stringable instance.
|
|
960
|
-
*/
|
|
961
|
-
lcfirst() {
|
|
962
|
-
return new r(je(this._value));
|
|
963
|
-
}
|
|
964
|
-
/**
|
|
965
|
-
* Make a string's first character uppercase.
|
|
966
|
-
*
|
|
967
|
-
* @returns The updated Stringable instance.
|
|
968
|
-
*/
|
|
969
|
-
ucfirst() {
|
|
970
|
-
return new r(Te(this._value));
|
|
971
|
-
}
|
|
972
|
-
/**
|
|
973
|
-
* Split a string by uppercase characters.
|
|
974
|
-
*
|
|
975
|
-
* @returns An array of substrings split at uppercase characters.
|
|
976
|
-
*/
|
|
977
|
-
ucsplit() {
|
|
978
|
-
return De(this._value);
|
|
979
|
-
}
|
|
980
|
-
/**
|
|
981
|
-
* Uppercase the first character of each word in a string.
|
|
982
|
-
*
|
|
983
|
-
* @returns The updated Stringable instance.
|
|
984
|
-
*/
|
|
985
|
-
ucwords() {
|
|
986
|
-
return new r(qe(this._value));
|
|
987
|
-
}
|
|
988
|
-
/**
|
|
989
|
-
* Apply the callback if the given "value" is (or resolves to) truthy.
|
|
990
|
-
*
|
|
991
|
-
* @param value - The value to evaluate or a closure that returns the value
|
|
992
|
-
* @param callback - The callback to execute if the value is truthy
|
|
993
|
-
* @param defaultCallback - The callback to execute if the value is falsy
|
|
994
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
995
|
-
*
|
|
996
|
-
* @example
|
|
997
|
-
*
|
|
998
|
-
* ```typescript
|
|
999
|
-
* const str = new Stringable('hello world');
|
|
1000
|
-
*
|
|
1001
|
-
* Using a direct value
|
|
1002
|
-
* str.when(true, s => s.upper()); // Returns 'HELLO WORLD'
|
|
1003
|
-
* str.when(false, s => s.upper(), s => s.lower()); // Returns 'hello world'
|
|
1004
|
-
*
|
|
1005
|
-
* Using a closure to determine the value
|
|
1006
|
-
* str.when(s => s.contains('world'), s => s.upper()); // Returns 'HELLO WORLD'
|
|
1007
|
-
* str.when(s => s.contains('foo'), s => s.upper(), s => s.lower()); // Returns 'hello world'
|
|
1008
|
-
* ```
|
|
1009
|
-
*/
|
|
1010
|
-
when(e, t = null, s = null) {
|
|
1011
|
-
const n = a(e) ? e(this) : e;
|
|
1012
|
-
return n ? t?.(this, n) ?? this : s ? s(this, n) ?? this : this;
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Apply the callback if the given "value" is (or resolves to) falsy.
|
|
1016
|
-
*
|
|
1017
|
-
* @param value - The value to evaluate or a closure that returns the value
|
|
1018
|
-
* @param callback - The callback to execute if the value is falsy
|
|
1019
|
-
* @param defaultCallback - The callback to execute if the value is truthy
|
|
1020
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1021
|
-
*
|
|
1022
|
-
* @example
|
|
1023
|
-
*
|
|
1024
|
-
* const str = new Stringable('hello world');
|
|
1025
|
-
* str.unless(true, s => s.upper()); // Returns 'hello world'
|
|
1026
|
-
* str.unless(false, s => s.upper(), s => s.lower()); // Returns 'HELLO WORLD'
|
|
1027
|
-
*/
|
|
1028
|
-
unless(e, t = null, s = null) {
|
|
1029
|
-
const n = a(e) ? e(this) : e;
|
|
1030
|
-
if (n) {
|
|
1031
|
-
if (s)
|
|
1032
|
-
return s(this, n) ?? this;
|
|
1033
|
-
} else return t?.(this, n) ?? this;
|
|
1034
|
-
return this;
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Execute the given callback if the string contains a given substring.
|
|
1038
|
-
*
|
|
1039
|
-
* @param needles - The substring(s) to search for
|
|
1040
|
-
* @param callback - The callback to execute if the substring(s) are found
|
|
1041
|
-
* @param defaultCallback - The callback to execute if the substring(s) are not found
|
|
1042
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1043
|
-
*/
|
|
1044
|
-
whenContains(e, t, s = null) {
|
|
1045
|
-
return this.when(this.contains(e), t, s);
|
|
1046
|
-
}
|
|
1047
|
-
/**
|
|
1048
|
-
* Execute the given callback if the string contains all array values.
|
|
1049
|
-
*
|
|
1050
|
-
* @param needles - The substring(s) to search for
|
|
1051
|
-
* @param callback - The callback to execute if all substring(s) are found
|
|
1052
|
-
* @param defaultCallback - The callback to execute if not all substring(s) are found
|
|
1053
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1054
|
-
*/
|
|
1055
|
-
whenContainsAll(e, t, s = null) {
|
|
1056
|
-
return this.when(this.containsAll(e), t, s);
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* Execute the given callback if the string is empty.
|
|
1060
|
-
*
|
|
1061
|
-
* @param callback - The callback to execute if the string is empty
|
|
1062
|
-
* @param defaultCallback - The callback to execute if the string is not empty
|
|
1063
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1064
|
-
*/
|
|
1065
|
-
whenEmpty(e, t = null) {
|
|
1066
|
-
return this.when(this.isEmpty(), e, t);
|
|
1067
|
-
}
|
|
1068
|
-
/**
|
|
1069
|
-
* Execute the given callback if the string is not empty.
|
|
1070
|
-
*
|
|
1071
|
-
* @param callback - The callback to execute if the string is not empty
|
|
1072
|
-
* @param defaultCallback - The callback to execute if the string is empty
|
|
1073
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1074
|
-
*/
|
|
1075
|
-
whenNotEmpty(e, t = null) {
|
|
1076
|
-
return this.when(this.isNotEmpty(), e, t);
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* Execute the given callback if the string ends with a given substring.
|
|
1080
|
-
*
|
|
1081
|
-
* @param needles - The substring(s) to search for
|
|
1082
|
-
* @param callback - The callback to execute if the substring(s) are found
|
|
1083
|
-
* @param defaultCallback - The callback to execute if the substring(s) are not found
|
|
1084
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1085
|
-
*/
|
|
1086
|
-
whenEndsWith(e, t, s = null) {
|
|
1087
|
-
return this.when(this.endsWith(e), t, s);
|
|
1088
|
-
}
|
|
1089
|
-
/**
|
|
1090
|
-
* Execute the given callback if the string doesn't end with a given substring.
|
|
1091
|
-
*
|
|
1092
|
-
* @param needles - The substring(s) to search for
|
|
1093
|
-
* @param callback - The callback to execute if the substring(s) are not found
|
|
1094
|
-
* @param defaultCallback - The callback to execute if the substring(s) are found
|
|
1095
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1096
|
-
*/
|
|
1097
|
-
whenDoesntEndWith(e, t, s = null) {
|
|
1098
|
-
return this.when(
|
|
1099
|
-
this.doesntEndWith(e),
|
|
1100
|
-
t,
|
|
1101
|
-
s
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Execute the given callback if the string is an exact match with the given value.
|
|
1106
|
-
*
|
|
1107
|
-
* @param value - The value to compare against
|
|
1108
|
-
* @param callback - The callback to execute if the string matches the value
|
|
1109
|
-
* @param defaultCallback - The callback to execute if the string does not match the value
|
|
1110
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1111
|
-
*/
|
|
1112
|
-
whenExactly(e, t, s = null) {
|
|
1113
|
-
return this.when(this.exactly(e), t, s);
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Execute the given callback if the string is not an exact match with the given value.
|
|
1117
|
-
*
|
|
1118
|
-
* @param value - The value to compare against
|
|
1119
|
-
* @param callback - The callback to execute if the string does not match the value
|
|
1120
|
-
* @param defaultCallback - The callback to execute if the string matches the value
|
|
1121
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1122
|
-
*/
|
|
1123
|
-
whenNotExactly(e, t, s = null) {
|
|
1124
|
-
return this.when(!this.exactly(e), t, s);
|
|
1125
|
-
}
|
|
1126
|
-
/**
|
|
1127
|
-
* Execute the given callback if the string matches a given pattern.
|
|
1128
|
-
*
|
|
1129
|
-
* @param pattern - The pattern(s) to match against
|
|
1130
|
-
* @param callback - The callback to execute if the pattern(s) match
|
|
1131
|
-
* @param defaultCallback - The callback to execute if the pattern(s) do not match
|
|
1132
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1133
|
-
*/
|
|
1134
|
-
whenIs(e, t, s = null) {
|
|
1135
|
-
return this.when(this.is(e), t, s);
|
|
1136
|
-
}
|
|
1137
|
-
/**
|
|
1138
|
-
* Execute the given callback if the string is 7 bit ASCII.
|
|
1139
|
-
*
|
|
1140
|
-
* @param callback - The callback to execute if the string is ASCII
|
|
1141
|
-
* @param defaultCallback - The callback to execute if the string is not ASCII
|
|
1142
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1143
|
-
*/
|
|
1144
|
-
whenIsAscii(e, t = null) {
|
|
1145
|
-
return this.when(this.isAscii(), e, t);
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Execute the given callback if the string is a valid UUID.
|
|
1149
|
-
*
|
|
1150
|
-
* @param callback - The callback to execute if the string is a UUID
|
|
1151
|
-
* @param defaultCallback - The callback to execute if the string is not a UUID
|
|
1152
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1153
|
-
*/
|
|
1154
|
-
whenIsUuid(e, t = null) {
|
|
1155
|
-
return this.when(this.isUuid(), e, t);
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Execute the given callback if the string is a valid ULID.
|
|
1159
|
-
*
|
|
1160
|
-
* @param callback - The callback to execute if the string is a ULID
|
|
1161
|
-
* @param defaultCallback - The callback to execute if the string is not a ULID
|
|
1162
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1163
|
-
*/
|
|
1164
|
-
whenIsUlid(e, t = null) {
|
|
1165
|
-
return this.when(this.isUlid(), e, t);
|
|
1166
|
-
}
|
|
1167
|
-
/**
|
|
1168
|
-
* Execute the given callback if the string starts with a given substring.
|
|
1169
|
-
*
|
|
1170
|
-
* @param needles - The substring(s) to search for
|
|
1171
|
-
* @param callback - The callback to execute if the substring(s) are found
|
|
1172
|
-
* @param defaultCallback - The callback to execute if the substring(s) are not found
|
|
1173
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1174
|
-
*/
|
|
1175
|
-
whenStartsWith(e, t, s = null) {
|
|
1176
|
-
return this.when(this.startsWith(e), t, s);
|
|
1177
|
-
}
|
|
1178
|
-
/**
|
|
1179
|
-
* Execute the given callback if the string matches the given pattern.
|
|
1180
|
-
*
|
|
1181
|
-
* @param pattern - The pattern(s) to match against
|
|
1182
|
-
* @param callback - The callback to execute if the pattern(s) match
|
|
1183
|
-
* @param defaultCallback - The callback to execute if the pattern(s) do not match
|
|
1184
|
-
* @returns Stringable - The current instance or the result of the callback
|
|
1185
|
-
*/
|
|
1186
|
-
whenTest(e, t, s = null) {
|
|
1187
|
-
return this.when(this.test(e), t, s);
|
|
1188
|
-
}
|
|
1189
|
-
/**
|
|
1190
|
-
* Limit the number of words in a string.
|
|
1191
|
-
*
|
|
1192
|
-
* @param wordsValue - The maximum number of words allowed. Defaults to 100.
|
|
1193
|
-
* @param end - The string to append if the string is truncated. Defaults to "...".
|
|
1194
|
-
* @returns The truncated string as a new Stringable instance.
|
|
1195
|
-
*/
|
|
1196
|
-
words(e = 100, t = "...") {
|
|
1197
|
-
return new r(Oe(this._value, e, t));
|
|
1198
|
-
}
|
|
1199
|
-
/**
|
|
1200
|
-
* Get the number of words a string contains.
|
|
1201
|
-
*
|
|
1202
|
-
* @param characters - The characters to consider as word boundaries. If null, defaults to standard word boundaries.
|
|
1203
|
-
* @returns The number of words in the string.
|
|
1204
|
-
*/
|
|
1205
|
-
wordCount(e = null) {
|
|
1206
|
-
return Pe(this._value, e);
|
|
1207
|
-
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Wrap a string to a given number of characters.
|
|
1210
|
-
*
|
|
1211
|
-
* @param characters - The number of characters at which to wrap the string. Defaults to 75.
|
|
1212
|
-
* @param breakStr - The string to insert as a break. Defaults to "\n".
|
|
1213
|
-
* @param cutLongWords - Whether to cut words longer than the specified length. Defaults to false.
|
|
1214
|
-
* @returns The wrapped string as a new Stringable instance.
|
|
1215
|
-
*/
|
|
1216
|
-
wordWrap(e = 75, t = `
|
|
1217
|
-
`, s = !1) {
|
|
1218
|
-
return new r(
|
|
1219
|
-
$e(this._value, e, t, s)
|
|
1220
|
-
);
|
|
1221
|
-
}
|
|
1222
|
-
/**
|
|
1223
|
-
* Wrap the string with the given strings.
|
|
1224
|
-
*
|
|
1225
|
-
* @param before - The string to prepend
|
|
1226
|
-
* @param after - The string to append. Defaults to the value of `before`
|
|
1227
|
-
* @returns The wrapped string as a new Stringable instance.
|
|
1228
|
-
*/
|
|
1229
|
-
wrap(e, t = null) {
|
|
1230
|
-
return new r(Je(this._value, e, t));
|
|
1231
|
-
}
|
|
1232
|
-
/**
|
|
1233
|
-
* Unwrap the string with the given strings.
|
|
1234
|
-
*
|
|
1235
|
-
* @param before - The string to remove from the start
|
|
1236
|
-
* @param after - The string to remove from the end. Defaults to the value of `before`
|
|
1237
|
-
* @returns The unwrapped string as a new Stringable instance.
|
|
1238
|
-
*/
|
|
1239
|
-
unwrap(e, t = null) {
|
|
1240
|
-
return new r(Ve(this._value, e, t));
|
|
1241
|
-
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Convert the string to Base64 encoding.
|
|
1244
|
-
*
|
|
1245
|
-
* @returns The Base64 encoded string as a new Stringable instance.
|
|
1246
|
-
*/
|
|
1247
|
-
toBase64() {
|
|
1248
|
-
return new r(m(this._value));
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Decode the Base64 encoded string.
|
|
1252
|
-
*
|
|
1253
|
-
* @param strict - Whether to use strict decoding. Defaults to false.
|
|
1254
|
-
* @returns The decoded string as a new Stringable instance, or false on failure.
|
|
1255
|
-
*/
|
|
1256
|
-
fromBase64(e = !1) {
|
|
1257
|
-
const t = f(this._value, e);
|
|
1258
|
-
return t === !1 ? !1 : new r(t);
|
|
1259
|
-
}
|
|
1260
|
-
/**
|
|
1261
|
-
* Dump the string and the given arguments to the console.
|
|
1262
|
-
*
|
|
1263
|
-
* @param args - Extra values to log alongside the string.
|
|
1264
|
-
* @returns The current instance.
|
|
1265
|
-
*/
|
|
1266
|
-
dump(...e) {
|
|
1267
|
-
return console.log(this._value, ...e), this;
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Get the underlying string value.
|
|
1271
|
-
*
|
|
1272
|
-
* @returns The string representation of the object.
|
|
1273
|
-
*/
|
|
1274
|
-
toString() {
|
|
1275
|
-
return this.value();
|
|
1276
|
-
}
|
|
1277
|
-
/**
|
|
1278
|
-
* Get the underlying string value.
|
|
1279
|
-
*
|
|
1280
|
-
* @returns The string value.
|
|
1281
|
-
*/
|
|
1282
|
-
value() {
|
|
1283
|
-
return String(this._value);
|
|
1284
|
-
}
|
|
1285
|
-
/**
|
|
1286
|
-
* Get the underlying string value as an integer.
|
|
1287
|
-
*
|
|
1288
|
-
* @param base - The base to use for conversion. Defaults to 10.
|
|
1289
|
-
* @returns The integer value.
|
|
1290
|
-
*/
|
|
1291
|
-
toInteger(e = 10) {
|
|
1292
|
-
const t = Number(e) || 10;
|
|
1293
|
-
return parseInt(this._value, t);
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Get the underlying string value as a float.
|
|
1297
|
-
*
|
|
1298
|
-
* @returns The float value.
|
|
1299
|
-
*/
|
|
1300
|
-
toFloat() {
|
|
1301
|
-
return parseFloat(this._value);
|
|
1302
|
-
}
|
|
1303
|
-
/**
|
|
1304
|
-
* Get the underlying string value as a boolean.
|
|
1305
|
-
*
|
|
1306
|
-
* @returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.
|
|
1307
|
-
*/
|
|
1308
|
-
toBoolean() {
|
|
1309
|
-
const e = o(w(this._value));
|
|
1310
|
-
return e === "1" || e === "true" || e === "on" || e === "yes";
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* Get the underlying string value as a Date instance.
|
|
1314
|
-
*
|
|
1315
|
-
* @returns The Date instance or null if parsing fails.
|
|
1316
|
-
*/
|
|
1317
|
-
toDate() {
|
|
1318
|
-
const e = Date.parse(this._value);
|
|
1319
|
-
return isNaN(e) ? null : new Date(e);
|
|
1320
|
-
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Convert the object to a string when JSON encoded.
|
|
1323
|
-
*
|
|
1324
|
-
* @returns The string representation of the object.
|
|
1325
|
-
*/
|
|
1326
|
-
jsonSerialize() {
|
|
1327
|
-
return this.toString();
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
export {
|
|
1331
|
-
r as Stringable,
|
|
1332
|
-
at as of,
|
|
1333
|
-
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
|
+
}
|
|
1334
469
|
};
|
|
470
|
+
export { $ as Stringable, Z as of, Ve as str };
|