@tolki/str 1.0.5 → 1.0.6
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/dist/ascii/index.d.ts.map +1 -1
- package/dist/ascii/index.js +4 -4
- package/dist/random/index.d.ts.map +1 -1
- package/dist/random/index.js +1 -1
- package/dist/str.d.ts.map +1 -1
- package/dist/str.js +145 -142
- package/dist/stringable/index.d.ts +2 -1
- package/dist/stringable/index.d.ts.map +1 -1
- package/dist/stringable/index.js +108 -98
- package/package.json +2 -2
package/dist/stringable/index.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { isInteger as v, isFunction as l } from "@tolki/utils";
|
|
2
|
+
import { ascii as c, slug as p } from "../ascii/index.js";
|
|
3
|
+
import { toBase64 as d, fromBase64 as f } from "../base64/index.js";
|
|
4
|
+
import { convertCase as m, upper as _, title as E } from "../convertcase/index.js";
|
|
5
|
+
import { markdown as y, inlineMarkdown as A } from "../markdown/index.js";
|
|
6
|
+
import { plural as W, pluralStudly as x, pluralPascal as k, singular as N } from "../pluralizer/index.js";
|
|
7
|
+
import { substr as U, substrCount as C, substrReplace as L } from "../replacer/index.js";
|
|
8
|
+
import { after as M, afterLast as F, before as I, beforeLast as B, between as R, betweenFirst as j, camel as D, charAt as T, chopStart as P, chopEnd as q, contains as J, containsAll as V, doesntContain as $, deduplicate as z, endsWith as G, doesntEndWith as X, excerpt as H, finish as K, is as O, isAscii as Q, isJson as Y, isUrl as Z, kebab as g, length as b, limit as S, lower as a, mask as ee, match as te, isMatch as se, matchAll as re, numbers as ne, padBoth as ue, padLeft as ie, padRight as he, position as le, remove as ae, reverse as oe, repeat as we, replace as ve, replaceArray as ce, replaceFirst as pe, replaceStart as de, replaceLast as fe, replaceEnd as me, replaceMatches as _e, squish as Ee, start as ye, stripTags as Ae, headline as We, apa as xe, snake as ke, startsWith as Ne, doesntStartWith as Ue, studly as Ce, pascal as Le, swap as Me, take as Fe, lcfirst as Ie, ucfirst as Be, ucsplit as Re, ucwords as je, words as De, wordCount as Te, wordWrap as Pe, wrap as qe, unwrap as Je } from "../str.js";
|
|
9
|
+
import { transliterate as Ve } from "../transliterate/index.js";
|
|
10
|
+
import { trim as o, ltrim as $e, rtrim as ze } from "../trimmer/index.js";
|
|
11
|
+
import { isUlid as Ge } from "../ulid/index.js";
|
|
12
|
+
import { isUuid as Xe } from "../uuid/index.js";
|
|
13
|
+
function rt(h = "") {
|
|
4
14
|
return new s(h);
|
|
5
15
|
}
|
|
6
|
-
function
|
|
16
|
+
function nt(h = "") {
|
|
7
17
|
return new s(h);
|
|
8
18
|
}
|
|
9
19
|
class s {
|
|
@@ -22,7 +32,7 @@ class s {
|
|
|
22
32
|
* @returns The portion of the string after the first occurrence of the search value.
|
|
23
33
|
*/
|
|
24
34
|
after(e) {
|
|
25
|
-
return new s(
|
|
35
|
+
return new s(M(this._value, e));
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
28
38
|
* Return the remainder of a string after the last occurrence of a given value
|
|
@@ -31,7 +41,7 @@ class s {
|
|
|
31
41
|
* @returns The portion of the string after the last occurrence of the search value.
|
|
32
42
|
*/
|
|
33
43
|
afterLast(e) {
|
|
34
|
-
return new s(
|
|
44
|
+
return new s(F(this._value, e));
|
|
35
45
|
}
|
|
36
46
|
/**
|
|
37
47
|
* Append the given values to the string.
|
|
@@ -58,7 +68,7 @@ class s {
|
|
|
58
68
|
* @returns The transliterated string as a new Stringable instance.
|
|
59
69
|
*/
|
|
60
70
|
ascii() {
|
|
61
|
-
return new s(
|
|
71
|
+
return new s(c(this._value));
|
|
62
72
|
}
|
|
63
73
|
/**
|
|
64
74
|
* Get the portion of a string before the first occurrence of a given value.
|
|
@@ -67,7 +77,7 @@ class s {
|
|
|
67
77
|
* @returns The portion of the string before the first occurrence of the search value.
|
|
68
78
|
*/
|
|
69
79
|
before(e) {
|
|
70
|
-
return new s(
|
|
80
|
+
return new s(I(this._value, e));
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
73
83
|
* Get the portion of a string before the last occurrence of a given value.
|
|
@@ -76,7 +86,7 @@ class s {
|
|
|
76
86
|
* @returns The portion of the string before the last occurrence of the search value.
|
|
77
87
|
*/
|
|
78
88
|
beforeLast(e) {
|
|
79
|
-
return new s(
|
|
89
|
+
return new s(B(this._value, e));
|
|
80
90
|
}
|
|
81
91
|
/**
|
|
82
92
|
* Get the portion of a string between two given values.
|
|
@@ -86,7 +96,7 @@ class s {
|
|
|
86
96
|
* @returns The portion of the string between the two given values.
|
|
87
97
|
*/
|
|
88
98
|
between(e, t) {
|
|
89
|
-
return new s(
|
|
99
|
+
return new s(R(this._value, e, t));
|
|
90
100
|
}
|
|
91
101
|
/**
|
|
92
102
|
* Get the smallest possible portion of a string between two given values.
|
|
@@ -96,7 +106,7 @@ class s {
|
|
|
96
106
|
* @returns The smallest possible portion of the string between the two given values.
|
|
97
107
|
*/
|
|
98
108
|
betweenFirst(e, t) {
|
|
99
|
-
return new s(
|
|
109
|
+
return new s(j(this._value, e, t));
|
|
100
110
|
}
|
|
101
111
|
/**
|
|
102
112
|
* Convert a value to camel case.
|
|
@@ -104,7 +114,7 @@ class s {
|
|
|
104
114
|
* @returns The camel-cased string as a new Stringable instance.
|
|
105
115
|
*/
|
|
106
116
|
camel() {
|
|
107
|
-
return new s(
|
|
117
|
+
return new s(D(this._value));
|
|
108
118
|
}
|
|
109
119
|
/**
|
|
110
120
|
* Get the character at the specified index.
|
|
@@ -113,7 +123,7 @@ class s {
|
|
|
113
123
|
* @returns The character at the specified index, or false if the index is out of bounds.
|
|
114
124
|
*/
|
|
115
125
|
charAt(e) {
|
|
116
|
-
return
|
|
126
|
+
return T(this._value, e);
|
|
117
127
|
}
|
|
118
128
|
/**
|
|
119
129
|
* Remove the given string if it exists at the start of the current string.
|
|
@@ -122,7 +132,7 @@ class s {
|
|
|
122
132
|
* @returns The updated Stringable instance.
|
|
123
133
|
*/
|
|
124
134
|
chopStart(e) {
|
|
125
|
-
return new s(
|
|
135
|
+
return new s(P(this._value, e));
|
|
126
136
|
}
|
|
127
137
|
/**
|
|
128
138
|
* Remove the given string if it exists at the end of the current string.
|
|
@@ -131,7 +141,7 @@ class s {
|
|
|
131
141
|
* @returns The updated Stringable instance.
|
|
132
142
|
*/
|
|
133
143
|
chopEnd(e) {
|
|
134
|
-
return new s(
|
|
144
|
+
return new s(q(this._value, e));
|
|
135
145
|
}
|
|
136
146
|
/**
|
|
137
147
|
* Determine if a given string contains a given substring.
|
|
@@ -141,7 +151,7 @@ class s {
|
|
|
141
151
|
* @returns boolean - True if the substring(s) are found, false otherwise
|
|
142
152
|
*/
|
|
143
153
|
contains(e, t = !1) {
|
|
144
|
-
return
|
|
154
|
+
return J(this._value, e, t);
|
|
145
155
|
}
|
|
146
156
|
/**
|
|
147
157
|
* Determine if a given string contains all array values.
|
|
@@ -151,7 +161,7 @@ class s {
|
|
|
151
161
|
* @returns boolean - True if all substring(s) are found, false otherwise
|
|
152
162
|
*/
|
|
153
163
|
containsAll(e, t = !1) {
|
|
154
|
-
return
|
|
164
|
+
return V(this._value, e, t);
|
|
155
165
|
}
|
|
156
166
|
/**
|
|
157
167
|
* Determine if a given string doesn't contain a given substring.
|
|
@@ -161,7 +171,7 @@ class s {
|
|
|
161
171
|
* @returns boolean - True if the substring(s) are not found, false otherwise
|
|
162
172
|
*/
|
|
163
173
|
doesntContain(e, t = !1) {
|
|
164
|
-
return
|
|
174
|
+
return $(this._value, e, t);
|
|
165
175
|
}
|
|
166
176
|
/**
|
|
167
177
|
* Convert the case of a string.
|
|
@@ -170,7 +180,7 @@ class s {
|
|
|
170
180
|
* @returns The converted string as a new Stringable instance.
|
|
171
181
|
*/
|
|
172
182
|
convertCase(e) {
|
|
173
|
-
return new s(
|
|
183
|
+
return new s(m(this._value, e));
|
|
174
184
|
}
|
|
175
185
|
/**
|
|
176
186
|
* Replace consecutive instances of a given character with a single character.
|
|
@@ -179,7 +189,7 @@ class s {
|
|
|
179
189
|
* @returns The updated Stringable instance.
|
|
180
190
|
*/
|
|
181
191
|
deduplicate(e = " ") {
|
|
182
|
-
return new s(
|
|
192
|
+
return new s(z(this._value, e));
|
|
183
193
|
}
|
|
184
194
|
/**
|
|
185
195
|
* Determine if a given string ends with a given substring.
|
|
@@ -188,7 +198,7 @@ class s {
|
|
|
188
198
|
* @returns boolean - True if the substring(s) are found, false otherwise
|
|
189
199
|
*/
|
|
190
200
|
endsWith(e) {
|
|
191
|
-
return
|
|
201
|
+
return G(this._value, e);
|
|
192
202
|
}
|
|
193
203
|
/**
|
|
194
204
|
* Determine if a given string doesn't end with a given substring.
|
|
@@ -197,7 +207,7 @@ class s {
|
|
|
197
207
|
* @returns boolean - True if the substring(s) are not found, false otherwise
|
|
198
208
|
*/
|
|
199
209
|
doesntEndWith(e) {
|
|
200
|
-
return
|
|
210
|
+
return X(this._value, e);
|
|
201
211
|
}
|
|
202
212
|
/**
|
|
203
213
|
* Determine if the string is an exact match with the given value.
|
|
@@ -217,7 +227,7 @@ class s {
|
|
|
217
227
|
* @returns The extracted excerpt or null if the phrase is not found.
|
|
218
228
|
*/
|
|
219
229
|
excerpt(e = "", t = {}) {
|
|
220
|
-
return
|
|
230
|
+
return H(this._value, e, t);
|
|
221
231
|
}
|
|
222
232
|
/**
|
|
223
233
|
* Explode the string into an array
|
|
@@ -243,7 +253,7 @@ class s {
|
|
|
243
253
|
* @returns An array of strings obtained by splitting the original string.
|
|
244
254
|
*/
|
|
245
255
|
split(e, t = null) {
|
|
246
|
-
if (
|
|
256
|
+
if (v(e)) {
|
|
247
257
|
const n = Number(e), i = [];
|
|
248
258
|
for (let u = 0; u < this._value.length; u += n)
|
|
249
259
|
i.push(this._value.substr(u, n));
|
|
@@ -261,7 +271,7 @@ class s {
|
|
|
261
271
|
* @returns The updated Stringable instance.
|
|
262
272
|
*/
|
|
263
273
|
finish(e) {
|
|
264
|
-
return new s(
|
|
274
|
+
return new s(K(this._value, e));
|
|
265
275
|
}
|
|
266
276
|
/**
|
|
267
277
|
* Determine if a given string matches a given pattern.
|
|
@@ -270,7 +280,7 @@ class s {
|
|
|
270
280
|
* @returns boolean - True if the pattern(s) match, false otherwise
|
|
271
281
|
*/
|
|
272
282
|
is(e, t = !1) {
|
|
273
|
-
return
|
|
283
|
+
return O(e, this._value, t);
|
|
274
284
|
}
|
|
275
285
|
/**
|
|
276
286
|
* Determine if a given string is 7 bit ASCII.
|
|
@@ -278,7 +288,7 @@ class s {
|
|
|
278
288
|
* @returns True if the string is ASCII, false otherwise.
|
|
279
289
|
*/
|
|
280
290
|
isAscii() {
|
|
281
|
-
return
|
|
291
|
+
return Q(this._value);
|
|
282
292
|
}
|
|
283
293
|
/**
|
|
284
294
|
* Determine if a given string is valid JSON.
|
|
@@ -286,7 +296,7 @@ class s {
|
|
|
286
296
|
* @returns True if the string is valid JSON, false otherwise.
|
|
287
297
|
*/
|
|
288
298
|
isJson() {
|
|
289
|
-
return
|
|
299
|
+
return Y(this._value);
|
|
290
300
|
}
|
|
291
301
|
/**
|
|
292
302
|
* Determine if a given value is a valid URL.
|
|
@@ -295,7 +305,7 @@ class s {
|
|
|
295
305
|
* @returns True if the string is a valid URL, false otherwise.
|
|
296
306
|
*/
|
|
297
307
|
isUrl(e = []) {
|
|
298
|
-
return
|
|
308
|
+
return Z(this._value, e);
|
|
299
309
|
}
|
|
300
310
|
/**
|
|
301
311
|
* Determine if a given string is a valid UUID.
|
|
@@ -304,7 +314,7 @@ class s {
|
|
|
304
314
|
* @returns True if the string is a valid UUID, false otherwise.
|
|
305
315
|
*/
|
|
306
316
|
isUuid(e = null) {
|
|
307
|
-
return
|
|
317
|
+
return Xe(this._value, e);
|
|
308
318
|
}
|
|
309
319
|
/**
|
|
310
320
|
* Determine if a given string is a valid ULID.
|
|
@@ -312,7 +322,7 @@ class s {
|
|
|
312
322
|
* @return True if the string is a valid ULID, false otherwise.
|
|
313
323
|
*/
|
|
314
324
|
isUlid() {
|
|
315
|
-
return
|
|
325
|
+
return Ge(this._value);
|
|
316
326
|
}
|
|
317
327
|
/**
|
|
318
328
|
* Determine if the given string is empty.
|
|
@@ -336,7 +346,7 @@ class s {
|
|
|
336
346
|
* @returns The kebab-cased string as a new Stringable instance.
|
|
337
347
|
*/
|
|
338
348
|
kebab() {
|
|
339
|
-
return new s(
|
|
349
|
+
return new s(g(this._value));
|
|
340
350
|
}
|
|
341
351
|
/**
|
|
342
352
|
* Return the length of the given string.
|
|
@@ -344,7 +354,7 @@ class s {
|
|
|
344
354
|
* @returns The length of the string.
|
|
345
355
|
*/
|
|
346
356
|
length() {
|
|
347
|
-
return
|
|
357
|
+
return b(this._value);
|
|
348
358
|
}
|
|
349
359
|
/**
|
|
350
360
|
* Limit the number of characters in a string.
|
|
@@ -356,7 +366,7 @@ class s {
|
|
|
356
366
|
*/
|
|
357
367
|
limit(e = 100, t = "...", r = !1) {
|
|
358
368
|
return new s(
|
|
359
|
-
|
|
369
|
+
S(this._value, e, t, r)
|
|
360
370
|
);
|
|
361
371
|
}
|
|
362
372
|
/**
|
|
@@ -365,7 +375,7 @@ class s {
|
|
|
365
375
|
* @returns The lower-cased string as a new Stringable instance.
|
|
366
376
|
*/
|
|
367
377
|
lower() {
|
|
368
|
-
return new s(
|
|
378
|
+
return new s(a(this._value));
|
|
369
379
|
}
|
|
370
380
|
/**
|
|
371
381
|
* Convert GitHub flavored Markdown into HTML.
|
|
@@ -375,7 +385,7 @@ class s {
|
|
|
375
385
|
* @returns The resulting HTML string as a new Stringable instance.
|
|
376
386
|
*/
|
|
377
387
|
markdown(e = { gfm: !0, anchors: !1 }, t = []) {
|
|
378
|
-
return new s(
|
|
388
|
+
return new s(y(this._value, e, t));
|
|
379
389
|
}
|
|
380
390
|
/**
|
|
381
391
|
* Convert inline Markdown into HTML.
|
|
@@ -385,7 +395,7 @@ class s {
|
|
|
385
395
|
* @returns The resulting HTML string as a new Stringable instance.
|
|
386
396
|
*/
|
|
387
397
|
inlineMarkdown(e = { gfm: !0 }, t = []) {
|
|
388
|
-
return new s(
|
|
398
|
+
return new s(A(this._value, e, t));
|
|
389
399
|
}
|
|
390
400
|
/**
|
|
391
401
|
* Masks a portion of a string with a repeated character.
|
|
@@ -396,7 +406,7 @@ class s {
|
|
|
396
406
|
* @returns The masked string as a new Stringable instance.
|
|
397
407
|
*/
|
|
398
408
|
mask(e, t, r = null) {
|
|
399
|
-
return new s(
|
|
409
|
+
return new s(ee(this._value, e, t, r));
|
|
400
410
|
}
|
|
401
411
|
/**
|
|
402
412
|
* Get the string matching the given pattern.
|
|
@@ -405,7 +415,7 @@ class s {
|
|
|
405
415
|
* @returns A new Stringable instance containing the matched string.
|
|
406
416
|
*/
|
|
407
417
|
match(e) {
|
|
408
|
-
return new s(
|
|
418
|
+
return new s(te(e, this._value));
|
|
409
419
|
}
|
|
410
420
|
/**
|
|
411
421
|
* Determine if a given string matches a given pattern.
|
|
@@ -414,7 +424,7 @@ class s {
|
|
|
414
424
|
* @returns boolean - True if the pattern(s) match, false otherwise
|
|
415
425
|
*/
|
|
416
426
|
isMatch(e) {
|
|
417
|
-
return
|
|
427
|
+
return se(e, this._value);
|
|
418
428
|
}
|
|
419
429
|
/**
|
|
420
430
|
* Get the string matching the given pattern.
|
|
@@ -423,7 +433,7 @@ class s {
|
|
|
423
433
|
* @returns An array of all matched strings.
|
|
424
434
|
*/
|
|
425
435
|
matchAll(e) {
|
|
426
|
-
return
|
|
436
|
+
return re(e, this._value);
|
|
427
437
|
}
|
|
428
438
|
/**
|
|
429
439
|
* Determine if the string matches the given pattern.
|
|
@@ -440,7 +450,7 @@ class s {
|
|
|
440
450
|
* @returns The numeric string as a new Stringable instance.
|
|
441
451
|
*/
|
|
442
452
|
numbers() {
|
|
443
|
-
return new s(
|
|
453
|
+
return new s(ne(this._value));
|
|
444
454
|
}
|
|
445
455
|
/**
|
|
446
456
|
* Pad both sides of the string with another.
|
|
@@ -450,7 +460,7 @@ class s {
|
|
|
450
460
|
* @returns The padded string as a new Stringable instance.
|
|
451
461
|
*/
|
|
452
462
|
padBoth(e, t = " ") {
|
|
453
|
-
return new s(
|
|
463
|
+
return new s(ue(this._value, e, t));
|
|
454
464
|
}
|
|
455
465
|
/**
|
|
456
466
|
* Pad the left side of the string with another.
|
|
@@ -460,7 +470,7 @@ class s {
|
|
|
460
470
|
* @returns The padded string as a new Stringable instance.
|
|
461
471
|
*/
|
|
462
472
|
padLeft(e, t = " ") {
|
|
463
|
-
return new s(
|
|
473
|
+
return new s(ie(this._value, e, t));
|
|
464
474
|
}
|
|
465
475
|
/**
|
|
466
476
|
* Pad the right side of the string with another.
|
|
@@ -470,7 +480,7 @@ class s {
|
|
|
470
480
|
* @returns The padded string as a new Stringable instance.
|
|
471
481
|
*/
|
|
472
482
|
padRight(e, t = " ") {
|
|
473
|
-
return new s(
|
|
483
|
+
return new s(he(this._value, e, t));
|
|
474
484
|
}
|
|
475
485
|
/**
|
|
476
486
|
* Call the given callback and return a new string.
|
|
@@ -490,7 +500,7 @@ class s {
|
|
|
490
500
|
* @returns The pluralized string as a new Stringable instance.
|
|
491
501
|
*/
|
|
492
502
|
plural(e = 2, t = !1) {
|
|
493
|
-
return new s(
|
|
503
|
+
return new s(W(this._value, e, t));
|
|
494
504
|
}
|
|
495
505
|
/**
|
|
496
506
|
* Pluralize the last word of an English, studly caps case string.
|
|
@@ -499,7 +509,7 @@ class s {
|
|
|
499
509
|
* @returns The pluralized string as a new Stringable instance.
|
|
500
510
|
*/
|
|
501
511
|
pluralStudly(e = 2) {
|
|
502
|
-
return new s(
|
|
512
|
+
return new s(x(this._value, e));
|
|
503
513
|
}
|
|
504
514
|
/**
|
|
505
515
|
* Pluralize the last word of an English, Pascal caps case string.
|
|
@@ -508,7 +518,7 @@ class s {
|
|
|
508
518
|
* @returns The pluralized string as a new Stringable instance.
|
|
509
519
|
*/
|
|
510
520
|
pluralPascal(e = 2) {
|
|
511
|
-
return new s(
|
|
521
|
+
return new s(k(this._value, e));
|
|
512
522
|
}
|
|
513
523
|
/**
|
|
514
524
|
* Find the multi-byte safe position of the first occurrence of the given substring.
|
|
@@ -518,7 +528,7 @@ class s {
|
|
|
518
528
|
* @returns The position of the first occurrence of the substring, or false if not found.
|
|
519
529
|
*/
|
|
520
530
|
position(e, t = 0) {
|
|
521
|
-
return
|
|
531
|
+
return le(this._value, e, t);
|
|
522
532
|
}
|
|
523
533
|
/**
|
|
524
534
|
* Prepend the given values to the string.
|
|
@@ -538,7 +548,7 @@ class s {
|
|
|
538
548
|
*/
|
|
539
549
|
remove(e, t = !0) {
|
|
540
550
|
return new s(
|
|
541
|
-
|
|
551
|
+
ae(e, this._value, t)
|
|
542
552
|
);
|
|
543
553
|
}
|
|
544
554
|
/**
|
|
@@ -547,7 +557,7 @@ class s {
|
|
|
547
557
|
* @returns The reversed string as a new Stringable instance.
|
|
548
558
|
*/
|
|
549
559
|
reverse() {
|
|
550
|
-
return new s(
|
|
560
|
+
return new s(oe(this._value));
|
|
551
561
|
}
|
|
552
562
|
/**
|
|
553
563
|
* Repeat the string.
|
|
@@ -556,7 +566,7 @@ class s {
|
|
|
556
566
|
* @returns The repeated string as a new Stringable instance.
|
|
557
567
|
*/
|
|
558
568
|
repeat(e) {
|
|
559
|
-
return new s(
|
|
569
|
+
return new s(we(this._value, e));
|
|
560
570
|
}
|
|
561
571
|
/**
|
|
562
572
|
* Replace the given value in the given string.
|
|
@@ -568,7 +578,7 @@ class s {
|
|
|
568
578
|
*/
|
|
569
579
|
replace(e, t, r = !0) {
|
|
570
580
|
return new s(
|
|
571
|
-
|
|
581
|
+
ve(e, t, this._value, r)
|
|
572
582
|
);
|
|
573
583
|
}
|
|
574
584
|
/**
|
|
@@ -579,7 +589,7 @@ class s {
|
|
|
579
589
|
* @returns The updated Stringable instance.
|
|
580
590
|
*/
|
|
581
591
|
replaceArray(e, t) {
|
|
582
|
-
return new s(
|
|
592
|
+
return new s(ce(e, t, this._value));
|
|
583
593
|
}
|
|
584
594
|
/**
|
|
585
595
|
* Replace the first occurrence of a given value in the string.
|
|
@@ -589,7 +599,7 @@ class s {
|
|
|
589
599
|
* @returns The updated Stringable instance.
|
|
590
600
|
*/
|
|
591
601
|
replaceFirst(e, t) {
|
|
592
|
-
return new s(
|
|
602
|
+
return new s(pe(e, t, this._value));
|
|
593
603
|
}
|
|
594
604
|
/**
|
|
595
605
|
* Replace the first occurrence of the given value if it appears at the start of the string.
|
|
@@ -599,7 +609,7 @@ class s {
|
|
|
599
609
|
* @returns The updated Stringable instance.
|
|
600
610
|
*/
|
|
601
611
|
replaceStart(e, t) {
|
|
602
|
-
return new s(
|
|
612
|
+
return new s(de(e, t, this._value));
|
|
603
613
|
}
|
|
604
614
|
/**
|
|
605
615
|
* Replace the last occurrence of a given value in the string.
|
|
@@ -609,7 +619,7 @@ class s {
|
|
|
609
619
|
* @returns The updated Stringable instance.
|
|
610
620
|
*/
|
|
611
621
|
replaceLast(e, t) {
|
|
612
|
-
return new s(
|
|
622
|
+
return new s(fe(e, t, this._value));
|
|
613
623
|
}
|
|
614
624
|
/**
|
|
615
625
|
* Replace the last occurrence of a given value if it appears at the end of the string.
|
|
@@ -619,7 +629,7 @@ class s {
|
|
|
619
629
|
* @returns The updated Stringable instance.
|
|
620
630
|
*/
|
|
621
631
|
replaceEnd(e, t) {
|
|
622
|
-
return new s(
|
|
632
|
+
return new s(me(e, t, this._value));
|
|
623
633
|
}
|
|
624
634
|
/**
|
|
625
635
|
* Replace the patterns matching the given regular expression.
|
|
@@ -630,7 +640,7 @@ class s {
|
|
|
630
640
|
* @returns The updated Stringable instance.
|
|
631
641
|
*/
|
|
632
642
|
replaceMatches(e, t, r = -1) {
|
|
633
|
-
const n =
|
|
643
|
+
const n = _e(e, t, this._value, r);
|
|
634
644
|
return new s(n);
|
|
635
645
|
}
|
|
636
646
|
/**
|
|
@@ -653,8 +663,8 @@ class s {
|
|
|
653
663
|
let u = r + 2;
|
|
654
664
|
for (; u < e.length && e[u] !== "]"; )
|
|
655
665
|
u++;
|
|
656
|
-
const
|
|
657
|
-
t += "([" +
|
|
666
|
+
const w = e.substring(r + 2, u);
|
|
667
|
+
t += "([" + w + "]+)", r = u + 1;
|
|
658
668
|
} else e[r + 1] === "d" ? (t += "\\s*(-?\\d+)", r += 2) : e[r + 1] === "s" ? (t += "\\s*(\\S+)", r += 2) : (t += e[r], r++);
|
|
659
669
|
else {
|
|
660
670
|
const u = e[r];
|
|
@@ -669,7 +679,7 @@ class s {
|
|
|
669
679
|
* @returns The updated Stringable instance.
|
|
670
680
|
*/
|
|
671
681
|
squish() {
|
|
672
|
-
return new s(
|
|
682
|
+
return new s(Ee(this._value));
|
|
673
683
|
}
|
|
674
684
|
/**
|
|
675
685
|
* Begin a string with a single instance of a given value.
|
|
@@ -678,7 +688,7 @@ class s {
|
|
|
678
688
|
* @returns The updated Stringable instance.
|
|
679
689
|
*/
|
|
680
690
|
start(e) {
|
|
681
|
-
return new s(
|
|
691
|
+
return new s(ye(this._value, e));
|
|
682
692
|
}
|
|
683
693
|
/**
|
|
684
694
|
* Strip HTML and PHP tags from the given string.
|
|
@@ -686,7 +696,7 @@ class s {
|
|
|
686
696
|
* @returns The updated Stringable instance.
|
|
687
697
|
*/
|
|
688
698
|
stripTags() {
|
|
689
|
-
return new s(
|
|
699
|
+
return new s(Ae(this._value));
|
|
690
700
|
}
|
|
691
701
|
/**
|
|
692
702
|
* Convert the given string to upper-case.
|
|
@@ -694,7 +704,7 @@ class s {
|
|
|
694
704
|
* @returns The upper-cased string as a new Stringable instance.
|
|
695
705
|
*/
|
|
696
706
|
upper() {
|
|
697
|
-
return new s(
|
|
707
|
+
return new s(_(this._value));
|
|
698
708
|
}
|
|
699
709
|
/**
|
|
700
710
|
* Convert the given string to proper case.
|
|
@@ -702,7 +712,7 @@ class s {
|
|
|
702
712
|
* @returns The title-cased string as a new Stringable instance.
|
|
703
713
|
*/
|
|
704
714
|
title() {
|
|
705
|
-
return new s(
|
|
715
|
+
return new s(E(this._value));
|
|
706
716
|
}
|
|
707
717
|
/**
|
|
708
718
|
* Convert the given string to proper case for each word.
|
|
@@ -710,7 +720,7 @@ class s {
|
|
|
710
720
|
* @returns The headline-cased string as a new Stringable instance.
|
|
711
721
|
*/
|
|
712
722
|
headline() {
|
|
713
|
-
return new s(
|
|
723
|
+
return new s(We(this._value));
|
|
714
724
|
}
|
|
715
725
|
/**
|
|
716
726
|
* Convert the given string to APA-style title case.
|
|
@@ -718,7 +728,7 @@ class s {
|
|
|
718
728
|
* @returns The APA title-cased string as a new Stringable instance.
|
|
719
729
|
*/
|
|
720
730
|
apa() {
|
|
721
|
-
return new s(
|
|
731
|
+
return new s(xe(this._value));
|
|
722
732
|
}
|
|
723
733
|
/**
|
|
724
734
|
* Transliterate a string to its closest ASCII representation.
|
|
@@ -726,7 +736,7 @@ class s {
|
|
|
726
736
|
* @returns The transliterated string as a new Stringable instance.
|
|
727
737
|
*/
|
|
728
738
|
transliterate() {
|
|
729
|
-
return new s(
|
|
739
|
+
return new s(Ve(this._value));
|
|
730
740
|
}
|
|
731
741
|
/**
|
|
732
742
|
* Get the singular form of an English word.
|
|
@@ -734,7 +744,7 @@ class s {
|
|
|
734
744
|
* @returns The singularized string as a new Stringable instance.
|
|
735
745
|
*/
|
|
736
746
|
singular() {
|
|
737
|
-
return new s(
|
|
747
|
+
return new s(N(this._value));
|
|
738
748
|
}
|
|
739
749
|
/**
|
|
740
750
|
* Generate a URL friendly "slug" from a given string.
|
|
@@ -744,7 +754,7 @@ class s {
|
|
|
744
754
|
* @returns The slugified string as a new Stringable instance.
|
|
745
755
|
*/
|
|
746
756
|
slug(e = "-", t = { "@": "at" }) {
|
|
747
|
-
return new s(
|
|
757
|
+
return new s(p(this._value, e, t));
|
|
748
758
|
}
|
|
749
759
|
/**
|
|
750
760
|
* Convert a string to snake case.
|
|
@@ -753,7 +763,7 @@ class s {
|
|
|
753
763
|
* @returns The snake-cased string as a new Stringable instance.
|
|
754
764
|
*/
|
|
755
765
|
snake(e = "_") {
|
|
756
|
-
return new s(
|
|
766
|
+
return new s(ke(this._value, e));
|
|
757
767
|
}
|
|
758
768
|
/**
|
|
759
769
|
* Determine if a given string starts with a given substring.
|
|
@@ -762,7 +772,7 @@ class s {
|
|
|
762
772
|
* @returns boolean - True if the substring(s) are found, false otherwise
|
|
763
773
|
*/
|
|
764
774
|
startsWith(e) {
|
|
765
|
-
return
|
|
775
|
+
return Ne(this._value, e);
|
|
766
776
|
}
|
|
767
777
|
/**
|
|
768
778
|
* Determine if a given string doesn't start with a given substring.
|
|
@@ -771,7 +781,7 @@ class s {
|
|
|
771
781
|
* @returns boolean - True if the substring(s) are not found, false otherwise
|
|
772
782
|
*/
|
|
773
783
|
doesntStartWith(e) {
|
|
774
|
-
return
|
|
784
|
+
return Ue(this._value, e);
|
|
775
785
|
}
|
|
776
786
|
/**
|
|
777
787
|
* Convert a value to studly caps case.
|
|
@@ -779,7 +789,7 @@ class s {
|
|
|
779
789
|
* @returns The studly-cased string as a new Stringable instance.
|
|
780
790
|
*/
|
|
781
791
|
studly() {
|
|
782
|
-
return new s(
|
|
792
|
+
return new s(Ce(this._value));
|
|
783
793
|
}
|
|
784
794
|
/**
|
|
785
795
|
* Convert the string to Pascal case.
|
|
@@ -787,7 +797,7 @@ class s {
|
|
|
787
797
|
* @returns The pascal-cased string as a new Stringable instance.
|
|
788
798
|
*/
|
|
789
799
|
pascal() {
|
|
790
|
-
return new s(
|
|
800
|
+
return new s(Le(this._value));
|
|
791
801
|
}
|
|
792
802
|
/**
|
|
793
803
|
* Returns the portion of the string specified by the start and length parameters.
|
|
@@ -797,7 +807,7 @@ class s {
|
|
|
797
807
|
* @returns The extracted substring as a new Stringable instance.
|
|
798
808
|
*/
|
|
799
809
|
substr(e, t = null) {
|
|
800
|
-
return new s(
|
|
810
|
+
return new s(U(this._value, e, t));
|
|
801
811
|
}
|
|
802
812
|
/**
|
|
803
813
|
* Returns the number of substring occurrences.
|
|
@@ -808,7 +818,7 @@ class s {
|
|
|
808
818
|
* @returns The number of occurrences of the substring.
|
|
809
819
|
*/
|
|
810
820
|
substrCount(e, t = 0, r = null) {
|
|
811
|
-
return
|
|
821
|
+
return C(this._value, e, t, r);
|
|
812
822
|
}
|
|
813
823
|
/**
|
|
814
824
|
* Replace text within a portion of a string.
|
|
@@ -820,7 +830,7 @@ class s {
|
|
|
820
830
|
*/
|
|
821
831
|
substrReplace(e, t = 0, r = null) {
|
|
822
832
|
return new s(
|
|
823
|
-
|
|
833
|
+
L(this._value, e, t, r)
|
|
824
834
|
);
|
|
825
835
|
}
|
|
826
836
|
/**
|
|
@@ -848,7 +858,7 @@ class s {
|
|
|
848
858
|
* @returns The trimmed string as a new Stringable instance.
|
|
849
859
|
*/
|
|
850
860
|
trim(e = null) {
|
|
851
|
-
return new s(
|
|
861
|
+
return new s(o(this._value, e));
|
|
852
862
|
}
|
|
853
863
|
/**
|
|
854
864
|
* Left trim the string of the given characters.
|
|
@@ -857,7 +867,7 @@ class s {
|
|
|
857
867
|
* @returns The left-trimmed string as a new Stringable instance.
|
|
858
868
|
*/
|
|
859
869
|
ltrim(e = null) {
|
|
860
|
-
return new s(
|
|
870
|
+
return new s($e(this._value, e));
|
|
861
871
|
}
|
|
862
872
|
/**
|
|
863
873
|
* Right trim the string of the given characters.
|
|
@@ -866,7 +876,7 @@ class s {
|
|
|
866
876
|
* @returns The right-trimmed string as a new Stringable instance.
|
|
867
877
|
*/
|
|
868
878
|
rtrim(e = null) {
|
|
869
|
-
return new s(
|
|
879
|
+
return new s(ze(this._value, e));
|
|
870
880
|
}
|
|
871
881
|
/**
|
|
872
882
|
* Make a string's first character lowercase.
|
|
@@ -874,7 +884,7 @@ class s {
|
|
|
874
884
|
* @returns The updated Stringable instance.
|
|
875
885
|
*/
|
|
876
886
|
lcfirst() {
|
|
877
|
-
return new s(
|
|
887
|
+
return new s(Ie(this._value));
|
|
878
888
|
}
|
|
879
889
|
/**
|
|
880
890
|
* Make a string's first character uppercase.
|
|
@@ -882,7 +892,7 @@ class s {
|
|
|
882
892
|
* @returns The updated Stringable instance.
|
|
883
893
|
*/
|
|
884
894
|
ucfirst() {
|
|
885
|
-
return new s(
|
|
895
|
+
return new s(Be(this._value));
|
|
886
896
|
}
|
|
887
897
|
/**
|
|
888
898
|
* Split a string by uppercase characters.
|
|
@@ -890,7 +900,7 @@ class s {
|
|
|
890
900
|
* @returns An array of substrings split at uppercase characters.
|
|
891
901
|
*/
|
|
892
902
|
ucsplit() {
|
|
893
|
-
return
|
|
903
|
+
return Re(this._value);
|
|
894
904
|
}
|
|
895
905
|
/**
|
|
896
906
|
* Uppercase the first character of each word in a string.
|
|
@@ -898,7 +908,7 @@ class s {
|
|
|
898
908
|
* @returns The updated Stringable instance.
|
|
899
909
|
*/
|
|
900
910
|
ucwords() {
|
|
901
|
-
return new s(
|
|
911
|
+
return new s(je(this._value));
|
|
902
912
|
}
|
|
903
913
|
/**
|
|
904
914
|
* Apply the callback if the given "value" is (or resolves to) truthy.
|
|
@@ -923,7 +933,7 @@ class s {
|
|
|
923
933
|
* ```
|
|
924
934
|
*/
|
|
925
935
|
when(e, t = null, r = null) {
|
|
926
|
-
const n =
|
|
936
|
+
const n = l(e) ? e(this) : e;
|
|
927
937
|
return n ? t?.(this, n) ?? this : r ? r(this, n) ?? this : this;
|
|
928
938
|
}
|
|
929
939
|
/**
|
|
@@ -941,7 +951,7 @@ class s {
|
|
|
941
951
|
* str.unless(false, s => s.upper(), s => s.lower()); // Returns 'HELLO WORLD'
|
|
942
952
|
*/
|
|
943
953
|
unless(e, t = null, r = null) {
|
|
944
|
-
const n =
|
|
954
|
+
const n = l(e) ? e(this) : e;
|
|
945
955
|
if (n) {
|
|
946
956
|
if (r)
|
|
947
957
|
return r(this, n) ?? this;
|
|
@@ -1109,7 +1119,7 @@ class s {
|
|
|
1109
1119
|
* @returns The truncated string as a new Stringable instance.
|
|
1110
1120
|
*/
|
|
1111
1121
|
words(e = 100, t = "...") {
|
|
1112
|
-
return new s(
|
|
1122
|
+
return new s(De(this._value, e, t));
|
|
1113
1123
|
}
|
|
1114
1124
|
/**
|
|
1115
1125
|
* Get the number of words a string contains.
|
|
@@ -1118,7 +1128,7 @@ class s {
|
|
|
1118
1128
|
* @returns The number of words in the string.
|
|
1119
1129
|
*/
|
|
1120
1130
|
wordCount(e = null) {
|
|
1121
|
-
return
|
|
1131
|
+
return Te(this._value, e);
|
|
1122
1132
|
}
|
|
1123
1133
|
/**
|
|
1124
1134
|
* Wrap a string to a given number of characters.
|
|
@@ -1131,7 +1141,7 @@ class s {
|
|
|
1131
1141
|
wordWrap(e = 75, t = `
|
|
1132
1142
|
`, r = !1) {
|
|
1133
1143
|
return new s(
|
|
1134
|
-
|
|
1144
|
+
Pe(this._value, e, t, r)
|
|
1135
1145
|
);
|
|
1136
1146
|
}
|
|
1137
1147
|
/**
|
|
@@ -1142,7 +1152,7 @@ class s {
|
|
|
1142
1152
|
* @returns The wrapped string as a new Stringable instance.
|
|
1143
1153
|
*/
|
|
1144
1154
|
wrap(e, t = null) {
|
|
1145
|
-
return new s(
|
|
1155
|
+
return new s(qe(this._value, e, t));
|
|
1146
1156
|
}
|
|
1147
1157
|
/**
|
|
1148
1158
|
* Unwrap the string with the given strings.
|
|
@@ -1152,7 +1162,7 @@ class s {
|
|
|
1152
1162
|
* @returns The unwrapped string as a new Stringable instance.
|
|
1153
1163
|
*/
|
|
1154
1164
|
unwrap(e, t = null) {
|
|
1155
|
-
return new s(
|
|
1165
|
+
return new s(Je(this._value, e, t));
|
|
1156
1166
|
}
|
|
1157
1167
|
/**
|
|
1158
1168
|
* Convert the string to Base64 encoding.
|
|
@@ -1160,7 +1170,7 @@ class s {
|
|
|
1160
1170
|
* @returns The Base64 encoded string as a new Stringable instance.
|
|
1161
1171
|
*/
|
|
1162
1172
|
toBase64() {
|
|
1163
|
-
return new s(
|
|
1173
|
+
return new s(d(this._value));
|
|
1164
1174
|
}
|
|
1165
1175
|
/**
|
|
1166
1176
|
* Decode the Base64 encoded string.
|
|
@@ -1169,7 +1179,7 @@ class s {
|
|
|
1169
1179
|
* @returns The decoded string as a new Stringable instance, or false on failure.
|
|
1170
1180
|
*/
|
|
1171
1181
|
fromBase64(e = !1) {
|
|
1172
|
-
const t =
|
|
1182
|
+
const t = f(this._value, e);
|
|
1173
1183
|
return t === !1 ? !1 : new s(t);
|
|
1174
1184
|
}
|
|
1175
1185
|
/**
|
|
@@ -1212,7 +1222,7 @@ class s {
|
|
|
1212
1222
|
* @returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.
|
|
1213
1223
|
*/
|
|
1214
1224
|
toBoolean() {
|
|
1215
|
-
const e =
|
|
1225
|
+
const e = a(o(this._value));
|
|
1216
1226
|
return e === "1" || e === "true" || e === "on" || e === "yes";
|
|
1217
1227
|
}
|
|
1218
1228
|
/**
|
|
@@ -1235,6 +1245,6 @@ class s {
|
|
|
1235
1245
|
}
|
|
1236
1246
|
export {
|
|
1237
1247
|
s as Stringable,
|
|
1238
|
-
|
|
1239
|
-
|
|
1248
|
+
rt as of,
|
|
1249
|
+
nt as str
|
|
1240
1250
|
};
|