@zinaid/str 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/ascii/index.d.ts +14 -0
  2. package/dist/ascii/index.d.ts.map +1 -0
  3. package/dist/ascii/index.js +7 -0
  4. package/dist/base64/index.d.ts +23 -0
  5. package/dist/base64/index.d.ts.map +1 -0
  6. package/dist/base64/index.js +124 -0
  7. package/dist/{convertcase.d.ts → convertcase/index.d.ts} +11 -1
  8. package/dist/convertcase/index.d.ts.map +1 -0
  9. package/dist/index.d.ts +4 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +136 -131
  12. package/dist/markdown/index.d.ts +49 -0
  13. package/dist/markdown/index.d.ts.map +1 -0
  14. package/dist/markdown/index.js +32 -0
  15. package/dist/pluralizer/index.d.ts +100 -0
  16. package/dist/pluralizer/index.d.ts.map +1 -0
  17. package/dist/{pluralizer.js → pluralizer/index.js} +39 -32
  18. package/dist/{random.d.ts → random/index.d.ts} +3 -3
  19. package/dist/random/index.d.ts.map +1 -0
  20. package/dist/{random.js → random/index.js} +2 -1
  21. package/dist/replacer/index.d.ts +31 -0
  22. package/dist/replacer/index.d.ts.map +1 -0
  23. package/dist/str.d.ts +308 -173
  24. package/dist/str.d.ts.map +1 -1
  25. package/dist/str.js +510 -661
  26. package/dist/stringable/index.d.ts +952 -0
  27. package/dist/stringable/index.d.ts.map +1 -0
  28. package/dist/{stringable.js → stringable/index.js} +400 -13
  29. package/dist/transliterate/index.d.ts +14 -0
  30. package/dist/transliterate/index.d.ts.map +1 -0
  31. package/dist/transliterate/index.js +7 -0
  32. package/dist/trimmer/index.d.ts +25 -0
  33. package/dist/trimmer/index.d.ts.map +1 -0
  34. package/dist/ulid/index.d.ts +79 -0
  35. package/dist/ulid/index.d.ts.map +1 -0
  36. package/dist/ulid/index.js +58 -0
  37. package/dist/uuid/index.d.ts +92 -0
  38. package/dist/uuid/index.d.ts.map +1 -0
  39. package/dist/uuid/index.js +50 -0
  40. package/package.json +78 -21
  41. package/dist/base64.d.ts +0 -7
  42. package/dist/base64.d.ts.map +0 -1
  43. package/dist/base64.js +0 -123
  44. package/dist/convertcase.d.ts.map +0 -1
  45. package/dist/markdown.d.ts +0 -26
  46. package/dist/markdown.d.ts.map +0 -1
  47. package/dist/markdown.js +0 -55
  48. package/dist/pluralizer.d.ts +0 -38
  49. package/dist/pluralizer.d.ts.map +0 -1
  50. package/dist/random.d.ts.map +0 -1
  51. package/dist/replacer.d.ts +0 -31
  52. package/dist/replacer.d.ts.map +0 -1
  53. package/dist/stringable.d.ts +0 -555
  54. package/dist/stringable.d.ts.map +0 -1
  55. package/dist/trimmer.d.ts +0 -4
  56. package/dist/trimmer.d.ts.map +0 -1
  57. /package/dist/{convertcase.js → convertcase/index.js} +0 -0
  58. /package/dist/{replacer.js → replacer/index.js} +0 -0
  59. /package/dist/{trimmer.js → trimmer/index.js} +0 -0
