@zairakai/js-utils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/arrays.cjs +210 -0
- package/dist/arrays.d.cts +119 -0
- package/dist/arrays.d.ts +119 -0
- package/dist/arrays.js +32 -0
- package/dist/chunk-27YHP2CK.js +407 -0
- package/dist/chunk-3WNRYKPG.js +37 -0
- package/dist/chunk-42CHLXT7.js +214 -0
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7SXRFZBB.js +173 -0
- package/dist/chunk-F6RSTW65.js +156 -0
- package/dist/chunk-G7ZJ23DW.js +253 -0
- package/dist/chunk-IPP7PA6H.js +136 -0
- package/dist/chunk-LDSWHSRX.js +96 -0
- package/dist/chunk-TY75OOIQ.js +700 -0
- package/dist/chunk-W6JEMFAF.js +54 -0
- package/dist/chunk-XEJLBAXE.js +164 -0
- package/dist/chunk-Z7G3SIQH.js +270 -0
- package/dist/chunk-ZJPKS2MQ.js +101 -0
- package/dist/collections.cjs +797 -0
- package/dist/collections.d.cts +353 -0
- package/dist/collections.d.ts +353 -0
- package/dist/collections.js +17 -0
- package/dist/datetime.cjs +80 -0
- package/dist/datetime.d.cts +75 -0
- package/dist/datetime.d.ts +75 -0
- package/dist/datetime.js +24 -0
- package/dist/equals.cjs +121 -0
- package/dist/equals.d.cts +24 -0
- package/dist/equals.d.ts +24 -0
- package/dist/equals.js +8 -0
- package/dist/formatters.cjs +201 -0
- package/dist/formatters.d.cts +180 -0
- package/dist/formatters.d.ts +180 -0
- package/dist/formatters.js +48 -0
- package/dist/index.cjs +2906 -0
- package/dist/index.d.cts +120 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +348 -0
- package/dist/number.cjs +279 -0
- package/dist/number.d.cts +177 -0
- package/dist/number.d.ts +177 -0
- package/dist/number.js +10 -0
- package/dist/obj.cjs +427 -0
- package/dist/obj.d.cts +177 -0
- package/dist/obj.d.ts +177 -0
- package/dist/obj.js +12 -0
- package/dist/php-arrays.cjs +954 -0
- package/dist/php-arrays.d.cts +256 -0
- package/dist/php-arrays.d.ts +256 -0
- package/dist/php-arrays.js +70 -0
- package/dist/runtime.cjs +134 -0
- package/dist/runtime.d.cts +90 -0
- package/dist/runtime.d.ts +90 -0
- package/dist/runtime.js +24 -0
- package/dist/schemas.cjs +86 -0
- package/dist/schemas.d.cts +108 -0
- package/dist/schemas.d.ts +108 -0
- package/dist/schemas.js +22 -0
- package/dist/str.cjs +499 -0
- package/dist/str.d.cts +282 -0
- package/dist/str.d.ts +282 -0
- package/dist/str.js +11 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +1 -0
- package/dist/validator.cjs +251 -0
- package/dist/validator.d.cts +99 -0
- package/dist/validator.d.ts +99 -0
- package/dist/validator.js +11 -0
- package/dist/validators.cjs +217 -0
- package/dist/validators.d.cts +216 -0
- package/dist/validators.d.ts +216 -0
- package/dist/validators.js +64 -0
- package/package.json +180 -0
- package/src/arrays.ts +316 -0
- package/src/collections.ts +866 -0
- package/src/datetime.ts +103 -0
- package/src/equals.ts +134 -0
- package/src/formatters.ts +342 -0
- package/src/index.ts +36 -0
- package/src/number.ts +281 -0
- package/src/obj.ts +303 -0
- package/src/php-arrays.ts +445 -0
- package/src/pipe.ts +29 -0
- package/src/runtime.ts +194 -0
- package/src/schemas.ts +136 -0
- package/src/str.ts +438 -0
- package/src/types.ts +13 -0
- package/src/validator.ts +157 -0
- package/src/validators.ts +359 -0
package/dist/str.d.cts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent string manipulation class inspired by Laravel's Str and Stringable
|
|
3
|
+
*/
|
|
4
|
+
declare class Stringable {
|
|
5
|
+
protected value: string;
|
|
6
|
+
constructor(value: unknown);
|
|
7
|
+
/**
|
|
8
|
+
* Get the raw string value
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The raw string
|
|
11
|
+
*/
|
|
12
|
+
toString(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Alias for toString()
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} The raw string
|
|
17
|
+
*/
|
|
18
|
+
get(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Convert to title case
|
|
21
|
+
*
|
|
22
|
+
* @returns {this} The Stringable instance
|
|
23
|
+
*/
|
|
24
|
+
title(): this;
|
|
25
|
+
/**
|
|
26
|
+
* Convert to slug
|
|
27
|
+
*
|
|
28
|
+
* @returns {this} The Stringable instance
|
|
29
|
+
*/
|
|
30
|
+
slug(): this;
|
|
31
|
+
/**
|
|
32
|
+
* Convert to snake_case
|
|
33
|
+
*
|
|
34
|
+
* @returns {this} The Stringable instance
|
|
35
|
+
*/
|
|
36
|
+
snake(): this;
|
|
37
|
+
/**
|
|
38
|
+
* Convert to kebab-case
|
|
39
|
+
*
|
|
40
|
+
* @returns {this} The Stringable instance
|
|
41
|
+
*/
|
|
42
|
+
kebab(): this;
|
|
43
|
+
/**
|
|
44
|
+
* Convert to camelCase
|
|
45
|
+
*
|
|
46
|
+
* @returns {this} The Stringable instance
|
|
47
|
+
*/
|
|
48
|
+
camel(): this;
|
|
49
|
+
/**
|
|
50
|
+
* Convert to StudlyCase
|
|
51
|
+
*
|
|
52
|
+
* @returns {this} The Stringable instance
|
|
53
|
+
*/
|
|
54
|
+
studly(): this;
|
|
55
|
+
/**
|
|
56
|
+
* Limit the string length
|
|
57
|
+
*
|
|
58
|
+
* @param {number} size The maximum length
|
|
59
|
+
* @param {string} [end='…'] The string to append if limited
|
|
60
|
+
* @returns {this} The Stringable instance
|
|
61
|
+
*/
|
|
62
|
+
limit(size: number, end?: string): this;
|
|
63
|
+
/**
|
|
64
|
+
* Append a value to the string
|
|
65
|
+
*
|
|
66
|
+
* @param {...unknown[]} values The values to append
|
|
67
|
+
* @returns {this} The Stringable instance
|
|
68
|
+
*/
|
|
69
|
+
append(...values: unknown[]): this;
|
|
70
|
+
/**
|
|
71
|
+
* Prepend a value to the string
|
|
72
|
+
*
|
|
73
|
+
* @param {...unknown[]} values The values to prepend
|
|
74
|
+
* @returns {this} The Stringable instance
|
|
75
|
+
*/
|
|
76
|
+
prepend(...values: unknown[]): this;
|
|
77
|
+
/**
|
|
78
|
+
* Cap the string with a value if it doesn't already end with it
|
|
79
|
+
*
|
|
80
|
+
* @param {string} cap The string to end with
|
|
81
|
+
* @returns {this} The Stringable instance
|
|
82
|
+
*/
|
|
83
|
+
finish(cap: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Start the string with a value if it doesn't already start with it
|
|
86
|
+
*
|
|
87
|
+
* @param {string} prefix The string to start with
|
|
88
|
+
* @returns {this} The Stringable instance
|
|
89
|
+
*/
|
|
90
|
+
start(prefix: string): this;
|
|
91
|
+
/**
|
|
92
|
+
* Replace the first occurrence of a value
|
|
93
|
+
*
|
|
94
|
+
* @param {string | RegExp} search The value to search for
|
|
95
|
+
* @param {string} replace The value to replace with
|
|
96
|
+
* @returns {this} The Stringable instance
|
|
97
|
+
*/
|
|
98
|
+
replace(search: string | RegExp, replace: string): this;
|
|
99
|
+
/**
|
|
100
|
+
* Replace all occurrences of a value
|
|
101
|
+
*
|
|
102
|
+
* @param {string | RegExp} search The value to search for
|
|
103
|
+
* @param {string} replace The value to replace with
|
|
104
|
+
* @returns {this} The Stringable instance
|
|
105
|
+
*/
|
|
106
|
+
replaceAll(search: string | RegExp, replace: string): this;
|
|
107
|
+
/**
|
|
108
|
+
* Reverse the string
|
|
109
|
+
*
|
|
110
|
+
* @returns {this} The Stringable instance
|
|
111
|
+
*/
|
|
112
|
+
reverse(): this;
|
|
113
|
+
/**
|
|
114
|
+
* Mask a portion of the string
|
|
115
|
+
*
|
|
116
|
+
* @param {string} character The masking character
|
|
117
|
+
* @param {number} index The starting index
|
|
118
|
+
* @param {number} [length] The number of characters to mask
|
|
119
|
+
* @returns {this} The Stringable instance
|
|
120
|
+
*/
|
|
121
|
+
mask(character: string, index: number, length?: number): this;
|
|
122
|
+
/**
|
|
123
|
+
* Trim the string
|
|
124
|
+
*
|
|
125
|
+
* @param {string} [chars] The characters to trim (defaults to whitespace)
|
|
126
|
+
* @returns {this} The Stringable instance
|
|
127
|
+
*/
|
|
128
|
+
trim(chars?: string): this;
|
|
129
|
+
/**
|
|
130
|
+
* Convert to lower case
|
|
131
|
+
*
|
|
132
|
+
* @returns {this} The Stringable instance
|
|
133
|
+
*/
|
|
134
|
+
lower(): this;
|
|
135
|
+
/**
|
|
136
|
+
* Convert to upper case
|
|
137
|
+
*
|
|
138
|
+
* @returns {this} The Stringable instance
|
|
139
|
+
*/
|
|
140
|
+
upper(): this;
|
|
141
|
+
/**
|
|
142
|
+
* Capitalize the first letter
|
|
143
|
+
*
|
|
144
|
+
* @returns {this} The Stringable instance
|
|
145
|
+
*/
|
|
146
|
+
capitalize(): this;
|
|
147
|
+
/**
|
|
148
|
+
* Check if string contains a value
|
|
149
|
+
*
|
|
150
|
+
* @param {string | string[]} needles The values to search for
|
|
151
|
+
* @returns {boolean} True if the string contains any of the values
|
|
152
|
+
*/
|
|
153
|
+
contains(needles: string | string[]): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Check if string contains all values
|
|
156
|
+
*
|
|
157
|
+
* @param {string[]} needles The values to search for
|
|
158
|
+
* @returns {boolean} True if the string contains all values
|
|
159
|
+
*/
|
|
160
|
+
containsAll(needles: string[]): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Check if string starts with a value
|
|
163
|
+
*
|
|
164
|
+
* @param {string | string[]} needles The values to check
|
|
165
|
+
* @returns {boolean} True if the string starts with any of the values
|
|
166
|
+
*/
|
|
167
|
+
startsWith(needles: string | string[]): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Check if string ends with a value
|
|
170
|
+
*
|
|
171
|
+
* @param {string | string[]} needles The values to check
|
|
172
|
+
* @returns {boolean} True if the string ends with any of the values
|
|
173
|
+
*/
|
|
174
|
+
endsWith(needles: string | string[]): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Execute a callback with the stringable and return the result
|
|
177
|
+
*
|
|
178
|
+
* @param {(str: this) => U} callback The callback to execute
|
|
179
|
+
* @returns {U} The result of the callback
|
|
180
|
+
*/
|
|
181
|
+
pipe<U>(callback: (str: this) => U): U;
|
|
182
|
+
/**
|
|
183
|
+
* Conditionally execute a callback
|
|
184
|
+
*
|
|
185
|
+
* @param {boolean | (() => boolean)} condition The condition to check
|
|
186
|
+
* @param {(str: this) => void} callback The callback to execute
|
|
187
|
+
* @returns {this} The Stringable instance
|
|
188
|
+
*/
|
|
189
|
+
when(condition: boolean | (() => boolean), callback: (str: this) => void): this;
|
|
190
|
+
/**
|
|
191
|
+
* Execute a callback and return the stringable (for side effects)
|
|
192
|
+
*
|
|
193
|
+
* @param {(str: this) => void} callback The callback to execute
|
|
194
|
+
* @returns {this} The Stringable instance
|
|
195
|
+
*/
|
|
196
|
+
tap(callback: (str: this) => void): this;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Create a new fluent stringable instance
|
|
200
|
+
*
|
|
201
|
+
* @param {unknown} [value] The initial string value
|
|
202
|
+
* @returns {Stringable} A new Stringable instance
|
|
203
|
+
*/
|
|
204
|
+
declare const str: (value?: unknown) => Stringable;
|
|
205
|
+
/**
|
|
206
|
+
* Static methods for string manipulation
|
|
207
|
+
*/
|
|
208
|
+
declare const Str: {
|
|
209
|
+
/**
|
|
210
|
+
* Create a new fluent stringable instance
|
|
211
|
+
*
|
|
212
|
+
* @param {unknown} value The initial string value
|
|
213
|
+
* @returns {Stringable} A new Stringable instance
|
|
214
|
+
*/
|
|
215
|
+
of: (value: unknown) => Stringable;
|
|
216
|
+
/**
|
|
217
|
+
* Convert a string to a slug
|
|
218
|
+
*
|
|
219
|
+
* @param {string} value The string to slugify
|
|
220
|
+
* @returns {string} The slugified string
|
|
221
|
+
*/
|
|
222
|
+
slug: (value: string) => string;
|
|
223
|
+
/**
|
|
224
|
+
* Convert a string to snake_case
|
|
225
|
+
*
|
|
226
|
+
* @param {string} value The string to convert
|
|
227
|
+
* @returns {string} The snake_case string
|
|
228
|
+
*/
|
|
229
|
+
snake: (value: string) => string;
|
|
230
|
+
/**
|
|
231
|
+
* Convert a string to kebab-case
|
|
232
|
+
*
|
|
233
|
+
* @param {string} value The string to convert
|
|
234
|
+
* @returns {string} The kebab-case string
|
|
235
|
+
*/
|
|
236
|
+
kebab: (value: string) => string;
|
|
237
|
+
/**
|
|
238
|
+
* Convert a string to camelCase
|
|
239
|
+
*
|
|
240
|
+
* @param {string} value The string to convert
|
|
241
|
+
* @returns {string} The camelCase string
|
|
242
|
+
*/
|
|
243
|
+
camel: (value: string) => string;
|
|
244
|
+
/**
|
|
245
|
+
* Convert a string to StudlyCase
|
|
246
|
+
*
|
|
247
|
+
* @param {string} value The string to convert
|
|
248
|
+
* @returns {string} The StudlyCase string
|
|
249
|
+
*/
|
|
250
|
+
studly: (value: string) => string;
|
|
251
|
+
/**
|
|
252
|
+
* Convert a string to title case
|
|
253
|
+
*
|
|
254
|
+
* @param {string} value The string to convert
|
|
255
|
+
* @returns {string} The title case string
|
|
256
|
+
*/
|
|
257
|
+
title: (value: string) => string;
|
|
258
|
+
/**
|
|
259
|
+
* Limit the length of a string
|
|
260
|
+
*
|
|
261
|
+
* @param {string} value The string to limit
|
|
262
|
+
* @param {number} size The maximum length
|
|
263
|
+
* @param {string} [end='…'] The string to append if limited
|
|
264
|
+
* @returns {string} The limited string
|
|
265
|
+
*/
|
|
266
|
+
limit: (value: string, size: number, end?: string) => string;
|
|
267
|
+
/**
|
|
268
|
+
* Generate a random alphanumeric string
|
|
269
|
+
*
|
|
270
|
+
* @param {number} [length=16] The length of the random string
|
|
271
|
+
* @returns {string} The random string
|
|
272
|
+
*/
|
|
273
|
+
random: (length?: number) => string;
|
|
274
|
+
/**
|
|
275
|
+
* Generate a UUID (version 4)
|
|
276
|
+
*
|
|
277
|
+
* @returns {string} The generated UUID
|
|
278
|
+
*/
|
|
279
|
+
uuid: () => string;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
export { Str, Stringable, str };
|
package/dist/str.d.ts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent string manipulation class inspired by Laravel's Str and Stringable
|
|
3
|
+
*/
|
|
4
|
+
declare class Stringable {
|
|
5
|
+
protected value: string;
|
|
6
|
+
constructor(value: unknown);
|
|
7
|
+
/**
|
|
8
|
+
* Get the raw string value
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The raw string
|
|
11
|
+
*/
|
|
12
|
+
toString(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Alias for toString()
|
|
15
|
+
*
|
|
16
|
+
* @returns {string} The raw string
|
|
17
|
+
*/
|
|
18
|
+
get(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Convert to title case
|
|
21
|
+
*
|
|
22
|
+
* @returns {this} The Stringable instance
|
|
23
|
+
*/
|
|
24
|
+
title(): this;
|
|
25
|
+
/**
|
|
26
|
+
* Convert to slug
|
|
27
|
+
*
|
|
28
|
+
* @returns {this} The Stringable instance
|
|
29
|
+
*/
|
|
30
|
+
slug(): this;
|
|
31
|
+
/**
|
|
32
|
+
* Convert to snake_case
|
|
33
|
+
*
|
|
34
|
+
* @returns {this} The Stringable instance
|
|
35
|
+
*/
|
|
36
|
+
snake(): this;
|
|
37
|
+
/**
|
|
38
|
+
* Convert to kebab-case
|
|
39
|
+
*
|
|
40
|
+
* @returns {this} The Stringable instance
|
|
41
|
+
*/
|
|
42
|
+
kebab(): this;
|
|
43
|
+
/**
|
|
44
|
+
* Convert to camelCase
|
|
45
|
+
*
|
|
46
|
+
* @returns {this} The Stringable instance
|
|
47
|
+
*/
|
|
48
|
+
camel(): this;
|
|
49
|
+
/**
|
|
50
|
+
* Convert to StudlyCase
|
|
51
|
+
*
|
|
52
|
+
* @returns {this} The Stringable instance
|
|
53
|
+
*/
|
|
54
|
+
studly(): this;
|
|
55
|
+
/**
|
|
56
|
+
* Limit the string length
|
|
57
|
+
*
|
|
58
|
+
* @param {number} size The maximum length
|
|
59
|
+
* @param {string} [end='…'] The string to append if limited
|
|
60
|
+
* @returns {this} The Stringable instance
|
|
61
|
+
*/
|
|
62
|
+
limit(size: number, end?: string): this;
|
|
63
|
+
/**
|
|
64
|
+
* Append a value to the string
|
|
65
|
+
*
|
|
66
|
+
* @param {...unknown[]} values The values to append
|
|
67
|
+
* @returns {this} The Stringable instance
|
|
68
|
+
*/
|
|
69
|
+
append(...values: unknown[]): this;
|
|
70
|
+
/**
|
|
71
|
+
* Prepend a value to the string
|
|
72
|
+
*
|
|
73
|
+
* @param {...unknown[]} values The values to prepend
|
|
74
|
+
* @returns {this} The Stringable instance
|
|
75
|
+
*/
|
|
76
|
+
prepend(...values: unknown[]): this;
|
|
77
|
+
/**
|
|
78
|
+
* Cap the string with a value if it doesn't already end with it
|
|
79
|
+
*
|
|
80
|
+
* @param {string} cap The string to end with
|
|
81
|
+
* @returns {this} The Stringable instance
|
|
82
|
+
*/
|
|
83
|
+
finish(cap: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* Start the string with a value if it doesn't already start with it
|
|
86
|
+
*
|
|
87
|
+
* @param {string} prefix The string to start with
|
|
88
|
+
* @returns {this} The Stringable instance
|
|
89
|
+
*/
|
|
90
|
+
start(prefix: string): this;
|
|
91
|
+
/**
|
|
92
|
+
* Replace the first occurrence of a value
|
|
93
|
+
*
|
|
94
|
+
* @param {string | RegExp} search The value to search for
|
|
95
|
+
* @param {string} replace The value to replace with
|
|
96
|
+
* @returns {this} The Stringable instance
|
|
97
|
+
*/
|
|
98
|
+
replace(search: string | RegExp, replace: string): this;
|
|
99
|
+
/**
|
|
100
|
+
* Replace all occurrences of a value
|
|
101
|
+
*
|
|
102
|
+
* @param {string | RegExp} search The value to search for
|
|
103
|
+
* @param {string} replace The value to replace with
|
|
104
|
+
* @returns {this} The Stringable instance
|
|
105
|
+
*/
|
|
106
|
+
replaceAll(search: string | RegExp, replace: string): this;
|
|
107
|
+
/**
|
|
108
|
+
* Reverse the string
|
|
109
|
+
*
|
|
110
|
+
* @returns {this} The Stringable instance
|
|
111
|
+
*/
|
|
112
|
+
reverse(): this;
|
|
113
|
+
/**
|
|
114
|
+
* Mask a portion of the string
|
|
115
|
+
*
|
|
116
|
+
* @param {string} character The masking character
|
|
117
|
+
* @param {number} index The starting index
|
|
118
|
+
* @param {number} [length] The number of characters to mask
|
|
119
|
+
* @returns {this} The Stringable instance
|
|
120
|
+
*/
|
|
121
|
+
mask(character: string, index: number, length?: number): this;
|
|
122
|
+
/**
|
|
123
|
+
* Trim the string
|
|
124
|
+
*
|
|
125
|
+
* @param {string} [chars] The characters to trim (defaults to whitespace)
|
|
126
|
+
* @returns {this} The Stringable instance
|
|
127
|
+
*/
|
|
128
|
+
trim(chars?: string): this;
|
|
129
|
+
/**
|
|
130
|
+
* Convert to lower case
|
|
131
|
+
*
|
|
132
|
+
* @returns {this} The Stringable instance
|
|
133
|
+
*/
|
|
134
|
+
lower(): this;
|
|
135
|
+
/**
|
|
136
|
+
* Convert to upper case
|
|
137
|
+
*
|
|
138
|
+
* @returns {this} The Stringable instance
|
|
139
|
+
*/
|
|
140
|
+
upper(): this;
|
|
141
|
+
/**
|
|
142
|
+
* Capitalize the first letter
|
|
143
|
+
*
|
|
144
|
+
* @returns {this} The Stringable instance
|
|
145
|
+
*/
|
|
146
|
+
capitalize(): this;
|
|
147
|
+
/**
|
|
148
|
+
* Check if string contains a value
|
|
149
|
+
*
|
|
150
|
+
* @param {string | string[]} needles The values to search for
|
|
151
|
+
* @returns {boolean} True if the string contains any of the values
|
|
152
|
+
*/
|
|
153
|
+
contains(needles: string | string[]): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Check if string contains all values
|
|
156
|
+
*
|
|
157
|
+
* @param {string[]} needles The values to search for
|
|
158
|
+
* @returns {boolean} True if the string contains all values
|
|
159
|
+
*/
|
|
160
|
+
containsAll(needles: string[]): boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Check if string starts with a value
|
|
163
|
+
*
|
|
164
|
+
* @param {string | string[]} needles The values to check
|
|
165
|
+
* @returns {boolean} True if the string starts with any of the values
|
|
166
|
+
*/
|
|
167
|
+
startsWith(needles: string | string[]): boolean;
|
|
168
|
+
/**
|
|
169
|
+
* Check if string ends with a value
|
|
170
|
+
*
|
|
171
|
+
* @param {string | string[]} needles The values to check
|
|
172
|
+
* @returns {boolean} True if the string ends with any of the values
|
|
173
|
+
*/
|
|
174
|
+
endsWith(needles: string | string[]): boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Execute a callback with the stringable and return the result
|
|
177
|
+
*
|
|
178
|
+
* @param {(str: this) => U} callback The callback to execute
|
|
179
|
+
* @returns {U} The result of the callback
|
|
180
|
+
*/
|
|
181
|
+
pipe<U>(callback: (str: this) => U): U;
|
|
182
|
+
/**
|
|
183
|
+
* Conditionally execute a callback
|
|
184
|
+
*
|
|
185
|
+
* @param {boolean | (() => boolean)} condition The condition to check
|
|
186
|
+
* @param {(str: this) => void} callback The callback to execute
|
|
187
|
+
* @returns {this} The Stringable instance
|
|
188
|
+
*/
|
|
189
|
+
when(condition: boolean | (() => boolean), callback: (str: this) => void): this;
|
|
190
|
+
/**
|
|
191
|
+
* Execute a callback and return the stringable (for side effects)
|
|
192
|
+
*
|
|
193
|
+
* @param {(str: this) => void} callback The callback to execute
|
|
194
|
+
* @returns {this} The Stringable instance
|
|
195
|
+
*/
|
|
196
|
+
tap(callback: (str: this) => void): this;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Create a new fluent stringable instance
|
|
200
|
+
*
|
|
201
|
+
* @param {unknown} [value] The initial string value
|
|
202
|
+
* @returns {Stringable} A new Stringable instance
|
|
203
|
+
*/
|
|
204
|
+
declare const str: (value?: unknown) => Stringable;
|
|
205
|
+
/**
|
|
206
|
+
* Static methods for string manipulation
|
|
207
|
+
*/
|
|
208
|
+
declare const Str: {
|
|
209
|
+
/**
|
|
210
|
+
* Create a new fluent stringable instance
|
|
211
|
+
*
|
|
212
|
+
* @param {unknown} value The initial string value
|
|
213
|
+
* @returns {Stringable} A new Stringable instance
|
|
214
|
+
*/
|
|
215
|
+
of: (value: unknown) => Stringable;
|
|
216
|
+
/**
|
|
217
|
+
* Convert a string to a slug
|
|
218
|
+
*
|
|
219
|
+
* @param {string} value The string to slugify
|
|
220
|
+
* @returns {string} The slugified string
|
|
221
|
+
*/
|
|
222
|
+
slug: (value: string) => string;
|
|
223
|
+
/**
|
|
224
|
+
* Convert a string to snake_case
|
|
225
|
+
*
|
|
226
|
+
* @param {string} value The string to convert
|
|
227
|
+
* @returns {string} The snake_case string
|
|
228
|
+
*/
|
|
229
|
+
snake: (value: string) => string;
|
|
230
|
+
/**
|
|
231
|
+
* Convert a string to kebab-case
|
|
232
|
+
*
|
|
233
|
+
* @param {string} value The string to convert
|
|
234
|
+
* @returns {string} The kebab-case string
|
|
235
|
+
*/
|
|
236
|
+
kebab: (value: string) => string;
|
|
237
|
+
/**
|
|
238
|
+
* Convert a string to camelCase
|
|
239
|
+
*
|
|
240
|
+
* @param {string} value The string to convert
|
|
241
|
+
* @returns {string} The camelCase string
|
|
242
|
+
*/
|
|
243
|
+
camel: (value: string) => string;
|
|
244
|
+
/**
|
|
245
|
+
* Convert a string to StudlyCase
|
|
246
|
+
*
|
|
247
|
+
* @param {string} value The string to convert
|
|
248
|
+
* @returns {string} The StudlyCase string
|
|
249
|
+
*/
|
|
250
|
+
studly: (value: string) => string;
|
|
251
|
+
/**
|
|
252
|
+
* Convert a string to title case
|
|
253
|
+
*
|
|
254
|
+
* @param {string} value The string to convert
|
|
255
|
+
* @returns {string} The title case string
|
|
256
|
+
*/
|
|
257
|
+
title: (value: string) => string;
|
|
258
|
+
/**
|
|
259
|
+
* Limit the length of a string
|
|
260
|
+
*
|
|
261
|
+
* @param {string} value The string to limit
|
|
262
|
+
* @param {number} size The maximum length
|
|
263
|
+
* @param {string} [end='…'] The string to append if limited
|
|
264
|
+
* @returns {string} The limited string
|
|
265
|
+
*/
|
|
266
|
+
limit: (value: string, size: number, end?: string) => string;
|
|
267
|
+
/**
|
|
268
|
+
* Generate a random alphanumeric string
|
|
269
|
+
*
|
|
270
|
+
* @param {number} [length=16] The length of the random string
|
|
271
|
+
* @returns {string} The random string
|
|
272
|
+
*/
|
|
273
|
+
random: (length?: number) => string;
|
|
274
|
+
/**
|
|
275
|
+
* Generate a UUID (version 4)
|
|
276
|
+
*
|
|
277
|
+
* @returns {string} The generated UUID
|
|
278
|
+
*/
|
|
279
|
+
uuid: () => string;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
export { Str, Stringable, str };
|
package/dist/str.js
ADDED
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common type definitions for the helpers package
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A generic record object with string keys and unknown values
|
|
6
|
+
*/
|
|
7
|
+
type GenericRecord = Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* A type that can be an object record or an array
|
|
10
|
+
*/
|
|
11
|
+
type DataContainer = GenericRecord | unknown[];
|
|
12
|
+
|
|
13
|
+
export type { DataContainer, GenericRecord };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common type definitions for the helpers package
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A generic record object with string keys and unknown values
|
|
6
|
+
*/
|
|
7
|
+
type GenericRecord = Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* A type that can be an object record or an array
|
|
10
|
+
*/
|
|
11
|
+
type DataContainer = GenericRecord | unknown[];
|
|
12
|
+
|
|
13
|
+
export type { DataContainer, GenericRecord };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-6F4PWJZI.js";
|