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