package/dist/markdown.js DELETED
@@ -1,55 +0,0 @@
1
- import { isArray as w, optionalRequire as s } from "@zinaid/utils";
2
- function p() {
3
- return s(
4
- "markdown-it",
5
- 'The "markdown-it" package is required for markdown functions. Please install it: npm install markdown-it'
6
- );
7
- }
8
- function h() {
9
- return s(
10
- "markdown-it-anchor",
11
- 'The "markdown-it-anchor" package is required for anchor support. Please install it: npm install markdown-it-anchor'
12
- );
13
- }
14
- function g() {
15
- const n = s(
16
- "markdown-it-task-lists",
17
- 'The "markdown-it-task-lists" package is required for GFM task list support. Please install it: npm install markdown-it-task-lists'
18
- );
19
- return "default" in n ? n.default : n;
20
- }
21
- function M(n, r = { gfm: !0, anchors: !1 }, e = []) {
22
- return i(r, e).render(n);
23
- }
24
- function T(n, r = { gfm: !0 }, e = []) {
25
- return i(r, e).renderInline(n);
26
- }
27
- function i(n = { gfm: !0, anchors: !1 }, r = []) {
28
- const {
29
- html: e = !1,
30
- linkify: l = !0,
31
- breaks: u = !0,
32
- gfm: d = !0,
33
- anchors: a = !1,
34
- ...f
35
- } = n, k = p(), o = new k({ html: e, linkify: l, breaks: u, ...f });
36
- if (d) {
37
- const t = g();
38
- o.use(t, { label: !0, labelAfter: !0 });
39
- }
40
- if (a) {
41
- const t = h();
42
- o.use(t, typeof a == "object" ? a : {});
43
- }
44
- for (const t of r)
45
- if (w(t)) {
46
- const [c, m] = t;
47
- o.use(c, m);
48
- } else t && o.use(t);
49
- return o;
50
- }
51
- export {
52
- T as inlineMarkdown,
53
- i as markDownRenderer,
54
- M as markdown
55
- };
@@ -1,38 +0,0 @@
1
- export interface PluralizerRules {
2
- uncountable: string[];
3
- }
4
- /**
5
- * Get the plural form of an English word.
6
- *
7
- * @example
8
- *
9
- * plural("child"); -> "children"
10
- * plural("apple", 1); -> "apple"
11
- * plural("apple", 2, true); -> "2 apples"
12
- */
13
- export declare function plural(value: string, count?: number, prependCount?: boolean): string;
14
- /**
15
- * Get the singular form of an English word.
16
- */
17
- export declare function singular(value: string): string;
18
- /**
19
- * Determine if the given value is uncountable.
20
- */
21
- export declare function uncountable(value: string): boolean;
22
- /**
23
- * Determine if the given value is plural.
24
- */
25
- export declare function isPlural(value?: string): boolean;
26
- /**
27
- * Determine if the given value is singular.
28
- */
29
- export declare function isSingular(value?: string): boolean;
30
- /**
31
- * Attempt to match the case on two strings
32
- */
33
- export declare function matchCase(value: string, comparison: string): string;
34
- /**
35
- * Get the pluralize instance
36
- */
37
- export declare function inflector(): typeof import("pluralize");
38
- //# sourceMappingURL=pluralizer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pluralizer.d.ts","sourceRoot":"","sources":["../src/pluralizer.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAC;CACzB;AAoDD;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAClB,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAU,EACjB,YAAY,GAAE,OAAe,GAC9B,MAAM,CAKR;AAeD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAiBnE;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,cAAc,WAAW,CAAC,CActD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAK,GAAG,MAAM,CAehD;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA4C1D"}
@@ -1,31 +0,0 @@
1
- /**
2
- * Returns the portion of the string specified by the start and length parameters.
3
- *
4
- * @param string
5
- * @param start
6
- * @param length
7
- * @returns
8
- */
9
- export declare function substr(string: string, start: number, length?: number | null): string;
10
- /**
11
- * Returns the number of substring occurrences.
12
- *
13
- * @param haystack
14
- * @param needle
15
- * @param offset
16
- * @param length
17
- * @returns
18
- */
19
- export declare function substrCount(haystack: string, needle: string, offset?: number, length?: number | null): number;
20
- /**
21
- * Replace text within a portion of a string.
22
- * Properly handles multibyte characters.
23
- *
24
- * @param value
25
- * @param replace
26
- * @param offset
27
- * @param length
28
- * @returns
29
- */
30
- export declare function substrReplace(value: string, replace: string | string[], offset?: number | number[], length?: number | number[] | null): string | string[];
31
- //# sourceMappingURL=replacer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../src/replacer.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAWR;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CACvB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAgBR;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CACzB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,GAAE,MAAM,GAAG,MAAM,EAAM,EAC7B,MAAM,GAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAW,GACxC,MAAM,GAAG,MAAM,EAAE,CAyBnB"}
@@ -1,555 +0,0 @@
1
- import { ConvertCaseMode, MarkDownExtensions, MarkDownOptions } from './index.ts';
2
- export type ConditionableValue = string | number | boolean | ((instance: Stringable) => string | number | boolean);
3
- export type ConditionableClosure = ((instance: Stringable, value: ConditionableValue) => unknown) | null;
4
- /**
5
- * Get a new stringable object from the given string.
6
- *
7
- * @example
8
- *
9
- * of('foo').append('bar'); -> 'foobar'
10
- */
11
- export declare function of(value: string): Stringable;
12
- export declare class Stringable {
13
- private readonly _value;
14
- /**
15
- * Create a new instance of the class.
16
- */
17
- constructor(_value?: string);
18
- /**
19
- * Return the remainder of a string after the first occurrence of a given value.
20
- */
21
- after(search: string | number): Stringable;
22
- /**
23
- * Return the remainder of a string after the last occurrence of a given value
24
- */
25
- afterLast(search: string | number): Stringable;
26
- /**
27
- * Append the given values to the string.
28
- */
29
- append(...values: Array<string | number>): Stringable;
30
- /**
31
- * Append a new line to the string.
32
- */
33
- newLine(count?: number): Stringable;
34
- /**
35
- * Transliterate a UTF-8 value to ASCII.
36
- */
37
- ascii(): Stringable;
38
- /**
39
- * Get the portion of a string before the first occurrence of a given value.
40
- */
41
- before(search: string | number): Stringable;
42
- /**
43
- * Get the portion of a string before the last occurrence of a given value.
44
- */
45
- beforeLast(search: string | number): Stringable;
46
- /**
47
- * Get the portion of a string between two given values.
48
- */
49
- between(from: string | number, to: string | number): Stringable;
50
- /**
51
- * Get the smallest possible portion of a string between two given values.
52
- */
53
- betweenFirst(from: string | number, to: string | number): Stringable;
54
- /**
55
- * Convert a value to camel case.
56
- */
57
- camel(): Stringable;
58
- /**
59
- * Get the character at the specified index.
60
- */
61
- charAt(index: number): string | false;
62
- /**
63
- * Remove the given string if it exists at the start of the current string.
64
- */
65
- chopStart(needle: string | string[]): Stringable;
66
- /**
67
- * Remove the given string if it exists at the end of the current string.
68
- */
69
- chopEnd(needle: string | string[]): Stringable;
70
- /**
71
- * Determine if a given string contains a given substring.
72
- */
73
- contains(needles: string | Iterable<string>, ignoreCase?: boolean): boolean;
74
- /**
75
- * Determine if a given string contains all array values.
76
- */
77
- containsAll(needles: Iterable<string>, ignoreCase?: boolean): boolean;
78
- /**
79
- * Determine if a given string doesn't contain a given substring.
80
- *
81
- * @param needles - The substring(s) to search for
82
- * @param ignoreCase - Whether the search should be case-insensitive
83
- * @returns boolean - True if the substring(s) are not found, false otherwise
84
- */
85
- doesntContain(needles: string | Iterable<string>, ignoreCase?: boolean): boolean;
86
- /**
87
- * Convert the case of a string.
88
- */
89
- convertCase(mode: ConvertCaseMode): Stringable;
90
- /**
91
- * Replace consecutive instances of a given character with a single character.
92
- */
93
- deduplicate(character?: string | string[]): Stringable;
94
- /**
95
- * Determine if a given string ends with a given substring.
96
- */
97
- endsWith(needles: string | number | Iterable<string>): boolean;
98
- /**
99
- * Determine if a given string doesn't end with a given substring.
100
- */
101
- doesntEndWith(needles: string | number | Iterable<string>): boolean;
102
- /**
103
- * Determine if the string is an exact match with the given value.
104
- */
105
- exactly(value: Stringable | string): boolean;
106
- /**
107
- * Extracts an excerpt from text that matches the first instance of a phrase.
108
- */
109
- excerpt(phrase?: string | null, options?: {
110
- radius?: number;
111
- omission?: string;
112
- }): string | null;
113
- /**
114
- * Explode the string into an array
115
- */
116
- explode(delimiter: string, limit?: number): string[];
117
- /**
118
- * Split a string using a regular expression or by length.
119
- */
120
- split(pattern: string | number, limit?: number | null): string[];
121
- /**
122
- * Cap a string with a single instance of a given value.
123
- */
124
- finish(cap: string): Stringable;
125
- /**
126
- * Determine if a given string matches a given pattern.
127
- */
128
- is(pattern: string | Iterable<string>, ignoreCase?: boolean): boolean;
129
- /**
130
- * Determine if a given string is 7 bit ASCII.
131
- */
132
- isAscii(): boolean;
133
- /**
134
- * Determine if a given string is valid JSON.
135
- */
136
- isJson(): boolean;
137
- /**
138
- * Determine if a given value is a valid URL.
139
- */
140
- isUrl(protocols?: string[]): boolean;
141
- /**
142
- * Determine if a given string is a valid UUID.
143
- */
144
- isUuid(version?: number | "nil" | "max" | null): boolean;
145
- /**
146
- * Determine if a given string is a valid ULID.
147
- */
148
- isUlid(): boolean;
149
- /**
150
- * Determine if the given string is empty.
151
- */
152
- isEmpty(): boolean;
153
- /**
154
- * Determine if the given string is not empty.
155
- */
156
- isNotEmpty(): boolean;
157
- /**
158
- * Convert a string to kebab case.
159
- */
160
- kebab(): Stringable;
161
- /**
162
- * Return the length of the given string.
163
- */
164
- length(): number;
165
- /**
166
- * Limit the number of characters in a string.
167
- */
168
- limit(limitValue?: number, end?: string, preserveWords?: boolean): Stringable;
169
- /**
170
- * Convert the given string to lower-case.
171
- */
172
- lower(): Stringable;
173
- /**
174
- * Convert GitHub flavored Markdown into HTML.
175
- */
176
- markdown(options?: MarkDownOptions, extensions?: MarkDownExtensions): Stringable;
177
- /**
178
- * Convert inline Markdown into HTML.
179
- */
180
- inlineMarkdown(options?: MarkDownOptions, extensions?: MarkDownExtensions): Stringable;
181
- /**
182
- * Masks a portion of a string with a repeated character.
183
- */
184
- mask(character: string, index: number, length?: number | null): Stringable;
185
- /**
186
- * Get the string matching the given pattern.
187
- */
188
- match(pattern: string): Stringable;
189
- /**
190
- * Determine if a given string matches a given pattern.
191
- */
192
- isMatch(pattern: string | Iterable<string>): boolean;
193
- /**
194
- * Get the string matching the given pattern.
195
- */
196
- matchAll(pattern: string): string[];
197
- /**
198
- * Determine if the string matches the given pattern.
199
- */
200
- test(pattern: string): boolean;
201
- /**
202
- * Remove all non-numeric characters from a string.
203
- */
204
- numbers(): Stringable;
205
- /**
206
- * Pad both sides of the string with another.
207
- */
208
- padBoth(length: number, pad?: string): Stringable;
209
- /**
210
- * Pad the left side of the string with another.
211
- */
212
- padLeft(length: number, pad?: string): Stringable;
213
- /**
214
- * Pad the right side of the string with another.
215
- */
216
- padRight(length: number, pad?: string): Stringable;
217
- /**
218
- * Call the given callback and return a new string.
219
- */
220
- pipe<T = Stringable | string>(callback: (s: Stringable) => T): Stringable;
221
- /**
222
- * Get the plural form of an English word.
223
- */
224
- plural(count?: number, prependCount?: boolean): Stringable;
225
- /**
226
- * Pluralize the last word of an English, studly caps case string.
227
- */
228
- pluralStudly(count?: number): Stringable;
229
- /**
230
- * Pluralize the last word of an English, Pascal caps case string.
231
- */
232
- pluralPascal(count?: number): Stringable;
233
- /**
234
- * Find the multi-byte safe position of the first occurrence of the given substring.
235
- */
236
- position(needle: string, offset?: number): number | false;
237
- /**
238
- * Prepend the given values to the string.
239
- */
240
- prepend(...values: Array<string | number>): Stringable;
241
- /**
242
- * Remove any occurrence of the given string in the subject.
243
- */
244
- remove(search: string | Iterable<string>, caseSensitive?: boolean): Stringable;
245
- /**
246
- * Reverse the string.
247
- */
248
- reverse(): Stringable;
249
- /**
250
- * Repeat the string.
251
- */
252
- repeat(times: number): Stringable;
253
- /**
254
- * Replace the given value in the given string.
255
- */
256
- replace(search: string | Iterable<string>, replacement: string | Iterable<string>, caseSensitive?: boolean): Stringable;
257
- /**
258
- * Replace a given value in the string sequentially with an array.
259
- */
260
- replaceArray(search: string, replace: Record<string, string> | Iterable<string>): Stringable;
261
- /**
262
- * Replace the first occurrence of a given value in the string.
263
- */
264
- replaceFirst(search: string | number, replace: string): Stringable;
265
- /**
266
- * Replace the first occurrence of the given value if it appears at the start of the string.
267
- */
268
- replaceStart(search: string | number, replace: string): Stringable;
269
- /**
270
- * Replace the last occurrence of a given value in the string.
271
- */
272
- replaceLast(search: string | number, replace: string): Stringable;
273
- /**
274
- * Replace the last occurrence of a given value if it appears at the end of the string.
275
- */
276
- replaceEnd(search: string | number, replace: string): Stringable;
277
- /**
278
- * Replace the patterns matching the given regular expression.
279
- */
280
- replaceMatches(pattern: string | string[] | RegExp | RegExp[], replace: string | string[] | ((match: string[]) => string), limit?: number): Stringable;
281
- /**
282
- * Parse input from a string to an array, according to a format.
283
- *
284
- * @param format - A format string like "%d", "%s", "%[^,],%s", etc.
285
- * @returns Array of parsed values according to the format
286
- *
287
- * @example
288
- *
289
- * Str.of("SN/123456").scan("SN/%d") -> ["123456"]
290
- * Str.of("Otwell, Taylor").scan("%[^,],%s") -> ["Otwell", "Taylor"]
291
- * Str.of("filename.jpg").scan("%[^.].%s") -> ["filename", "jpg"]
292
- */
293
- scan(format: string): string[];
294
- /**
295
- * Remove all "extra" blank space from the given string.
296
- */
297
- squish(): Stringable;
298
- /**
299
- * Begin a string with a single instance of a given value.
300
- */
301
- start(prefix: string): Stringable;
302
- /**
303
- * Strip HTML and PHP tags from the given string.
304
- */
305
- stripTags(): Stringable;
306
- /**
307
- * Convert the given string to upper-case.
308
- */
309
- upper(): Stringable;
310
- /**
311
- * Convert the given string to proper case.
312
- */
313
- title(): Stringable;
314
- /**
315
- * Convert the given string to proper case for each word.
316
- */
317
- headline(): Stringable;
318
- /**
319
- * Convert the given string to APA-style title case.
320
- */
321
- apa(): Stringable;
322
- /**
323
- * Transliterate a string to its closest ASCII representation.
324
- */
325
- transliterate(): Stringable;
326
- /**
327
- * Get the singular form of an English word.
328
- */
329
- singular(): Stringable;
330
- /**
331
- * Generate a URL friendly "slug" from a given string.
332
- */
333
- slug(separator?: string, dictionary?: Record<string, string>): Stringable;
334
- /**
335
- * Convert a string to snake case.
336
- */
337
- snake(delimiter?: string): Stringable;
338
- /**
339
- * Determine if a given string starts with a given substring.
340
- */
341
- startsWith(needles: string | number | null | Iterable<string | number | null>): boolean;
342
- /**
343
- * Determine if a given string doesn't start with a given substring.
344
- */
345
- doesntStartWith(needles: string | number | null | Iterable<string | number | null>): boolean;
346
- /**
347
- * Convert a value to studly caps case.
348
- */
349
- studly(): Stringable;
350
- /**
351
- * Convert the string to Pascal case.
352
- */
353
- pascal(): Stringable;
354
- /**
355
- * Returns the portion of the string specified by the start and length parameters.
356
- */
357
- substr(start: number, length?: number | null): Stringable;
358
- /**
359
- * Returns the number of substring occurrences.
360
- */
361
- substrCount(needle: string, offset?: number, length?: number | null): number;
362
- /**
363
- * Replace text within a portion of a string.
364
- */
365
- substrReplace(replace: string, offset?: number | number[], length?: number | number[] | null): Stringable;
366
- /**
367
- * Swap multiple keywords in a string with other keywords.
368
- */
369
- swap(map: Record<string, string>): Stringable;
370
- /**
371
- * Take the first or last {$limit} characters.
372
- */
373
- take(limit: number): Stringable;
374
- /**
375
- * Trim the string of the given characters.
376
- */
377
- trim(charlist?: string | null): Stringable;
378
- /**
379
- * Left trim the string of the given characters.
380
- */
381
- ltrim(charlist?: string | null): Stringable;
382
- /**
383
- * Right trim the string of the given characters.
384
- */
385
- rtrim(charlist?: string | null): Stringable;
386
- /**
387
- * Make a string's first character lowercase.
388
- */
389
- lcfirst(): Stringable;
390
- /**
391
- * Make a string's first character uppercase.
392
- */
393
- ucfirst(): Stringable;
394
- /**
395
- * Split a string by uppercase characters.
396
- */
397
- ucsplit(): string[];
398
- /**
399
- * Uppercase the first character of each word in a string.
400
- */
401
- ucwords(): Stringable;
402
- /**
403
- * Apply the callback if the given "value" is (or resolves to) truthy.
404
- *
405
- * @param value - The value to evaluate or a closure that returns the value
406
- * @param callback - The callback to execute if the value is truthy
407
- * @param defaultCallback - The callback to execute if the value is falsy
408
- * @returns Stringable - The current instance or the result of the callback
409
- *
410
- * @example
411
- *
412
- * ```typescript
413
- * const str = new Stringable('hello world');
414
- *
415
- * Using a direct value
416
- * str.when(true, s => s.upper()); // Returns 'HELLO WORLD'
417
- * str.when(false, s => s.upper(), s => s.lower()); // Returns 'hello world'
418
- *
419
- * Using a closure to determine the value
420
- * str.when(s => s.contains('world'), s => s.upper()); // Returns 'HELLO WORLD'
421
- * str.when(s => s.contains('foo'), s => s.upper(), s => s.lower()); // Returns 'hello world'
422
- * ```
423
- */
424
- when<TWhenParameter, TWhenReturnType>(value: ((instance: this) => TWhenParameter) | TWhenParameter | null, callback?: ((instance: this, value: TWhenParameter) => TWhenReturnType) | null, defaultCallback?: ((instance: this, value: TWhenParameter) => TWhenReturnType) | null): Stringable;
425
- /**
426
- * Apply the callback if the given "value" is (or resolves to) falsy.
427
- *
428
- * @param value - The value to evaluate or a closure that returns the value
429
- * @param callback - The callback to execute if the value is falsy
430
- * @param defaultCallback - The callback to execute if the value is truthy
431
- * @returns Stringable - The current instance or the result of the callback
432
- *
433
- * @example
434
- *
435
- * const str = new Stringable('hello world');
436
- * str.unless(true, s => s.upper()); // Returns 'hello world'
437
- * str.unless(false, s => s.upper(), s => s.lower()); // Returns 'HELLO WORLD'
438
- */
439
- unless<TUnlessParameter, TUnlessReturnType>(value: ((instance: this) => TUnlessParameter) | TUnlessParameter | null, callback?: ((instance: this, value: TUnlessParameter) => TUnlessReturnType) | null, defaultCallback?: ((instance: this, value: TUnlessParameter) => TUnlessReturnType) | null): Stringable;
440
- /**
441
- * Execute the given callback if the string contains a given substring.
442
- */
443
- whenContains(needles: string | Iterable<string>, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
444
- /**
445
- * Execute the given callback if the string contains all array values.
446
- */
447
- whenContainsAll(needles: string | Iterable<string>, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
448
- /**
449
- * Execute the given callback if the string is empty.
450
- */
451
- whenEmpty(callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
452
- /**
453
- * Execute the given callback if the string is not empty.
454
- */
455
- whenNotEmpty(callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
456
- /**
457
- * Execute the given callback if the string ends with a given substring.
458
- */
459
- whenEndsWith(needles: string | Iterable<string>, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
460
- /**
461
- * Execute the given callback if the string doesn't end with a given substring.
462
- */
463
- whenDoesntEndWith(needles: string | Iterable<string>, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
464
- /**
465
- * Execute the given callback if the string is an exact match with the given value.
466
- */
467
- whenExactly(value: string, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
468
- /**
469
- * Execute the given callback if the string is not an exact match with the given value.
470
- */
471
- whenNotExactly(value: string, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
472
- /**
473
- * Execute the given callback if the string matches a given pattern.
474
- */
475
- whenIs(pattern: string | Iterable<string>, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
476
- /**
477
- * Execute the given callback if the string is 7 bit ASCII.
478
- */
479
- whenIsAscii(callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
480
- /**
481
- * Execute the given callback if the string is a valid UUID.
482
- */
483
- whenIsUuid(callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
484
- /**
485
- * Execute the given callback if the string is a valid ULID.
486
- */
487
- whenIsUlid(callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
488
- /**
489
- * Execute the given callback if the string starts with a given substring.
490
- */
491
- whenStartsWith(needles: string | Iterable<string>, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
492
- /**
493
- * Execute the given callback if the string matches the given pattern.
494
- */
495
- whenTest(pattern: string, callback: ConditionableClosure, defaultCallback?: ConditionableClosure): Stringable;
496
- /**
497
- * Limit the number of words in a string.
498
- */
499
- words(wordsValue?: number, end?: string): Stringable;
500
- /**
501
- * Get the number of words a string contains.
502
- */
503
- wordCount(characters?: string | null): number;
504
- /**
505
- * Wrap a string to a given number of characters.
506
- */
507
- wordWrap(characters?: number, breakStr?: string, cutLongWords?: boolean): Stringable;
508
- /**
509
- * Wrap the string with the given strings.
510
- */
511
- wrap(before: string, after?: string | null): Stringable;
512
- /**
513
- * Unwrap the string with the given strings.
514
- */
515
- unwrap(before: string, after?: string | null): Stringable;
516
- /**
517
- * Convert the string to Base64 encoding.
518
- */
519
- toBase64(): Stringable;
520
- /**
521
- * Decode the Base64 encoded string.
522
- */
523
- fromBase64(strict?: boolean): Stringable | false;
524
- /**
525
- * Get the underlying string value.
526
- */
527
- toString(): string;
528
- /**
529
- * Get the underlying string value.
530
- */
531
- value(): string;
532
- /**
533
- * Get the underlying string value as an integer.
534
- */
535
- toInteger(base?: number): number;
536
- /**
537
- * Get the underlying string value as a float.
538
- */
539
- toFloat(): number;
540
- /**
541
- * Get the underlying string value as a boolean.
542
- *
543
- * Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false.
544
- */
545
- toBoolean(): boolean;
546
- /**
547
- * Get the underlying string value as a Carbon instance.
548
- */
549
- toDate(): Date | null;
550
- /**
551
- * Convert the object to a string when JSON encoded.
552
- */
553
- jsonSerialize(): string;
554
- }
555
- //# sourceMappingURL=stringable.d.ts.map