utilitify-core 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 +338 -0
- package/dist/async.cjs +25 -0
- package/dist/async.cjs.map +1 -0
- package/dist/async.d.cts +104 -0
- package/dist/async.d.ts +104 -0
- package/dist/async.js +4 -0
- package/dist/async.js.map +1 -0
- package/dist/chunk-2ICNRTSN.cjs +346 -0
- package/dist/chunk-2ICNRTSN.cjs.map +1 -0
- package/dist/chunk-3DPF72DY.js +170 -0
- package/dist/chunk-3DPF72DY.js.map +1 -0
- package/dist/chunk-4CV4JOE5.js +24 -0
- package/dist/chunk-4CV4JOE5.js.map +1 -0
- package/dist/chunk-4SLYNSLH.cjs +783 -0
- package/dist/chunk-4SLYNSLH.cjs.map +1 -0
- package/dist/chunk-5WP7DWCG.js +1285 -0
- package/dist/chunk-5WP7DWCG.js.map +1 -0
- package/dist/chunk-BMQ6YPKV.js +876 -0
- package/dist/chunk-BMQ6YPKV.js.map +1 -0
- package/dist/chunk-BZCMWUKS.cjs +479 -0
- package/dist/chunk-BZCMWUKS.cjs.map +1 -0
- package/dist/chunk-C5R744DY.cjs +173 -0
- package/dist/chunk-C5R744DY.cjs.map +1 -0
- package/dist/chunk-C75J62CV.cjs +913 -0
- package/dist/chunk-C75J62CV.cjs.map +1 -0
- package/dist/chunk-CZLDE2OZ.cjs +28 -0
- package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
- package/dist/chunk-DSMB6AF6.cjs +193 -0
- package/dist/chunk-DSMB6AF6.cjs.map +1 -0
- package/dist/chunk-ETWGPOPY.js +426 -0
- package/dist/chunk-ETWGPOPY.js.map +1 -0
- package/dist/chunk-FQBPVN63.cjs +403 -0
- package/dist/chunk-FQBPVN63.cjs.map +1 -0
- package/dist/chunk-G4GYQGTW.cjs +178 -0
- package/dist/chunk-G4GYQGTW.cjs.map +1 -0
- package/dist/chunk-GFDMZDMI.js +486 -0
- package/dist/chunk-GFDMZDMI.js.map +1 -0
- package/dist/chunk-HOTOYIPB.js +171 -0
- package/dist/chunk-HOTOYIPB.js.map +1 -0
- package/dist/chunk-HYADH4ZX.js +176 -0
- package/dist/chunk-HYADH4ZX.js.map +1 -0
- package/dist/chunk-JBN7C5WE.js +255 -0
- package/dist/chunk-JBN7C5WE.js.map +1 -0
- package/dist/chunk-JNCTPFTD.cjs +25 -0
- package/dist/chunk-JNCTPFTD.cjs.map +1 -0
- package/dist/chunk-N3BH3BV7.js +21 -0
- package/dist/chunk-N3BH3BV7.js.map +1 -0
- package/dist/chunk-NFPGAVRQ.js +749 -0
- package/dist/chunk-NFPGAVRQ.js.map +1 -0
- package/dist/chunk-OFFRGRBN.cjs +1332 -0
- package/dist/chunk-OFFRGRBN.cjs.map +1 -0
- package/dist/chunk-OZLKYIZL.cjs +490 -0
- package/dist/chunk-OZLKYIZL.cjs.map +1 -0
- package/dist/chunk-P3NUK46X.js +145 -0
- package/dist/chunk-P3NUK46X.js.map +1 -0
- package/dist/chunk-P7P2B7ZI.cjs +429 -0
- package/dist/chunk-P7P2B7ZI.cjs.map +1 -0
- package/dist/chunk-PB6SKSJN.cjs +150 -0
- package/dist/chunk-PB6SKSJN.cjs.map +1 -0
- package/dist/chunk-R3IXCJR7.js +378 -0
- package/dist/chunk-R3IXCJR7.js.map +1 -0
- package/dist/chunk-SD6P3WEJ.js +324 -0
- package/dist/chunk-SD6P3WEJ.js.map +1 -0
- package/dist/chunk-YSCHP26P.js +451 -0
- package/dist/chunk-YSCHP26P.js.map +1 -0
- package/dist/chunk-ZLMPRPCY.cjs +274 -0
- package/dist/chunk-ZLMPRPCY.cjs.map +1 -0
- package/dist/common-CBDYNJeh.d.cts +48 -0
- package/dist/common-CBDYNJeh.d.ts +48 -0
- package/dist/constants.cjs +42 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +60 -0
- package/dist/constants.d.ts +60 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/country/index.cjs +154 -0
- package/dist/country/index.cjs.map +1 -0
- package/dist/country/index.d.cts +1 -0
- package/dist/country/index.d.ts +1 -0
- package/dist/country/index.js +5 -0
- package/dist/country/index.js.map +1 -0
- package/dist/date/index.cjs +117 -0
- package/dist/date/index.cjs.map +1 -0
- package/dist/date/index.d.cts +283 -0
- package/dist/date/index.d.ts +283 -0
- package/dist/date/index.js +4 -0
- package/dist/date/index.js.map +1 -0
- package/dist/environment/index.cjs +73 -0
- package/dist/environment/index.cjs.map +1 -0
- package/dist/environment/index.d.cts +127 -0
- package/dist/environment/index.d.ts +127 -0
- package/dist/environment/index.js +4 -0
- package/dist/environment/index.js.map +1 -0
- package/dist/form/index.cjs +81 -0
- package/dist/form/index.cjs.map +1 -0
- package/dist/form/index.d.cts +227 -0
- package/dist/form/index.d.ts +227 -0
- package/dist/form/index.js +4 -0
- package/dist/form/index.js.map +1 -0
- package/dist/i18n.cjs +37 -0
- package/dist/i18n.cjs.map +1 -0
- package/dist/i18n.d.cts +102 -0
- package/dist/i18n.d.ts +102 -0
- package/dist/i18n.js +4 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index-BXBmBHyL.d.ts +718 -0
- package/dist/index-BYsUCP3u.d.cts +718 -0
- package/dist/index-Cl26FrAZ.d.cts +362 -0
- package/dist/index-Cl26FrAZ.d.ts +362 -0
- package/dist/index.cjs +1265 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +205 -0
- package/dist/index.d.ts +205 -0
- package/dist/index.js +277 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.cjs +13 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +84 -0
- package/dist/schema.d.ts +84 -0
- package/dist/schema.js +4 -0
- package/dist/schema.js.map +1 -0
- package/dist/security/index.cjs +94 -0
- package/dist/security/index.cjs.map +1 -0
- package/dist/security/index.d.cts +216 -0
- package/dist/security/index.d.ts +216 -0
- package/dist/security/index.js +5 -0
- package/dist/security/index.js.map +1 -0
- package/dist/string/index.cjs +153 -0
- package/dist/string/index.cjs.map +1 -0
- package/dist/string/index.d.cts +471 -0
- package/dist/string/index.d.ts +471 -0
- package/dist/string/index.js +4 -0
- package/dist/string/index.js.map +1 -0
- package/dist/transform/index.cjs +105 -0
- package/dist/transform/index.cjs.map +1 -0
- package/dist/transform/index.d.cts +271 -0
- package/dist/transform/index.d.ts +271 -0
- package/dist/transform/index.js +4 -0
- package/dist/transform/index.js.map +1 -0
- package/dist/validators/index.cjs +195 -0
- package/dist/validators/index.cjs.map +1 -0
- package/dist/validators/index.d.cts +2 -0
- package/dist/validators/index.d.ts +2 -0
- package/dist/validators/index.js +6 -0
- package/dist/validators/index.js.map +1 -0
- package/package.json +229 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert string to camelCase
|
|
3
|
+
*
|
|
4
|
+
* @param str - String to convert
|
|
5
|
+
* @returns camelCase string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* toCamelCase('hello world'); // 'helloWorld'
|
|
10
|
+
* toCamelCase('hello-world'); // 'helloWorld'
|
|
11
|
+
* toCamelCase('HelloWorld'); // 'helloWorld'
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function toCamelCase(str: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Convert string to PascalCase
|
|
17
|
+
*
|
|
18
|
+
* @param str - String to convert
|
|
19
|
+
* @returns PascalCase string
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* toPascalCase('hello world'); // 'HelloWorld'
|
|
24
|
+
* toPascalCase('hello-world'); // 'HelloWorld'
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function toPascalCase(str: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Convert string to snake_case
|
|
30
|
+
*
|
|
31
|
+
* @param str - String to convert
|
|
32
|
+
* @returns snake_case string
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* toSnakeCase('helloWorld'); // 'hello_world'
|
|
37
|
+
* toSnakeCase('Hello World'); // 'hello_world'
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function toSnakeCase(str: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Convert string to kebab-case
|
|
43
|
+
*
|
|
44
|
+
* @param str - String to convert
|
|
45
|
+
* @returns kebab-case string
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* toKebabCase('helloWorld'); // 'hello-world'
|
|
50
|
+
* toKebabCase('Hello World'); // 'hello-world'
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function toKebabCase(str: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Convert string to Title Case
|
|
56
|
+
*
|
|
57
|
+
* @param str - String to convert
|
|
58
|
+
* @returns Title Case string
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* toTitleCase('hello world'); // 'Hello World'
|
|
63
|
+
* toTitleCase('the quick brown'); // 'The Quick Brown'
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function toTitleCase(str: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Convert string to CONSTANT_CASE
|
|
69
|
+
*
|
|
70
|
+
* @param str - String to convert
|
|
71
|
+
* @returns CONSTANT_CASE string
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* toConstantCase('helloWorld'); // 'HELLO_WORLD'
|
|
76
|
+
* toConstantCase('Hello World'); // 'HELLO_WORLD'
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function toConstantCase(str: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Convert string to Sentence case
|
|
82
|
+
*
|
|
83
|
+
* @param str - String to convert
|
|
84
|
+
* @returns Sentence case string
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* toSentenceCase('hello World'); // 'Hello world'
|
|
89
|
+
* toSentenceCase('HELLO WORLD'); // 'Hello world'
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function toSentenceCase(str: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Convert string to dot.case
|
|
95
|
+
*
|
|
96
|
+
* @param str - String to convert
|
|
97
|
+
* @returns dot.case string
|
|
98
|
+
*/
|
|
99
|
+
declare function toDotCase(str: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Capitalize first letter
|
|
102
|
+
*
|
|
103
|
+
* @param str - String to capitalize
|
|
104
|
+
* @returns Capitalized string
|
|
105
|
+
*/
|
|
106
|
+
declare function capitalize(str: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Uncapitalize first letter
|
|
109
|
+
*
|
|
110
|
+
* @param str - String to uncapitalize
|
|
111
|
+
* @returns Uncapitalized string
|
|
112
|
+
*/
|
|
113
|
+
declare function uncapitalize(str: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* Swap case of each character
|
|
116
|
+
*
|
|
117
|
+
* @param str - String to swap
|
|
118
|
+
* @returns Swapped case string
|
|
119
|
+
*/
|
|
120
|
+
declare function swapCase(str: string): string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Slug generation options
|
|
124
|
+
*/
|
|
125
|
+
interface SlugOptions {
|
|
126
|
+
/** Convert to lowercase (default: true) */
|
|
127
|
+
lowercase?: boolean;
|
|
128
|
+
/** Separator character (default: '-') */
|
|
129
|
+
separator?: string;
|
|
130
|
+
/** Maximum length (default: unlimited) */
|
|
131
|
+
maxLength?: number;
|
|
132
|
+
/** Transliterate non-ASCII characters (default: true) */
|
|
133
|
+
transliterate?: boolean;
|
|
134
|
+
/** Remove stop words (default: false) */
|
|
135
|
+
removeStopWords?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Convert string to SEO-friendly slug
|
|
139
|
+
*
|
|
140
|
+
* @param str - String to convert
|
|
141
|
+
* @param options - Slug options
|
|
142
|
+
* @returns SEO-friendly slug
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* toSlug('Hello World!'); // 'hello-world'
|
|
147
|
+
* toSlug('Café & Restaurant'); // 'cafe-and-restaurant'
|
|
148
|
+
* toSlug('Hello World', { separator: '_' }); // 'hello_world'
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
declare function toSlug(str: string, options?: SlugOptions): string;
|
|
152
|
+
/**
|
|
153
|
+
* Transliterate non-ASCII characters to ASCII
|
|
154
|
+
*
|
|
155
|
+
* @param str - String to transliterate
|
|
156
|
+
* @returns Transliterated string
|
|
157
|
+
*/
|
|
158
|
+
declare function transliterate(str: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Generate URL-safe slug from string
|
|
161
|
+
*
|
|
162
|
+
* @param str - String to slugify
|
|
163
|
+
* @returns URL-safe slug
|
|
164
|
+
*/
|
|
165
|
+
declare function slugify(str: string): string;
|
|
166
|
+
/**
|
|
167
|
+
* Generate unique slug by appending number if needed
|
|
168
|
+
*
|
|
169
|
+
* @param str - Base string
|
|
170
|
+
* @param existingSlugs - Set of existing slugs
|
|
171
|
+
* @param options - Slug options
|
|
172
|
+
* @returns Unique slug
|
|
173
|
+
*/
|
|
174
|
+
declare function uniqueSlug(str: string, existingSlugs: Set<string> | string[], options?: SlugOptions): string;
|
|
175
|
+
/**
|
|
176
|
+
* Check if string is a valid slug
|
|
177
|
+
*
|
|
178
|
+
* @param str - String to check
|
|
179
|
+
* @returns true if valid slug
|
|
180
|
+
*/
|
|
181
|
+
declare function isValidSlug(str: string): boolean;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Mask options
|
|
185
|
+
*/
|
|
186
|
+
interface MaskOptions {
|
|
187
|
+
/** Mask character (default: '*') */
|
|
188
|
+
maskChar?: string;
|
|
189
|
+
/** Number of visible chars at start (default: varies by type) */
|
|
190
|
+
visibleStart?: number;
|
|
191
|
+
/** Number of visible chars at end (default: varies by type) */
|
|
192
|
+
visibleEnd?: number;
|
|
193
|
+
/** Minimum string length to mask (default: 4) */
|
|
194
|
+
minLength?: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Mask an email address
|
|
198
|
+
*
|
|
199
|
+
* @param email - Email to mask
|
|
200
|
+
* @param options - Mask options
|
|
201
|
+
* @returns Masked email
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* maskEmail('john.doe@gmail.com'); // 'j***@gmail.com'
|
|
206
|
+
* maskEmail('test@example.com'); // 't***@example.com'
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
declare function maskEmail(email: string, options?: MaskOptions): string;
|
|
210
|
+
/**
|
|
211
|
+
* Mask a phone number
|
|
212
|
+
*
|
|
213
|
+
* @param phone - Phone to mask
|
|
214
|
+
* @param options - Mask options
|
|
215
|
+
* @returns Masked phone
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* maskPhone('+1 555-123-4567'); // '+1 *** *** 4567'
|
|
220
|
+
* maskPhone('03001234567'); // '030*****67'
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
declare function maskPhone(phone: string, options?: MaskOptions): string;
|
|
224
|
+
/**
|
|
225
|
+
* Mask a credit card number
|
|
226
|
+
*
|
|
227
|
+
* @param card - Card number to mask
|
|
228
|
+
* @param options - Mask options
|
|
229
|
+
* @returns Masked card number
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* maskCreditCard('4111 1111 1111 1111'); // '**** **** **** 1111'
|
|
234
|
+
* maskCreditCard('4111111111111111'); // '************1111'
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function maskCreditCard(card: string, options?: MaskOptions): string;
|
|
238
|
+
/**
|
|
239
|
+
* Mask a generic string
|
|
240
|
+
*
|
|
241
|
+
* @param str - String to mask
|
|
242
|
+
* @param options - Mask options
|
|
243
|
+
* @returns Masked string
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* maskString('password123', { visibleStart: 2, visibleEnd: 2 }); // 'pa*******23'
|
|
248
|
+
* maskString('secret', { visibleEnd: 3 }); // '***ret'
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare function maskString(str: string, options?: MaskOptions): string;
|
|
252
|
+
/**
|
|
253
|
+
* Mask IP address
|
|
254
|
+
*
|
|
255
|
+
* @param ip - IP address to mask
|
|
256
|
+
* @returns Masked IP
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* maskIP('192.168.1.100'); // '192.168.***.***'
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
declare function maskIP(ip: string): string;
|
|
264
|
+
/**
|
|
265
|
+
* Mask name (for privacy)
|
|
266
|
+
*
|
|
267
|
+
* @param name - Name to mask
|
|
268
|
+
* @returns Masked name
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* maskName('John Doe'); // 'J*** D**'
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
declare function maskName(name: string): string;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Password generation options
|
|
279
|
+
*/
|
|
280
|
+
interface PasswordOptions {
|
|
281
|
+
/** Password length (default: 16) */
|
|
282
|
+
length?: number;
|
|
283
|
+
/** Include uppercase letters (default: true) */
|
|
284
|
+
uppercase?: boolean;
|
|
285
|
+
/** Include lowercase letters (default: true) */
|
|
286
|
+
lowercase?: boolean;
|
|
287
|
+
/** Include numbers (default: true) */
|
|
288
|
+
numbers?: boolean;
|
|
289
|
+
/** Include symbols (default: true) */
|
|
290
|
+
symbols?: boolean;
|
|
291
|
+
/** Exclude ambiguous characters like 0, O, l, 1 (default: false) */
|
|
292
|
+
excludeAmbiguous?: boolean;
|
|
293
|
+
/** Custom characters to include */
|
|
294
|
+
customChars?: string;
|
|
295
|
+
/** Minimum number of each character type */
|
|
296
|
+
minOfEachType?: number;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Generate a random password
|
|
300
|
+
*
|
|
301
|
+
* @param options - Password options
|
|
302
|
+
* @returns Generated password
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* generatePassword(); // 'Xy7@mK9#pL2$nR4!'
|
|
307
|
+
* generatePassword({ length: 8, symbols: false }); // 'xY7mK9pL'
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
declare function generatePassword(options?: PasswordOptions): string;
|
|
311
|
+
/**
|
|
312
|
+
* Generate a random string
|
|
313
|
+
*
|
|
314
|
+
* @param length - Length of string
|
|
315
|
+
* @param charset - Character set to use
|
|
316
|
+
* @returns Random string
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* generateRandomString(10); // 'xK7mP9nL2s'
|
|
321
|
+
* generateRandomString(6, 'abc123'); // 'a1b2c3'
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare function generateRandomString(length?: number, charset?: string): string;
|
|
325
|
+
/**
|
|
326
|
+
* Generate a numeric OTP (One-Time Password)
|
|
327
|
+
*
|
|
328
|
+
* @param length - Length of OTP (default: 6)
|
|
329
|
+
* @returns OTP string
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* generateOTP(); // '482957'
|
|
334
|
+
* generateOTP(4); // '7382'
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare function generateOTP(length?: number): string;
|
|
338
|
+
/**
|
|
339
|
+
* Generate a memorable passphrase
|
|
340
|
+
*
|
|
341
|
+
* @param wordCount - Number of words
|
|
342
|
+
* @param separator - Word separator
|
|
343
|
+
* @returns Passphrase
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* generatePassphrase(4); // 'correct-horse-battery-staple'
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
declare function generatePassphrase(wordCount?: number, separator?: string): string;
|
|
351
|
+
/**
|
|
352
|
+
* Generate a hex string
|
|
353
|
+
*
|
|
354
|
+
* @param length - Length in bytes (output will be 2x this)
|
|
355
|
+
* @returns Hex string
|
|
356
|
+
*/
|
|
357
|
+
declare function generateHexString(length?: number): string;
|
|
358
|
+
/**
|
|
359
|
+
* Generate a base64 string
|
|
360
|
+
*
|
|
361
|
+
* @param length - Approximate length
|
|
362
|
+
* @returns Base64 string
|
|
363
|
+
*/
|
|
364
|
+
declare function generateBase64String(length?: number): string;
|
|
365
|
+
/**
|
|
366
|
+
* Generate URL-safe random string
|
|
367
|
+
*
|
|
368
|
+
* @param length - Length of string
|
|
369
|
+
* @returns URL-safe random string
|
|
370
|
+
*/
|
|
371
|
+
declare function generateUrlSafeString(length?: number): string;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Truncation options
|
|
375
|
+
*/
|
|
376
|
+
interface TruncateOptions {
|
|
377
|
+
/** Suffix to append (default: '...') */
|
|
378
|
+
suffix?: string;
|
|
379
|
+
/** Preserve word boundaries (default: true) */
|
|
380
|
+
preserveWords?: boolean;
|
|
381
|
+
/** Where to truncate: 'end', 'middle', 'start' (default: 'end') */
|
|
382
|
+
position?: 'end' | 'middle' | 'start';
|
|
383
|
+
/** Use grapheme-aware truncation for proper emoji handling (default: false) */
|
|
384
|
+
graphemeAware?: boolean;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Truncate a string to specified length
|
|
388
|
+
*
|
|
389
|
+
* @param str - String to truncate
|
|
390
|
+
* @param length - Maximum length (including suffix)
|
|
391
|
+
* @param options - Truncation options
|
|
392
|
+
* @returns Truncated string
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* truncate('Hello World', 8); // 'Hello...'
|
|
397
|
+
* truncate('Hello World', 8, { preserveWords: false }); // 'Hello...'
|
|
398
|
+
* truncate('Hello World', 8, { suffix: '…' }); // 'Hello W…'
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function truncate(str: string, length: number, options?: TruncateOptions): string;
|
|
402
|
+
/**
|
|
403
|
+
* Truncate by word count
|
|
404
|
+
*
|
|
405
|
+
* @param str - String to truncate
|
|
406
|
+
* @param wordCount - Maximum number of words
|
|
407
|
+
* @param suffix - Suffix to append (default: '...')
|
|
408
|
+
* @returns Truncated string
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```typescript
|
|
412
|
+
* truncateWords('The quick brown fox jumps', 3); // 'The quick brown...'
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
declare function truncateWords(str: string, wordCount: number, suffix?: string): string;
|
|
416
|
+
/**
|
|
417
|
+
* Truncate by sentence count
|
|
418
|
+
*
|
|
419
|
+
* @param str - String to truncate
|
|
420
|
+
* @param sentenceCount - Maximum number of sentences
|
|
421
|
+
* @param suffix - Suffix to append (default: '')
|
|
422
|
+
* @returns Truncated string
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```typescript
|
|
426
|
+
* truncateSentences('Hello. World. Test.', 2); // 'Hello. World.'
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
declare function truncateSentences(str: string, sentenceCount: number, suffix?: string): string;
|
|
430
|
+
/**
|
|
431
|
+
* Truncate from middle, keeping file extension
|
|
432
|
+
* Useful for file names
|
|
433
|
+
*
|
|
434
|
+
* @param filename - Filename to truncate
|
|
435
|
+
* @param length - Maximum length
|
|
436
|
+
* @param separator - Separator to use (default: '...')
|
|
437
|
+
* @returns Truncated filename
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* truncateFilename('very_long_filename.pdf', 15); // 'very_l...me.pdf'
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
declare function truncateFilename(filename: string, length: number, separator?: string): string;
|
|
445
|
+
/**
|
|
446
|
+
* Ellipsis a string (alias for truncate with default options)
|
|
447
|
+
*
|
|
448
|
+
* @param str - String to ellipsis
|
|
449
|
+
* @param length - Maximum length
|
|
450
|
+
* @returns Ellipsized string
|
|
451
|
+
*/
|
|
452
|
+
declare function ellipsis(str: string, length: number): string;
|
|
453
|
+
/**
|
|
454
|
+
* Smart truncate for HTML content (strips tags first)
|
|
455
|
+
*
|
|
456
|
+
* @param html - HTML string to truncate
|
|
457
|
+
* @param length - Maximum length
|
|
458
|
+
* @param suffix - Suffix to append
|
|
459
|
+
* @returns Truncated text (no HTML)
|
|
460
|
+
*/
|
|
461
|
+
declare function truncateHtml(html: string, length: number, suffix?: string): string;
|
|
462
|
+
/**
|
|
463
|
+
* Check if string needs truncation
|
|
464
|
+
*
|
|
465
|
+
* @param str - String to check
|
|
466
|
+
* @param length - Maximum length
|
|
467
|
+
* @returns true if string exceeds length
|
|
468
|
+
*/
|
|
469
|
+
declare function needsTruncation(str: string, length: number): boolean;
|
|
470
|
+
|
|
471
|
+
export { type MaskOptions, type PasswordOptions, type SlugOptions, type TruncateOptions, capitalize, ellipsis, generateBase64String, generateHexString, generateOTP, generatePassphrase, generatePassword, generateRandomString, generateUrlSafeString, isValidSlug, maskCreditCard, maskEmail, maskIP, maskName, maskPhone, maskString, needsTruncation, slugify, swapCase, toCamelCase, toConstantCase, toDotCase, toKebabCase, toPascalCase, toSentenceCase, toSlug, toSnakeCase, toTitleCase, transliterate, truncate, truncateFilename, truncateHtml, truncateSentences, truncateWords, uncapitalize, uniqueSlug };
|