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.
Files changed (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +338 -0
  3. package/dist/async.cjs +25 -0
  4. package/dist/async.cjs.map +1 -0
  5. package/dist/async.d.cts +104 -0
  6. package/dist/async.d.ts +104 -0
  7. package/dist/async.js +4 -0
  8. package/dist/async.js.map +1 -0
  9. package/dist/chunk-2ICNRTSN.cjs +346 -0
  10. package/dist/chunk-2ICNRTSN.cjs.map +1 -0
  11. package/dist/chunk-3DPF72DY.js +170 -0
  12. package/dist/chunk-3DPF72DY.js.map +1 -0
  13. package/dist/chunk-4CV4JOE5.js +24 -0
  14. package/dist/chunk-4CV4JOE5.js.map +1 -0
  15. package/dist/chunk-4SLYNSLH.cjs +783 -0
  16. package/dist/chunk-4SLYNSLH.cjs.map +1 -0
  17. package/dist/chunk-5WP7DWCG.js +1285 -0
  18. package/dist/chunk-5WP7DWCG.js.map +1 -0
  19. package/dist/chunk-BMQ6YPKV.js +876 -0
  20. package/dist/chunk-BMQ6YPKV.js.map +1 -0
  21. package/dist/chunk-BZCMWUKS.cjs +479 -0
  22. package/dist/chunk-BZCMWUKS.cjs.map +1 -0
  23. package/dist/chunk-C5R744DY.cjs +173 -0
  24. package/dist/chunk-C5R744DY.cjs.map +1 -0
  25. package/dist/chunk-C75J62CV.cjs +913 -0
  26. package/dist/chunk-C75J62CV.cjs.map +1 -0
  27. package/dist/chunk-CZLDE2OZ.cjs +28 -0
  28. package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
  29. package/dist/chunk-DSMB6AF6.cjs +193 -0
  30. package/dist/chunk-DSMB6AF6.cjs.map +1 -0
  31. package/dist/chunk-ETWGPOPY.js +426 -0
  32. package/dist/chunk-ETWGPOPY.js.map +1 -0
  33. package/dist/chunk-FQBPVN63.cjs +403 -0
  34. package/dist/chunk-FQBPVN63.cjs.map +1 -0
  35. package/dist/chunk-G4GYQGTW.cjs +178 -0
  36. package/dist/chunk-G4GYQGTW.cjs.map +1 -0
  37. package/dist/chunk-GFDMZDMI.js +486 -0
  38. package/dist/chunk-GFDMZDMI.js.map +1 -0
  39. package/dist/chunk-HOTOYIPB.js +171 -0
  40. package/dist/chunk-HOTOYIPB.js.map +1 -0
  41. package/dist/chunk-HYADH4ZX.js +176 -0
  42. package/dist/chunk-HYADH4ZX.js.map +1 -0
  43. package/dist/chunk-JBN7C5WE.js +255 -0
  44. package/dist/chunk-JBN7C5WE.js.map +1 -0
  45. package/dist/chunk-JNCTPFTD.cjs +25 -0
  46. package/dist/chunk-JNCTPFTD.cjs.map +1 -0
  47. package/dist/chunk-N3BH3BV7.js +21 -0
  48. package/dist/chunk-N3BH3BV7.js.map +1 -0
  49. package/dist/chunk-NFPGAVRQ.js +749 -0
  50. package/dist/chunk-NFPGAVRQ.js.map +1 -0
  51. package/dist/chunk-OFFRGRBN.cjs +1332 -0
  52. package/dist/chunk-OFFRGRBN.cjs.map +1 -0
  53. package/dist/chunk-OZLKYIZL.cjs +490 -0
  54. package/dist/chunk-OZLKYIZL.cjs.map +1 -0
  55. package/dist/chunk-P3NUK46X.js +145 -0
  56. package/dist/chunk-P3NUK46X.js.map +1 -0
  57. package/dist/chunk-P7P2B7ZI.cjs +429 -0
  58. package/dist/chunk-P7P2B7ZI.cjs.map +1 -0
  59. package/dist/chunk-PB6SKSJN.cjs +150 -0
  60. package/dist/chunk-PB6SKSJN.cjs.map +1 -0
  61. package/dist/chunk-R3IXCJR7.js +378 -0
  62. package/dist/chunk-R3IXCJR7.js.map +1 -0
  63. package/dist/chunk-SD6P3WEJ.js +324 -0
  64. package/dist/chunk-SD6P3WEJ.js.map +1 -0
  65. package/dist/chunk-YSCHP26P.js +451 -0
  66. package/dist/chunk-YSCHP26P.js.map +1 -0
  67. package/dist/chunk-ZLMPRPCY.cjs +274 -0
  68. package/dist/chunk-ZLMPRPCY.cjs.map +1 -0
  69. package/dist/common-CBDYNJeh.d.cts +48 -0
  70. package/dist/common-CBDYNJeh.d.ts +48 -0
  71. package/dist/constants.cjs +42 -0
  72. package/dist/constants.cjs.map +1 -0
  73. package/dist/constants.d.cts +60 -0
  74. package/dist/constants.d.ts +60 -0
  75. package/dist/constants.js +5 -0
  76. package/dist/constants.js.map +1 -0
  77. package/dist/country/index.cjs +154 -0
  78. package/dist/country/index.cjs.map +1 -0
  79. package/dist/country/index.d.cts +1 -0
  80. package/dist/country/index.d.ts +1 -0
  81. package/dist/country/index.js +5 -0
  82. package/dist/country/index.js.map +1 -0
  83. package/dist/date/index.cjs +117 -0
  84. package/dist/date/index.cjs.map +1 -0
  85. package/dist/date/index.d.cts +283 -0
  86. package/dist/date/index.d.ts +283 -0
  87. package/dist/date/index.js +4 -0
  88. package/dist/date/index.js.map +1 -0
  89. package/dist/environment/index.cjs +73 -0
  90. package/dist/environment/index.cjs.map +1 -0
  91. package/dist/environment/index.d.cts +127 -0
  92. package/dist/environment/index.d.ts +127 -0
  93. package/dist/environment/index.js +4 -0
  94. package/dist/environment/index.js.map +1 -0
  95. package/dist/form/index.cjs +81 -0
  96. package/dist/form/index.cjs.map +1 -0
  97. package/dist/form/index.d.cts +227 -0
  98. package/dist/form/index.d.ts +227 -0
  99. package/dist/form/index.js +4 -0
  100. package/dist/form/index.js.map +1 -0
  101. package/dist/i18n.cjs +37 -0
  102. package/dist/i18n.cjs.map +1 -0
  103. package/dist/i18n.d.cts +102 -0
  104. package/dist/i18n.d.ts +102 -0
  105. package/dist/i18n.js +4 -0
  106. package/dist/i18n.js.map +1 -0
  107. package/dist/index-BXBmBHyL.d.ts +718 -0
  108. package/dist/index-BYsUCP3u.d.cts +718 -0
  109. package/dist/index-Cl26FrAZ.d.cts +362 -0
  110. package/dist/index-Cl26FrAZ.d.ts +362 -0
  111. package/dist/index.cjs +1265 -0
  112. package/dist/index.cjs.map +1 -0
  113. package/dist/index.d.cts +205 -0
  114. package/dist/index.d.ts +205 -0
  115. package/dist/index.js +277 -0
  116. package/dist/index.js.map +1 -0
  117. package/dist/schema.cjs +13 -0
  118. package/dist/schema.cjs.map +1 -0
  119. package/dist/schema.d.cts +84 -0
  120. package/dist/schema.d.ts +84 -0
  121. package/dist/schema.js +4 -0
  122. package/dist/schema.js.map +1 -0
  123. package/dist/security/index.cjs +94 -0
  124. package/dist/security/index.cjs.map +1 -0
  125. package/dist/security/index.d.cts +216 -0
  126. package/dist/security/index.d.ts +216 -0
  127. package/dist/security/index.js +5 -0
  128. package/dist/security/index.js.map +1 -0
  129. package/dist/string/index.cjs +153 -0
  130. package/dist/string/index.cjs.map +1 -0
  131. package/dist/string/index.d.cts +471 -0
  132. package/dist/string/index.d.ts +471 -0
  133. package/dist/string/index.js +4 -0
  134. package/dist/string/index.js.map +1 -0
  135. package/dist/transform/index.cjs +105 -0
  136. package/dist/transform/index.cjs.map +1 -0
  137. package/dist/transform/index.d.cts +271 -0
  138. package/dist/transform/index.d.ts +271 -0
  139. package/dist/transform/index.js +4 -0
  140. package/dist/transform/index.js.map +1 -0
  141. package/dist/validators/index.cjs +195 -0
  142. package/dist/validators/index.cjs.map +1 -0
  143. package/dist/validators/index.d.cts +2 -0
  144. package/dist/validators/index.d.ts +2 -0
  145. package/dist/validators/index.js +6 -0
  146. package/dist/validators/index.js.map +1 -0
  147. package/package.json +229 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Utilitify
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,338 @@
1
+ # Utilitify
2
+
3
+ > Comprehensive validation & utility SDK for JavaScript/TypeScript applications
4
+
5
+ [![npm version](https://img.shields.io/npm/v/utilitify-core.svg)](https://www.npmjs.com/package/utilitify-core)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue)](https://www.typescriptlang.org/)
8
+
9
+ ## Features
10
+
11
+ - **Security** - Password strength, hashing, secure tokens
12
+ - **Validators** - Email, phone, username, URL, credit card, IBAN, VAT, IP
13
+ - **Country Data** - Countries, timezones, currencies, dialing codes
14
+ - **String Utils** - Case conversion, slugs, masking, truncation
15
+ - **Date Utils** - Age calculation, formatting, validation
16
+ - **Transform** - Deep merge, flatten, sanitization
17
+ - **Form Validation** - Field validators, conditional rules
18
+ - **Tree-Shakable** - Import only what you need
19
+ - **Zero Dependencies** - Lightweight core
20
+ - **TypeScript Native** - Full type safety
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install utilitify-core
26
+ ```
27
+
28
+ Optional (for bcrypt hashing):
29
+ ```bash
30
+ npm install bcryptjs
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ```typescript
36
+ import { validateEmail } from 'utilitify-core/validators';
37
+ import { checkPasswordStrength } from 'utilitify-core/security';
38
+ import { slugify } from 'utilitify-core/string';
39
+
40
+ // Email validation
41
+ const email = validateEmail('user@example.com');
42
+ console.log(email.isValid); // true
43
+
44
+ // Password strength
45
+ const password = checkPasswordStrength('MyP@ssw0rd123');
46
+ console.log(password.score); // 0-4
47
+ console.log(password.crackTime); // "Centuries"
48
+
49
+ // String utilities
50
+ const slug = slugify('Hello World!'); // "hello-world"
51
+ ```
52
+
53
+ ## API Reference
54
+
55
+ ### Validators (`utilitify-core/validators`)
56
+
57
+ ```typescript
58
+ // Email
59
+ validateEmail(email, options?)
60
+ isValidEmail(email)
61
+ isDisposableEmail(email)
62
+ normalizeEmail(email)
63
+
64
+ // Phone
65
+ validatePhone(phone, country?)
66
+ formatPhone(phone, country?)
67
+
68
+ // Username
69
+ validateUsername(username, options?)
70
+ suggestUsernames(base)
71
+
72
+ // URL
73
+ validateUrl(url, options?)
74
+ isDangerousUrl(url)
75
+
76
+ // Credit Card
77
+ validateCreditCard(number)
78
+ detectCardType(number)
79
+
80
+ // Financial
81
+ validateIBAN(iban)
82
+ validateVAT(vat, country)
83
+
84
+ // IP Address
85
+ validateIp(ip, options?)
86
+ isPrivateIp(ip)
87
+ ```
88
+
89
+ ### Security (`utilitify-core/security`)
90
+
91
+ ```typescript
92
+ // Password
93
+ checkPasswordStrength(password, options?)
94
+ isStrongPassword(password, minScore?)
95
+ getPasswordFeedback(password)
96
+
97
+ // Hashing
98
+ hashSHA256(data)
99
+ hashSHA512(data)
100
+ hashBcrypt(password, rounds?)
101
+ verifyBcrypt(password, hash)
102
+ hmacSHA256(data, key)
103
+
104
+ // Tokens
105
+ generateUUID()
106
+ generateUUIDv7()
107
+ generateToken(length)
108
+ generateSecureToken(length)
109
+ generateNanoId(length?)
110
+ ```
111
+
112
+ ### String (`utilitify-core/string`)
113
+
114
+ ```typescript
115
+ // Case conversion
116
+ toCamelCase(str)
117
+ toPascalCase(str)
118
+ toSnakeCase(str)
119
+ toKebabCase(str)
120
+ toTitleCase(str)
121
+
122
+ // Slugs
123
+ slugify(str, options?)
124
+ uniqueSlug(str, existing)
125
+
126
+ // Masking
127
+ maskEmail(email)
128
+ maskPhone(phone)
129
+ maskCreditCard(number)
130
+
131
+ // Random
132
+ generatePassword(options?)
133
+ generateOTP(length?)
134
+
135
+ // Truncation
136
+ truncate(str, length, options?)
137
+ truncateWords(str, words)
138
+ ```
139
+
140
+ ### Country (`utilitify-core/country`)
141
+
142
+ ```typescript
143
+ // Country lookup
144
+ getCountry(code)
145
+ getAllCountries()
146
+ searchCountries(query)
147
+
148
+ // Timezone
149
+ getTimezonesByCountry(country)
150
+ getCurrentTimeInCountry(country)
151
+
152
+ // Currency
153
+ getCurrencyByCountry(country)
154
+ formatCurrency(amount, currency)
155
+
156
+ // Flags & Dialing
157
+ getFlagEmoji(country)
158
+ getDialingCode(country)
159
+ ```
160
+
161
+ ### Date (`utilitify-core/date`)
162
+
163
+ ```typescript
164
+ // Age
165
+ calculateAge(birthDate)
166
+ isAdult(birthDate, minAge?)
167
+ getAgeBracket(age)
168
+
169
+ // Formatting
170
+ formatRelativeTime(date)
171
+ formatDate(date, format)
172
+
173
+ // Validation
174
+ isValidDate(date)
175
+ isInPast(date)
176
+ isWeekend(date)
177
+
178
+ // Time difference
179
+ getTimeDiff(date1, date2)
180
+ addTime(date, amount, unit)
181
+ ```
182
+
183
+ ### Transform (`utilitify-core/transform`)
184
+
185
+ ```typescript
186
+ // Objects
187
+ deepMerge(obj1, obj2)
188
+ cloneDeep(obj)
189
+ flattenObject(obj)
190
+ pick(obj, keys)
191
+ omit(obj, keys)
192
+
193
+ // Sanitization
194
+ sanitizeString(str)
195
+ stripHtml(html)
196
+ escapeHtml(str)
197
+ ```
198
+
199
+ ### Form (`utilitify-core/form`)
200
+
201
+ ```typescript
202
+ // Validators
203
+ required(value)
204
+ minLength(value, min)
205
+ maxLength(value, max)
206
+ matchesPattern(value, pattern)
207
+
208
+ // Conditional
209
+ requiredIf(value, condition)
210
+ mustMatch(value, other)
211
+ ```
212
+
213
+ ### Schema (`utilitify-core/schema`)
214
+
215
+ ```typescript
216
+ import { z } from 'utilitify-core/schema';
217
+
218
+ const schema = z.object({
219
+ email: z.string().email(),
220
+ age: z.number().min(18).max(120),
221
+ name: z.string().min(2)
222
+ });
223
+
224
+ const result = schema.safeParse(data);
225
+ if (result.success) {
226
+ console.log(result.data);
227
+ }
228
+ ```
229
+
230
+ ## Usage Examples
231
+
232
+ ### Form Validation
233
+
234
+ ```typescript
235
+ import { validateEmail, validatePhone, checkPasswordStrength } from 'utilitify-core';
236
+
237
+ function validateForm(data) {
238
+ const errors = {};
239
+
240
+ const email = validateEmail(data.email, { checkDisposable: true });
241
+ if (!email.isValid) {
242
+ errors.email = email.errors[0].message;
243
+ }
244
+
245
+ const phone = validatePhone(data.phone, 'US');
246
+ if (!phone.isValid) {
247
+ errors.phone = 'Invalid phone number';
248
+ }
249
+
250
+ const password = checkPasswordStrength(data.password);
251
+ if (password.score < 3) {
252
+ errors.password = password.suggestions.join(', ');
253
+ }
254
+
255
+ return { isValid: Object.keys(errors).length === 0, errors };
256
+ }
257
+ ```
258
+
259
+ ### Secure Token Generation
260
+
261
+ ```typescript
262
+ import { generateUUID, generateSecureToken } from 'utilitify-core/security';
263
+
264
+ const userId = generateUUID();
265
+ const apiKey = generateSecureToken(32);
266
+ const sessionToken = generateSecureToken(64);
267
+ ```
268
+
269
+ ### International Phone Formatting
270
+
271
+ ```typescript
272
+ import { formatPhone, getDialingCode } from 'utilitify-core/country';
273
+
274
+ const formatted = formatPhone('2025551234', 'US');
275
+ // "+1 (202) 555-1234"
276
+
277
+ const code = getDialingCode('GB');
278
+ // "+44"
279
+ ```
280
+
281
+ ### String Manipulation
282
+
283
+ ```typescript
284
+ import { slugify, maskEmail, truncate } from 'utilitify-core/string';
285
+
286
+ slugify('Hello World! 123'); // "hello-world-123"
287
+ maskEmail('user@example.com'); // "u***@example.com"
288
+ truncate('Long text...', 10); // "Long te..."
289
+ ```
290
+
291
+ ## Tree-Shaking
292
+
293
+ Import from specific paths to reduce bundle size:
294
+
295
+ ```typescript
296
+ // Recommended - Only imports what you need
297
+ import { validateEmail } from 'utilitify-core/validators';
298
+ import { generateUUID } from 'utilitify-core/security';
299
+
300
+ // Avoid - Imports entire package
301
+ import { validateEmail, generateUUID } from 'utilitify-core';
302
+ ```
303
+
304
+ ## TypeScript Support
305
+
306
+ Full TypeScript support with type definitions:
307
+
308
+ ```typescript
309
+ import type {
310
+ EmailValidationResult,
311
+ PasswordStrength,
312
+ Country
313
+ } from 'utilitify-core';
314
+
315
+ const result: EmailValidationResult = validateEmail('test@example.com');
316
+ ```
317
+
318
+ ## Browser & Node.js Support
319
+
320
+ - **Node.js**: >= 18.0.0
321
+ - **Browsers**: All modern browsers (ES2022+)
322
+ - **TypeScript**: >= 5.0
323
+
324
+ ## Bundle Size
325
+
326
+ - Core validators: ~5 KB (gzipped)
327
+ - Full package: ~10 KB (gzipped)
328
+ - Tree-shakable modules
329
+
330
+ ## License
331
+
332
+ MIT © [Fahad](https://github.com/muhammadfahaddev)
333
+
334
+ ## Links
335
+
336
+ - [GitHub](https://github.com/muhammadfahaddev/utilitify-core)
337
+ - [Issues](https://github.com/muhammadfahaddev/utilitify-core/issues)
338
+ - [npm](https://www.npmjs.com/package/utilitify-core)
package/dist/async.cjs ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var chunkPB6SKSJN_cjs = require('./chunk-PB6SKSJN.cjs');
4
+ require('./chunk-CZLDE2OZ.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "composeValidators", {
9
+ enumerable: true,
10
+ get: function () { return chunkPB6SKSJN_cjs.composeValidators; }
11
+ });
12
+ Object.defineProperty(exports, "createDebouncedValidator", {
13
+ enumerable: true,
14
+ get: function () { return chunkPB6SKSJN_cjs.createDebouncedValidator; }
15
+ });
16
+ Object.defineProperty(exports, "validateAllAsync", {
17
+ enumerable: true,
18
+ get: function () { return chunkPB6SKSJN_cjs.validateAllAsync; }
19
+ });
20
+ Object.defineProperty(exports, "validateAsync", {
21
+ enumerable: true,
22
+ get: function () { return chunkPB6SKSJN_cjs.validateAsync; }
23
+ });
24
+ //# sourceMappingURL=async.cjs.map
25
+ //# sourceMappingURL=async.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"async.cjs"}
@@ -0,0 +1,104 @@
1
+ import { I as IValidationError } from './common-CBDYNJeh.cjs';
2
+
3
+ /**
4
+ * Async validation module for Utilitify
5
+ * Provides async validators for scenarios requiring external API calls
6
+ *
7
+ * @packageDocumentation
8
+ * @since 1.0.0
9
+ */
10
+
11
+ /**
12
+ * Async validation result
13
+ */
14
+ interface AsyncValidationResult {
15
+ isValid: boolean;
16
+ errors: IValidationError[];
17
+ /** Time taken for validation in milliseconds */
18
+ duration?: number;
19
+ }
20
+ /**
21
+ * Async validator function type
22
+ */
23
+ type AsyncValidator<T> = (value: T) => Promise<AsyncValidationResult>;
24
+ /**
25
+ * Async validation options
26
+ */
27
+ interface AsyncValidationOptions {
28
+ /** Timeout in milliseconds (default: 5000) */
29
+ timeout?: number;
30
+ /** Whether to abort on first error (default: false) */
31
+ abortEarly?: boolean;
32
+ /** Custom error messages */
33
+ messages?: Record<string, string>;
34
+ }
35
+ /**
36
+ * Run async validation with timeout
37
+ *
38
+ * @param value - Value to validate
39
+ * @param validator - Async validator function
40
+ * @param options - Validation options
41
+ * @returns Validation result
42
+ * @since 1.0.0
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const result = await validateAsync(email, async (email) => {
47
+ * const exists = await checkEmailExists(email);
48
+ * return {
49
+ * isValid: !exists,
50
+ * errors: exists ? [{ field: 'email', code: 'EXISTS', message: 'Email already registered' }] : []
51
+ * };
52
+ * });
53
+ * ```
54
+ */
55
+ declare function validateAsync<T>(value: T, validator: AsyncValidator<T>, options?: AsyncValidationOptions): Promise<AsyncValidationResult>;
56
+ /**
57
+ * Run multiple async validators in parallel
58
+ *
59
+ * @param validators - Array of validator configs
60
+ * @param options - Validation options
61
+ * @returns Combined validation result
62
+ * @since 1.0.0
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const result = await validateAllAsync([
67
+ * { value: email, validator: emailExistsCheck, field: 'email' },
68
+ * { value: username, validator: usernameAvailableCheck, field: 'username' }
69
+ * ]);
70
+ * ```
71
+ */
72
+ declare function validateAllAsync<T>(validators: Array<{
73
+ value: T;
74
+ validator: AsyncValidator<T>;
75
+ field: string;
76
+ }>, options?: AsyncValidationOptions): Promise<AsyncValidationResult>;
77
+ /**
78
+ * Create a debounced async validator
79
+ * Useful for real-time validation in forms
80
+ *
81
+ * @param validator - Async validator function
82
+ * @param delay - Debounce delay in milliseconds
83
+ * @returns Debounced validator
84
+ * @since 1.0.0
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const debouncedEmailCheck = createDebouncedValidator(
89
+ * async (email) => ({ isValid: !(await checkExists(email)), errors: [] }),
90
+ * 300
91
+ * );
92
+ * ```
93
+ */
94
+ declare function createDebouncedValidator<T>(validator: AsyncValidator<T>, delay?: number): (value: T) => Promise<AsyncValidationResult>;
95
+ /**
96
+ * Compose multiple validators into one
97
+ *
98
+ * @param validators - Validators to compose
99
+ * @returns Composed validator
100
+ * @since 1.0.0
101
+ */
102
+ declare function composeValidators<T>(...validators: AsyncValidator<T>[]): AsyncValidator<T>;
103
+
104
+ export { type AsyncValidationOptions, type AsyncValidationResult, type AsyncValidator, composeValidators, createDebouncedValidator, validateAllAsync, validateAsync };
@@ -0,0 +1,104 @@
1
+ import { I as IValidationError } from './common-CBDYNJeh.js';
2
+
3
+ /**
4
+ * Async validation module for Utilitify
5
+ * Provides async validators for scenarios requiring external API calls
6
+ *
7
+ * @packageDocumentation
8
+ * @since 1.0.0
9
+ */
10
+
11
+ /**
12
+ * Async validation result
13
+ */
14
+ interface AsyncValidationResult {
15
+ isValid: boolean;
16
+ errors: IValidationError[];
17
+ /** Time taken for validation in milliseconds */
18
+ duration?: number;
19
+ }
20
+ /**
21
+ * Async validator function type
22
+ */
23
+ type AsyncValidator<T> = (value: T) => Promise<AsyncValidationResult>;
24
+ /**
25
+ * Async validation options
26
+ */
27
+ interface AsyncValidationOptions {
28
+ /** Timeout in milliseconds (default: 5000) */
29
+ timeout?: number;
30
+ /** Whether to abort on first error (default: false) */
31
+ abortEarly?: boolean;
32
+ /** Custom error messages */
33
+ messages?: Record<string, string>;
34
+ }
35
+ /**
36
+ * Run async validation with timeout
37
+ *
38
+ * @param value - Value to validate
39
+ * @param validator - Async validator function
40
+ * @param options - Validation options
41
+ * @returns Validation result
42
+ * @since 1.0.0
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const result = await validateAsync(email, async (email) => {
47
+ * const exists = await checkEmailExists(email);
48
+ * return {
49
+ * isValid: !exists,
50
+ * errors: exists ? [{ field: 'email', code: 'EXISTS', message: 'Email already registered' }] : []
51
+ * };
52
+ * });
53
+ * ```
54
+ */
55
+ declare function validateAsync<T>(value: T, validator: AsyncValidator<T>, options?: AsyncValidationOptions): Promise<AsyncValidationResult>;
56
+ /**
57
+ * Run multiple async validators in parallel
58
+ *
59
+ * @param validators - Array of validator configs
60
+ * @param options - Validation options
61
+ * @returns Combined validation result
62
+ * @since 1.0.0
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const result = await validateAllAsync([
67
+ * { value: email, validator: emailExistsCheck, field: 'email' },
68
+ * { value: username, validator: usernameAvailableCheck, field: 'username' }
69
+ * ]);
70
+ * ```
71
+ */
72
+ declare function validateAllAsync<T>(validators: Array<{
73
+ value: T;
74
+ validator: AsyncValidator<T>;
75
+ field: string;
76
+ }>, options?: AsyncValidationOptions): Promise<AsyncValidationResult>;
77
+ /**
78
+ * Create a debounced async validator
79
+ * Useful for real-time validation in forms
80
+ *
81
+ * @param validator - Async validator function
82
+ * @param delay - Debounce delay in milliseconds
83
+ * @returns Debounced validator
84
+ * @since 1.0.0
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const debouncedEmailCheck = createDebouncedValidator(
89
+ * async (email) => ({ isValid: !(await checkExists(email)), errors: [] }),
90
+ * 300
91
+ * );
92
+ * ```
93
+ */
94
+ declare function createDebouncedValidator<T>(validator: AsyncValidator<T>, delay?: number): (value: T) => Promise<AsyncValidationResult>;
95
+ /**
96
+ * Compose multiple validators into one
97
+ *
98
+ * @param validators - Validators to compose
99
+ * @returns Composed validator
100
+ * @since 1.0.0
101
+ */
102
+ declare function composeValidators<T>(...validators: AsyncValidator<T>[]): AsyncValidator<T>;
103
+
104
+ export { type AsyncValidationOptions, type AsyncValidationResult, type AsyncValidator, composeValidators, createDebouncedValidator, validateAllAsync, validateAsync };
package/dist/async.js ADDED
@@ -0,0 +1,4 @@
1
+ export { composeValidators, createDebouncedValidator, validateAllAsync, validateAsync } from './chunk-P3NUK46X.js';
2
+ import './chunk-4CV4JOE5.js';
3
+ //# sourceMappingURL=async.js.map
4
+ //# sourceMappingURL=async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"async.js"}