@hy_ong/zod-kit 0.0.5 → 0.1.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 (46) hide show
  1. package/.claude/settings.local.json +9 -1
  2. package/README.md +465 -97
  3. package/dist/index.cjs +1690 -179
  4. package/dist/index.d.cts +2791 -28
  5. package/dist/index.d.ts +2791 -28
  6. package/dist/index.js +1672 -178
  7. package/package.json +2 -1
  8. package/src/i18n/locales/en.json +62 -0
  9. package/src/i18n/locales/zh-TW.json +62 -0
  10. package/src/index.ts +4 -0
  11. package/src/validators/common/boolean.ts +101 -4
  12. package/src/validators/common/date.ts +141 -6
  13. package/src/validators/common/datetime.ts +680 -0
  14. package/src/validators/common/email.ts +120 -4
  15. package/src/validators/common/file.ts +391 -0
  16. package/src/validators/common/id.ts +230 -18
  17. package/src/validators/common/number.ts +132 -4
  18. package/src/validators/common/password.ts +187 -8
  19. package/src/validators/common/text.ts +130 -6
  20. package/src/validators/common/time.ts +607 -0
  21. package/src/validators/common/url.ts +153 -6
  22. package/src/validators/taiwan/business-id.ts +138 -9
  23. package/src/validators/taiwan/fax.ts +164 -10
  24. package/src/validators/taiwan/mobile.ts +151 -10
  25. package/src/validators/taiwan/national-id.ts +233 -17
  26. package/src/validators/taiwan/postal-code.ts +1048 -0
  27. package/src/validators/taiwan/tel.ts +167 -10
  28. package/tests/common/boolean.test.ts +38 -38
  29. package/tests/common/date.test.ts +65 -65
  30. package/tests/common/datetime.test.ts +675 -0
  31. package/tests/common/email.test.ts +24 -28
  32. package/tests/common/file.test.ts +475 -0
  33. package/tests/common/id.test.ts +80 -113
  34. package/tests/common/number.test.ts +24 -25
  35. package/tests/common/password.test.ts +28 -35
  36. package/tests/common/text.test.ts +36 -37
  37. package/tests/common/time.test.ts +510 -0
  38. package/tests/common/url.test.ts +67 -67
  39. package/tests/taiwan/business-id.test.ts +22 -22
  40. package/tests/taiwan/fax.test.ts +33 -42
  41. package/tests/taiwan/mobile.test.ts +32 -41
  42. package/tests/taiwan/national-id.test.ts +31 -31
  43. package/tests/taiwan/postal-code.test.ts +751 -0
  44. package/tests/taiwan/tel.test.ts +33 -42
  45. package/debug.js +0 -21
  46. package/debug.ts +0 -16
package/dist/index.d.ts CHANGED
@@ -1,17 +1,50 @@
1
- import { ZodBoolean, ZodNullable, ZodString, ZodNumber } from 'zod';
1
+ import { ZodBoolean, ZodNullable, ZodString, ZodType, ZodNumber } from 'zod';
2
+ import dayjs from 'dayjs';
2
3
 
3
4
  type Locale = "zh-TW" | "en";
4
5
  declare const setLocale: (locale: Locale) => void;
5
6
  declare const getLocale: () => Locale;
6
7
 
8
+ /**
9
+ * @fileoverview Boolean validator for Zod Kit
10
+ *
11
+ * Provides flexible boolean validation with support for various truthy/falsy values,
12
+ * strict mode validation, and comprehensive transformation options.
13
+ *
14
+ * @author Ong Hoe Yuan
15
+ * @version 0.0.5
16
+ */
17
+
18
+ /**
19
+ * Type definition for boolean validation error messages
20
+ *
21
+ * @interface BooleanMessages
22
+ * @property {string} [required] - Message when field is required but empty
23
+ * @property {string} [shouldBeTrue] - Message when value should be true but isn't
24
+ * @property {string} [shouldBeFalse] - Message when value should be false but isn't
25
+ * @property {string} [invalid] - Message when value is not a valid boolean
26
+ */
7
27
  type BooleanMessages = {
8
28
  required?: string;
9
29
  shouldBeTrue?: string;
10
30
  shouldBeFalse?: string;
11
31
  invalid?: string;
12
32
  };
33
+ /**
34
+ * Configuration options for boolean validation
35
+ *
36
+ * @template IsRequired - Whether the field is required (affects return type)
37
+ *
38
+ * @interface BooleanOptions
39
+ * @property {boolean | null} [defaultValue] - Default value when input is empty
40
+ * @property {boolean} [shouldBe] - Specific boolean value that must be matched
41
+ * @property {unknown[]} [truthyValues] - Array of values that should be treated as true
42
+ * @property {unknown[]} [falsyValues] - Array of values that should be treated as false
43
+ * @property {boolean} [strict=false] - If true, only accepts actual boolean values
44
+ * @property {Function} [transform] - Custom transformation function for boolean values
45
+ * @property {Record<Locale, BooleanMessages>} [i18n] - Custom error messages for different locales
46
+ */
13
47
  type BooleanOptions<IsRequired extends boolean = true> = {
14
- required?: IsRequired;
15
48
  defaultValue?: IsRequired extends true ? boolean : boolean | null;
16
49
  shouldBe?: boolean;
17
50
  truthyValues?: unknown[];
@@ -20,9 +53,103 @@ type BooleanOptions<IsRequired extends boolean = true> = {
20
53
  transform?: (value: boolean) => boolean;
21
54
  i18n?: Record<Locale, BooleanMessages>;
22
55
  };
56
+ /**
57
+ * Type alias for boolean validation schema based on required flag
58
+ *
59
+ * @template IsRequired - Whether the field is required
60
+ * @typedef BooleanSchema
61
+ * @description Returns ZodBoolean if required, ZodNullable<ZodBoolean> if optional
62
+ */
23
63
  type BooleanSchema<IsRequired extends boolean> = IsRequired extends true ? ZodBoolean : ZodNullable<ZodBoolean>;
24
- declare function boolean<IsRequired extends boolean = true>(options?: BooleanOptions<IsRequired>): BooleanSchema<IsRequired>;
64
+ /**
65
+ * Creates a Zod schema for boolean validation with flexible value interpretation
66
+ *
67
+ * @template IsRequired - Whether the field is required (affects return type)
68
+ * @param {IsRequired} [required=false] - Whether the field is required
69
+ * @param {Omit<BooleanOptions<IsRequired>, 'required'>} [options] - Configuration options for boolean validation
70
+ * @returns {BooleanSchema<IsRequired>} Zod schema for boolean validation
71
+ *
72
+ * @description
73
+ * Creates a flexible boolean validator that can interpret various values as true/false,
74
+ * supports strict mode for type safety, and provides comprehensive transformation options.
75
+ *
76
+ * Features:
77
+ * - Flexible truthy/falsy value interpretation
78
+ * - Strict mode for type safety
79
+ * - Custom transformation functions
80
+ * - Specific boolean value requirements
81
+ * - Comprehensive internationalization
82
+ * - Default value support
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * // Basic boolean validation (optional by default)
87
+ * const basicSchema = boolean()
88
+ * basicSchema.parse(true) // ✓ Valid
89
+ * basicSchema.parse("true") // ✓ Valid (converted to true)
90
+ * basicSchema.parse(null) // ✓ Valid (optional)
91
+ *
92
+ * // Required boolean
93
+ * const requiredSchema = boolean(true)
94
+ * requiredSchema.parse(true) // ✓ Valid
95
+ * requiredSchema.parse(null) // ✗ Invalid (required)
96
+ *
97
+ * // Strict mode (only actual booleans)
98
+ * const strictSchema = boolean(false, { strict: true })
99
+ * strictSchema.parse(true) // ✓ Valid
100
+ * strictSchema.parse("true") // ✗ Invalid
101
+ *
102
+ * // Must be true
103
+ * const mustBeTrueSchema = boolean(true, { shouldBe: true })
104
+ * mustBeTrueSchema.parse(true) // ✓ Valid
105
+ * mustBeTrueSchema.parse(false) // ✗ Invalid
106
+ *
107
+ * // Custom truthy/falsy values
108
+ * const customSchema = boolean(false, {
109
+ * truthyValues: ["yes", "on", 1],
110
+ * falsyValues: ["no", "off", 0]
111
+ * })
112
+ * customSchema.parse("yes") // ✓ Valid (converted to true)
113
+ *
114
+ * // Optional with default
115
+ * const optionalSchema = boolean(false, { defaultValue: false })
116
+ * ```
117
+ *
118
+ * @throws {z.ZodError} When validation fails with specific error messages
119
+ * @see {@link BooleanOptions} for all available configuration options
120
+ */
121
+ declare function boolean<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<BooleanOptions<IsRequired>, 'required'>): BooleanSchema<IsRequired>;
122
+
123
+ /**
124
+ * @fileoverview Date validator for Zod Kit
125
+ *
126
+ * Provides comprehensive date validation with format support, range validation,
127
+ * temporal constraints, and weekday/weekend filtering using dayjs library.
128
+ *
129
+ * @author Ong Hoe Yuan
130
+ * @version 0.0.5
131
+ */
25
132
 
133
+ /**
134
+ * Type definition for date validation error messages
135
+ *
136
+ * @interface DateMessages
137
+ * @property {string} [required] - Message when field is required but empty
138
+ * @property {string} [invalid] - Message when date is invalid
139
+ * @property {string} [format] - Message when date doesn't match expected format
140
+ * @property {string} [min] - Message when date is before minimum allowed
141
+ * @property {string} [max] - Message when date is after maximum allowed
142
+ * @property {string} [includes] - Message when date string doesn't contain required text
143
+ * @property {string} [excludes] - Message when date string contains forbidden text
144
+ * @property {string} [past] - Message when date must be in the past
145
+ * @property {string} [future] - Message when date must be in the future
146
+ * @property {string} [today] - Message when date must be today
147
+ * @property {string} [notToday] - Message when date must not be today
148
+ * @property {string} [weekday] - Message when date must be a weekday
149
+ * @property {string} [notWeekday] - Message when date must not be a weekday
150
+ * @property {string} [weekend] - Message when date must be a weekend
151
+ * @property {string} [notWeekend] - Message when date must not be a weekend
152
+ */
26
153
  type DateMessages = {
27
154
  required?: string;
28
155
  invalid?: string;
@@ -40,8 +167,29 @@ type DateMessages = {
40
167
  weekend?: string;
41
168
  notWeekend?: string;
42
169
  };
170
+ /**
171
+ * Configuration options for date validation
172
+ *
173
+ * @template IsRequired - Whether the field is required (affects return type)
174
+ *
175
+ * @interface DateOptions
176
+ * @property {IsRequired} [required=true] - Whether the field is required
177
+ * @property {string} [min] - Minimum allowed date (in same format as specified)
178
+ * @property {string} [max] - Maximum allowed date (in same format as specified)
179
+ * @property {string} [format="YYYY-MM-DD"] - Date format for parsing and validation
180
+ * @property {string} [includes] - String that must be included in the date
181
+ * @property {string | string[]} [excludes] - String(s) that must not be included
182
+ * @property {boolean} [mustBePast] - Whether date must be in the past
183
+ * @property {boolean} [mustBeFuture] - Whether date must be in the future
184
+ * @property {boolean} [mustBeToday] - Whether date must be today
185
+ * @property {boolean} [mustNotBeToday] - Whether date must not be today
186
+ * @property {boolean} [weekdaysOnly] - Whether date must be a weekday (Monday-Friday)
187
+ * @property {boolean} [weekendsOnly] - Whether date must be a weekend (Saturday-Sunday)
188
+ * @property {Function} [transform] - Custom transformation function for date strings
189
+ * @property {string | null} [defaultValue] - Default value when input is empty
190
+ * @property {Record<Locale, DateMessages>} [i18n] - Custom error messages for different locales
191
+ */
43
192
  type DateOptions<IsRequired extends boolean = true> = {
44
- required?: IsRequired;
45
193
  min?: string;
46
194
  max?: string;
47
195
  format?: string;
@@ -57,9 +205,411 @@ type DateOptions<IsRequired extends boolean = true> = {
57
205
  defaultValue?: IsRequired extends true ? string : string | null;
58
206
  i18n?: Record<Locale, DateMessages>;
59
207
  };
208
+ /**
209
+ * Type alias for date validation schema based on required flag
210
+ *
211
+ * @template IsRequired - Whether the field is required
212
+ * @typedef DateSchema
213
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
214
+ */
60
215
  type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
61
- declare function date<IsRequired extends boolean = true>(options?: DateOptions<IsRequired>): DateSchema<IsRequired>;
216
+ /**
217
+ * Creates a Zod schema for date validation with temporal constraints
218
+ *
219
+ * @template IsRequired - Whether the field is required (affects return type)
220
+ * @param {IsRequired} [required=false] - Whether the field is required
221
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
222
+ * @returns {DateSchema<IsRequired>} Zod schema for date validation
223
+ *
224
+ * @description
225
+ * Creates a comprehensive date validator with format support, range validation,
226
+ * temporal constraints, and weekday/weekend filtering using dayjs library.
227
+ *
228
+ * Features:
229
+ * - Flexible date format parsing (default: YYYY-MM-DD)
230
+ * - Range validation (min/max dates)
231
+ * - Temporal validation (past/future/today)
232
+ * - Weekday/weekend filtering
233
+ * - Content inclusion/exclusion
234
+ * - Custom transformation functions
235
+ * - Comprehensive internationalization
236
+ * - Strict date parsing with format validation
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * // Basic date validation (YYYY-MM-DD)
241
+ * const basicSchema = date()
242
+ * basicSchema.parse("2024-03-15") // ✓ Valid
243
+ * basicSchema.parse(null) // ✓ Valid (optional)
244
+ *
245
+ * // Required validation
246
+ * const requiredSchema = parse("2024-03-15") // ✓ Valid
247
+ (true)
248
+ * requiredSchema.parse(null) // ✗ Invalid (required)
249
+ *
250
+ * basicSchema.parse("2024-13-01") // ✗ Invalid (month 13)
251
+ *
252
+ * // Custom format
253
+ * const customFormatSchema = date(false, { format: "DD/MM/YYYY" })
254
+ * customFormatSchema.parse("15/03/2024") // ✓ Valid
255
+ * customFormatSchema.parse("2024-03-15") // ✗ Invalid (wrong format)
256
+ *
257
+ * // Date range validation
258
+ * const rangeSchema = date(false, {
259
+ * min: "2024-01-01",
260
+ * max: "2024-12-31"
261
+ * })
262
+ * rangeSchema.parse("2024-06-15") // ✓ Valid
263
+ * rangeSchema.parse("2023-12-31") // ✗ Invalid (before min)
264
+ *
265
+ * // Future dates only
266
+ * const futureSchema = date(false, { mustBeFuture: true })
267
+ * futureSchema.parse("2030-01-01") // ✓ Valid (assuming current date < 2030)
268
+ * futureSchema.parse("2020-01-01") // ✗ Invalid (past date)
269
+ *
270
+ * // Weekdays only (Monday-Friday)
271
+ * const weekdaySchema = date(false, { weekdaysOnly: true })
272
+ * weekdaySchema.parse("2024-03-15") // ✓ Valid (if Friday)
273
+ * weekdaySchema.parse("2024-03-16") // ✗ Invalid (if Saturday)
274
+ *
275
+ * // Business date validation
276
+ * const businessSchema = date(false, {
277
+ * format: "YYYY-MM-DD",
278
+ * mustBeFuture: true,
279
+ * weekdaysOnly: true
280
+ * })
281
+ *
282
+ * // Optional with default
283
+ * const optionalSchema = date(false, {
284
+ * defaultValue: "2024-01-01"
285
+ * })
286
+ * ```
287
+ *
288
+ * @throws {z.ZodError} When validation fails with specific error messages
289
+ * @see {@link DateOptions} for all available configuration options
290
+ */
291
+ declare function date<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateOptions<IsRequired>, 'required'>): DateSchema<IsRequired>;
292
+
293
+ /**
294
+ * @fileoverview DateTime validator for Zod Kit
295
+ *
296
+ * Provides comprehensive datetime validation with support for multiple formats,
297
+ * timezone handling, range validation, and internationalization.
298
+ *
299
+ * @author Ong Hoe Yuan
300
+ * @version 0.0.5
301
+ */
302
+
303
+ /**
304
+ * Type definition for datetime validation error messages
305
+ *
306
+ * @interface DateTimeMessages
307
+ * @property {string} [required] - Message when field is required but empty
308
+ * @property {string} [invalid] - Message when datetime format is invalid
309
+ * @property {string} [format] - Message when datetime doesn't match expected format
310
+ * @property {string} [min] - Message when datetime is before minimum allowed
311
+ * @property {string} [max] - Message when datetime is after maximum allowed
312
+ * @property {string} [includes] - Message when datetime doesn't include required string
313
+ * @property {string} [excludes] - Message when datetime contains excluded string
314
+ * @property {string} [past] - Message when datetime must be in the past
315
+ * @property {string} [future] - Message when datetime must be in the future
316
+ * @property {string} [today] - Message when datetime must be today
317
+ * @property {string} [notToday] - Message when datetime must not be today
318
+ * @property {string} [weekday] - Message when datetime must be a weekday
319
+ * @property {string} [weekend] - Message when datetime must be a weekend
320
+ * @property {string} [hour] - Message when hour is outside allowed range
321
+ * @property {string} [minute] - Message when minute doesn't match step requirement
322
+ * @property {string} [customRegex] - Message when custom regex validation fails
323
+ * @property {string} [notInWhitelist] - Message when value is not in whitelist
324
+ */
325
+ type DateTimeMessages = {
326
+ required?: string;
327
+ invalid?: string;
328
+ format?: string;
329
+ min?: string;
330
+ max?: string;
331
+ includes?: string;
332
+ excludes?: string;
333
+ past?: string;
334
+ future?: string;
335
+ today?: string;
336
+ notToday?: string;
337
+ weekday?: string;
338
+ weekend?: string;
339
+ hour?: string;
340
+ minute?: string;
341
+ customRegex?: string;
342
+ notInWhitelist?: string;
343
+ };
344
+ /**
345
+ * Supported datetime formats for validation
346
+ *
347
+ * @typedef {string} DateTimeFormat
348
+ *
349
+ * Standard formats:
350
+ * - YYYY-MM-DD HH:mm: ISO-style date with 24-hour time (2024-03-15 14:30)
351
+ * - YYYY-MM-DD HH:mm:ss: ISO-style date with seconds (2024-03-15 14:30:45)
352
+ * - YYYY-MM-DD hh:mm A: ISO-style date with 12-hour time (2024-03-15 02:30 PM)
353
+ * - YYYY-MM-DD hh:mm:ss A: ISO-style date with 12-hour time and seconds (2024-03-15 02:30:45 PM)
354
+ *
355
+ * Regional formats:
356
+ * - DD/MM/YYYY HH:mm: European format (15/03/2024 14:30)
357
+ * - DD/MM/YYYY HH:mm:ss: European format with seconds (15/03/2024 14:30:45)
358
+ * - DD/MM/YYYY hh:mm A: European format with 12-hour time (15/03/2024 02:30 PM)
359
+ * - MM/DD/YYYY HH:mm: US format (03/15/2024 14:30)
360
+ * - MM/DD/YYYY hh:mm A: US format with 12-hour time (03/15/2024 02:30 PM)
361
+ * - YYYY/MM/DD HH:mm: Alternative slash format (2024/03/15 14:30)
362
+ * - DD-MM-YYYY HH:mm: European dash format (15-03-2024 14:30)
363
+ * - MM-DD-YYYY HH:mm: US dash format (03-15-2024 14:30)
364
+ *
365
+ * Special formats:
366
+ * - ISO: ISO 8601 format (2024-03-15T14:30:45.000Z)
367
+ * - RFC: RFC 2822 format (Fri, 15 Mar 2024 14:30:45 GMT)
368
+ * - UNIX: Unix timestamp (1710508245)
369
+ */
370
+ type DateTimeFormat = "YYYY-MM-DD HH:mm" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM-DD hh:mm A" | "YYYY-MM-DD hh:mm:ss A" | "DD/MM/YYYY HH:mm" | "DD/MM/YYYY HH:mm:ss" | "DD/MM/YYYY hh:mm A" | "MM/DD/YYYY HH:mm" | "MM/DD/YYYY hh:mm A" | "YYYY/MM/DD HH:mm" | "DD-MM-YYYY HH:mm" | "MM-DD-YYYY HH:mm" | "ISO" | "RFC" | "UNIX";
371
+ /**
372
+ * Configuration options for datetime validation
373
+ *
374
+ * @template IsRequired - Whether the field is required (affects return type)
375
+ *
376
+ * @interface DateTimeOptions
377
+ * @property {IsRequired} [required=true] - Whether the field is required
378
+ * @property {DateTimeFormat} [format="YYYY-MM-DD HH:mm"] - Expected datetime format
379
+ * @property {string | Date} [min] - Minimum allowed datetime
380
+ * @property {string | Date} [max] - Maximum allowed datetime
381
+ * @property {number} [minHour] - Minimum allowed hour (0-23)
382
+ * @property {number} [maxHour] - Maximum allowed hour (0-23)
383
+ * @property {number[]} [allowedHours] - Specific hours that are allowed
384
+ * @property {number} [minuteStep] - Required minute intervals (e.g., 15 for :00, :15, :30, :45)
385
+ * @property {string} [timezone] - Timezone for parsing and validation (e.g., "Asia/Taipei")
386
+ * @property {string} [includes] - String that must be included in the datetime
387
+ * @property {string | string[]} [excludes] - String(s) that must not be included
388
+ * @property {RegExp} [regex] - Custom regex for validation (overrides format validation)
389
+ * @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
390
+ * @property {"upper" | "lower" | "none"} [casing="none"] - Case transformation
391
+ * @property {boolean} [mustBePast] - Whether datetime must be in the past
392
+ * @property {boolean} [mustBeFuture] - Whether datetime must be in the future
393
+ * @property {boolean} [mustBeToday] - Whether datetime must be today
394
+ * @property {boolean} [mustNotBeToday] - Whether datetime must not be today
395
+ * @property {boolean} [weekdaysOnly] - Whether datetime must be a weekday (Monday-Friday)
396
+ * @property {boolean} [weekendsOnly] - Whether datetime must be a weekend (Saturday-Sunday)
397
+ * @property {string[]} [whitelist] - Specific datetime strings that are always allowed
398
+ * @property {boolean} [whitelistOnly=false] - If true, only values in whitelist are allowed
399
+ * @property {Function} [transform] - Custom transformation function applied before validation
400
+ * @property {string | null} [defaultValue] - Default value when input is empty
401
+ * @property {Record<Locale, DateTimeMessages>} [i18n] - Custom error messages for different locales
402
+ */
403
+ type DateTimeOptions<IsRequired extends boolean = true> = {
404
+ format?: DateTimeFormat;
405
+ min?: string | Date;
406
+ max?: string | Date;
407
+ minHour?: number;
408
+ maxHour?: number;
409
+ allowedHours?: number[];
410
+ minuteStep?: number;
411
+ timezone?: string;
412
+ includes?: string;
413
+ excludes?: string | string[];
414
+ regex?: RegExp;
415
+ trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
416
+ casing?: "upper" | "lower" | "none";
417
+ mustBePast?: boolean;
418
+ mustBeFuture?: boolean;
419
+ mustBeToday?: boolean;
420
+ mustNotBeToday?: boolean;
421
+ weekdaysOnly?: boolean;
422
+ weekendsOnly?: boolean;
423
+ whitelist?: string[];
424
+ whitelistOnly?: boolean;
425
+ transform?: (value: string) => string;
426
+ defaultValue?: IsRequired extends true ? string : string | null;
427
+ i18n?: Record<Locale, DateTimeMessages>;
428
+ };
429
+ /**
430
+ * Type alias for datetime validation schema based on required flag
431
+ *
432
+ * @template IsRequired - Whether the field is required
433
+ * @typedef DateTimeSchema
434
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
435
+ */
436
+ type DateTimeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
437
+ /**
438
+ * Regular expression patterns for datetime format validation
439
+ *
440
+ * @constant {Record<DateTimeFormat, RegExp>} DATETIME_PATTERNS
441
+ * @description Maps each supported datetime format to its corresponding regex pattern
442
+ *
443
+ * Pattern explanations:
444
+ * - YYYY-MM-DD HH:mm: 4-digit year, 2-digit month, 2-digit day, 24-hour time
445
+ * - ISO: ISO 8601 format with optional milliseconds and timezone
446
+ * - RFC: RFC 2822 format with day name, date, time, and timezone
447
+ * - UNIX: 10-digit Unix timestamp
448
+ */
449
+ declare const DATETIME_PATTERNS: Record<DateTimeFormat, RegExp>;
450
+ /**
451
+ * Validates if a datetime string matches the specified format pattern
452
+ *
453
+ * @param {string} value - The datetime string to validate
454
+ * @param {DateTimeFormat} format - The expected datetime format
455
+ * @returns {boolean} True if the datetime is valid for the given format
456
+ *
457
+ * @description
458
+ * Performs both regex pattern matching and actual datetime parsing validation.
459
+ * Returns false if either the pattern doesn't match or the parsed datetime is invalid.
460
+ *
461
+ * @example
462
+ * ```typescript
463
+ * validateDateTimeFormat("2024-03-15 14:30", "YYYY-MM-DD HH:mm") // true
464
+ * validateDateTimeFormat("2024-03-15 25:30", "YYYY-MM-DD HH:mm") // false (invalid hour)
465
+ * validateDateTimeFormat("15/03/2024", "YYYY-MM-DD HH:mm") // false (wrong format)
466
+ * ```
467
+ */
468
+ declare const validateDateTimeFormat: (value: string, format: DateTimeFormat) => boolean;
469
+ /**
470
+ * Parses a datetime string into a dayjs object using the specified format
471
+ *
472
+ * @param {string} value - The datetime string to parse
473
+ * @param {DateTimeFormat} format - The expected datetime format
474
+ * @param {string} [timezone] - Optional timezone for parsing (e.g., "Asia/Taipei")
475
+ * @returns {dayjs.Dayjs | null} Parsed dayjs object or null if parsing fails
476
+ *
477
+ * @description
478
+ * Handles different datetime formats including ISO, RFC, Unix timestamps, and custom formats.
479
+ * Uses strict parsing mode for custom formats to ensure accuracy.
480
+ * Applies timezone conversion if specified.
481
+ *
482
+ * @example
483
+ * ```typescript
484
+ * parseDateTimeValue("2024-03-15 14:30", "YYYY-MM-DD HH:mm")
485
+ * // Returns dayjs object for March 15, 2024 at 2:30 PM
486
+ *
487
+ * parseDateTimeValue("1710508245", "UNIX")
488
+ * // Returns dayjs object for the Unix timestamp
489
+ *
490
+ * parseDateTimeValue("2024-03-15T14:30:45.000Z", "ISO")
491
+ * // Returns dayjs object for the ISO datetime
492
+ * ```
493
+ *
494
+ * @throws {Error} Returns null if parsing fails or datetime is invalid
495
+ */
496
+ declare const parseDateTimeValue: (value: string, format: DateTimeFormat, timezone?: string) => dayjs.Dayjs | null;
497
+ /**
498
+ * Normalizes a datetime string to the specified format
499
+ *
500
+ * @param {string} value - The datetime string to normalize
501
+ * @param {DateTimeFormat} format - The target datetime format
502
+ * @param {string} [timezone] - Optional timezone for formatting
503
+ * @returns {string | null} Normalized datetime string or null if parsing fails
504
+ *
505
+ * @description
506
+ * Parses the input datetime and formats it according to the specified format.
507
+ * Handles special formats like ISO, RFC, and Unix timestamps appropriately.
508
+ * Returns null if the input datetime cannot be parsed.
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * normalizeDateTimeValue("2024-3-15 2:30 PM", "YYYY-MM-DD HH:mm")
513
+ * // Returns "2024-03-15 14:30"
514
+ *
515
+ * normalizeDateTimeValue("1710508245", "ISO")
516
+ * // Returns "2024-03-15T14:30:45.000Z"
517
+ * ```
518
+ */
519
+ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, timezone?: string) => string | null;
520
+ /**
521
+ * Creates a Zod schema for datetime validation with comprehensive options
522
+ *
523
+ * @template IsRequired - Whether the field is required (affects return type)
524
+ * @param {IsRequired} [required=false] - Whether the field is required
525
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
526
+ * @returns {DateTimeSchema<IsRequired>} Zod schema for datetime validation
527
+ *
528
+ * @description
529
+ * Creates a comprehensive datetime validator that supports multiple formats, timezone handling,
530
+ * range validation, temporal constraints, and extensive customization options.
531
+ *
532
+ * Features:
533
+ * - Multiple datetime formats (ISO, RFC, Unix, regional formats)
534
+ * - Timezone support and conversion
535
+ * - Range validation (min/max datetime)
536
+ * - Hour and minute constraints
537
+ * - Temporal validation (past/future/today)
538
+ * - Weekday/weekend validation
539
+ * - Whitelist/blacklist support
540
+ * - Custom regex patterns
541
+ * - String transformation and case handling
542
+ * - Comprehensive internationalization
543
+ *
544
+ * @example
545
+ * ```typescript
546
+ * // Basic datetime validation
547
+ * const basicSchema = datetime() // optional by default
548
+ * basicSchema.parse("2024-03-15 14:30") // ✓ Valid
549
+ * basicSchema.parse(null) // ✓ Valid (optional)
550
+ *
551
+ * // Required validation
552
+ * const requiredSchema = parse("2024-03-15 14:30") // ✓ Valid
553
+ (true)
554
+ * requiredSchema.parse(null) // ✗ Invalid (required)
555
+ *
556
+ *
557
+ * // Business hours validation
558
+ * const businessHours = datetime({
559
+ * format: "YYYY-MM-DD HH:mm",
560
+ * minHour: 9,
561
+ * maxHour: 17,
562
+ * weekdaysOnly: true
563
+ * })
564
+ *
565
+ * // Timezone-aware validation
566
+ * const timezoneSchema = datetime(false, {
567
+ * timezone: "Asia/Taipei",
568
+ * mustBeFuture: true
569
+ * })
570
+ *
571
+ * // Multiple format support
572
+ * const flexibleSchema = datetime(false, {
573
+ * format: "DD/MM/YYYY HH:mm"
574
+ * })
575
+ * flexibleSchema.parse("15/03/2024 14:30") // ✓ Valid
576
+ *
577
+ * // Optional with default
578
+ * const optionalSchema = datetime(false, {
579
+ * defaultValue: "2024-01-01 00:00"
580
+ * })
581
+ * ```
582
+ *
583
+ * @throws {z.ZodError} When validation fails with specific error messages
584
+ * @see {@link DateTimeOptions} for all available configuration options
585
+ * @see {@link DateTimeFormat} for supported datetime formats
586
+ */
587
+ declare function datetime<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateTimeOptions<IsRequired>, 'required'>): DateTimeSchema<IsRequired>;
62
588
 
589
+ /**
590
+ * @fileoverview Email validator for Zod Kit
591
+ *
592
+ * Provides comprehensive email validation with domain filtering, business email
593
+ * validation, disposable email detection, and extensive customization options.
594
+ *
595
+ * @author Ong Hoe Yuan
596
+ * @version 0.0.5
597
+ */
598
+
599
+ /**
600
+ * Type definition for email validation error messages
601
+ *
602
+ * @interface EmailMessages
603
+ * @property {string} [required] - Message when field is required but empty
604
+ * @property {string} [invalid] - Message when email format is invalid
605
+ * @property {string} [minLength] - Message when email is too short
606
+ * @property {string} [maxLength] - Message when email is too long
607
+ * @property {string} [includes] - Message when email doesn't contain required string
608
+ * @property {string} [domain] - Message when email domain is not allowed
609
+ * @property {string} [domainBlacklist] - Message when email domain is blacklisted
610
+ * @property {string} [businessOnly] - Message when free email providers are not allowed
611
+ * @property {string} [noDisposable] - Message when disposable email addresses are not allowed
612
+ */
63
613
  type EmailMessages = {
64
614
  required?: string;
65
615
  invalid?: string;
@@ -71,8 +621,27 @@ type EmailMessages = {
71
621
  businessOnly?: string;
72
622
  noDisposable?: string;
73
623
  };
624
+ /**
625
+ * Configuration options for email validation
626
+ *
627
+ * @template IsRequired - Whether the field is required (affects return type)
628
+ *
629
+ * @interface EmailOptions
630
+ * @property {string | string[]} [domain] - Allowed domain(s) for email addresses
631
+ * @property {string[]} [domainBlacklist] - Domains that are not allowed
632
+ * @property {number} [minLength] - Minimum length of email address
633
+ * @property {number} [maxLength] - Maximum length of email address
634
+ * @property {string} [includes] - String that must be included in the email
635
+ * @property {string | string[]} [excludes] - String(s) that must not be included
636
+ * @property {boolean} [allowSubdomains=true] - Whether to allow subdomains in domain validation
637
+ * @property {boolean} [businessOnly=false] - If true, reject common free email providers
638
+ * @property {boolean} [noDisposable=false] - If true, reject disposable email addresses
639
+ * @property {boolean} [lowercase=true] - Whether to convert email to lowercase
640
+ * @property {Function} [transform] - Custom transformation function for email strings
641
+ * @property {string | null} [defaultValue] - Default value when input is empty
642
+ * @property {Record<Locale, EmailMessages>} [i18n] - Custom error messages for different locales
643
+ */
74
644
  type EmailOptions<IsRequired extends boolean = true> = {
75
- required?: IsRequired;
76
645
  domain?: string | string[];
77
646
  domainBlacklist?: string[];
78
647
  minLength?: number;
@@ -87,9 +656,288 @@ type EmailOptions<IsRequired extends boolean = true> = {
87
656
  defaultValue?: IsRequired extends true ? string : string | null;
88
657
  i18n?: Record<Locale, EmailMessages>;
89
658
  };
659
+ /**
660
+ * Type alias for email validation schema based on required flag
661
+ *
662
+ * @template IsRequired - Whether the field is required
663
+ * @typedef EmailSchema
664
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
665
+ */
90
666
  type EmailSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
91
- declare function email<IsRequired extends boolean = true>(options?: EmailOptions<IsRequired>): EmailSchema<IsRequired>;
667
+ /**
668
+ * Creates a Zod schema for email validation with comprehensive filtering options
669
+ *
670
+ * @template IsRequired - Whether the field is required (affects return type)
671
+ * @param {IsRequired} [required=false] - Whether the field is required
672
+ * @param {Omit<EmailOptions<IsRequired>, 'required'>} [options] - Configuration options for email validation
673
+ * @returns {EmailSchema<IsRequired>} Zod schema for email validation
674
+ *
675
+ * @description
676
+ * Creates a comprehensive email validator with domain filtering, business email
677
+ * validation, disposable email detection, and extensive customization options.
678
+ *
679
+ * Features:
680
+ * - RFC-compliant email format validation
681
+ * - Domain whitelist/blacklist support
682
+ * - Business email validation (excludes free providers)
683
+ * - Disposable email detection
684
+ * - Subdomain support configuration
685
+ * - Length validation
686
+ * - Content inclusion/exclusion
687
+ * - Automatic lowercase conversion
688
+ * - Custom transformation functions
689
+ * - Comprehensive internationalization
690
+ *
691
+ * @example
692
+ * ```typescript
693
+ * // Basic email validation (optional by default)
694
+ * const basicSchema = email()
695
+ * basicSchema.parse("user@example.com") // ✓ Valid
696
+ * basicSchema.parse(null) // ✓ Valid (optional)
697
+ *
698
+ * // Required email
699
+ * const requiredSchema = email(true)
700
+ * requiredSchema.parse("user@example.com") // ✓ Valid
701
+ * requiredSchema.parse(null) // ✗ Invalid (required)
702
+ *
703
+ * // Domain restriction
704
+ * const domainSchema = email(false, {
705
+ * domain: ["company.com", "organization.org"]
706
+ * })
707
+ * domainSchema.parse("user@company.com") // ✓ Valid
708
+ * domainSchema.parse("user@gmail.com") // ✗ Invalid
709
+ *
710
+ * // Business emails only (no free providers)
711
+ * const businessSchema = email(true, { businessOnly: true })
712
+ * businessSchema.parse("user@company.com") // ✓ Valid
713
+ * businessSchema.parse("user@gmail.com") // ✗ Invalid
714
+ *
715
+ * // No disposable emails
716
+ * const noDisposableSchema = email(true, { noDisposable: true })
717
+ * noDisposableSchema.parse("user@company.com") // ✓ Valid
718
+ * noDisposableSchema.parse("user@10minutemail.com") // ✗ Invalid
719
+ *
720
+ * // Domain blacklist
721
+ * const blacklistSchema = email(false, {
722
+ * domainBlacklist: ["spam.com", "blocked.org"]
723
+ * })
724
+ *
725
+ * // Optional with default
726
+ * const optionalSchema = email(false, { defaultValue: null })
727
+ * ```
728
+ *
729
+ * @throws {z.ZodError} When validation fails with specific error messages
730
+ * @see {@link EmailOptions} for all available configuration options
731
+ */
732
+ declare function email<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<EmailOptions<IsRequired>, 'required'>): EmailSchema<IsRequired>;
733
+
734
+ /**
735
+ * @fileoverview File validator for Zod Kit
736
+ *
737
+ * Provides comprehensive file validation with MIME type filtering, size validation,
738
+ * extension validation, and extensive customization options.
739
+ *
740
+ * @author Ong Hoe Yuan
741
+ * @version 0.0.5
742
+ */
743
+
744
+ /**
745
+ * Type definition for file validation error messages
746
+ *
747
+ * @interface FileMessages
748
+ * @property {string} [required] - Message when field is required but empty
749
+ * @property {string} [invalid] - Message when file format is invalid
750
+ * @property {string} [size] - Message when file size exceeds limit
751
+ * @property {string} [minSize] - Message when file size is too small
752
+ * @property {string} [maxSize] - Message when file size exceeds maximum
753
+ * @property {string} [type] - Message when file type is not allowed
754
+ * @property {string} [extension] - Message when file extension is not allowed
755
+ * @property {string} [extensionBlacklist] - Message when file extension is blacklisted
756
+ * @property {string} [name] - Message when file name doesn't match pattern
757
+ * @property {string} [nameBlacklist] - Message when file name matches blacklisted pattern
758
+ * @property {string} [imageOnly] - Message when only image files are allowed
759
+ * @property {string} [documentOnly] - Message when only document files are allowed
760
+ * @property {string} [videoOnly] - Message when only video files are allowed
761
+ * @property {string} [audioOnly] - Message when only audio files are allowed
762
+ * @property {string} [archiveOnly] - Message when only archive files are allowed
763
+ */
764
+ type FileMessages = {
765
+ required?: string;
766
+ invalid?: string;
767
+ size?: string;
768
+ minSize?: string;
769
+ maxSize?: string;
770
+ type?: string;
771
+ extension?: string;
772
+ extensionBlacklist?: string;
773
+ name?: string;
774
+ nameBlacklist?: string;
775
+ imageOnly?: string;
776
+ documentOnly?: string;
777
+ videoOnly?: string;
778
+ audioOnly?: string;
779
+ archiveOnly?: string;
780
+ };
781
+ /**
782
+ * Configuration options for file validation
783
+ *
784
+ * @template IsRequired - Whether the field is required (affects return type)
785
+ *
786
+ * @interface FileOptions
787
+ * @property {IsRequired} [required=true] - Whether the field is required
788
+ * @property {number} [maxSize] - Maximum file size in bytes
789
+ * @property {number} [minSize] - Minimum file size in bytes
790
+ * @property {string | string[]} [type] - Allowed MIME type(s)
791
+ * @property {string[]} [typeBlacklist] - MIME types that are not allowed
792
+ * @property {string | string[]} [extension] - Allowed file extension(s)
793
+ * @property {string[]} [extensionBlacklist] - File extensions that are not allowed
794
+ * @property {RegExp | string} [namePattern] - Pattern that file name must match
795
+ * @property {RegExp | string | Array<RegExp | string>} [nameBlacklist] - Pattern(s) that file name must not match
796
+ * @property {boolean} [imageOnly=false] - If true, only allow image files
797
+ * @property {boolean} [documentOnly=false] - If true, only allow document files
798
+ * @property {boolean} [videoOnly=false] - If true, only allow video files
799
+ * @property {boolean} [audioOnly=false] - If true, only allow audio files
800
+ * @property {boolean} [archiveOnly=false] - If true, only allow archive files
801
+ * @property {boolean} [caseSensitive=false] - Whether extension matching is case-sensitive
802
+ * @property {Function} [transform] - Custom transformation function for File objects
803
+ * @property {File | null} [defaultValue] - Default value when input is empty
804
+ * @property {Record<Locale, FileMessages>} [i18n] - Custom error messages for different locales
805
+ */
806
+ type FileOptions<IsRequired extends boolean = true> = {
807
+ maxSize?: number;
808
+ minSize?: number;
809
+ type?: string | string[];
810
+ typeBlacklist?: string[];
811
+ extension?: string | string[];
812
+ extensionBlacklist?: string[];
813
+ namePattern?: RegExp | string;
814
+ nameBlacklist?: RegExp | string | Array<RegExp | string>;
815
+ imageOnly?: boolean;
816
+ documentOnly?: boolean;
817
+ videoOnly?: boolean;
818
+ audioOnly?: boolean;
819
+ archiveOnly?: boolean;
820
+ caseSensitive?: boolean;
821
+ transform?: (value: File) => File;
822
+ defaultValue?: IsRequired extends true ? File : File | null;
823
+ i18n?: Record<Locale, FileMessages>;
824
+ };
825
+ /**
826
+ * Type alias for file validation schema based on required flag
827
+ *
828
+ * @template IsRequired - Whether the field is required
829
+ * @typedef FileSchema
830
+ * @description Returns ZodType<File> if required, ZodNullable<ZodType<File>> if optional
831
+ */
832
+ type FileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodType<File> : ZodNullable<ZodType<File>>;
833
+ /**
834
+ * Creates a Zod schema for file validation with comprehensive filtering options
835
+ *
836
+ * @template IsRequired - Whether the field is required (affects return type)
837
+ * @param {IsRequired} [required=false] - Whether the field is required
838
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
839
+ * @returns {FileSchema<IsRequired>} Zod schema for file validation
840
+ *
841
+ * @description
842
+ * Creates a comprehensive file validator with MIME type filtering, size validation,
843
+ * extension validation, and extensive customization options.
844
+ *
845
+ * Features:
846
+ * - File size validation (min/max)
847
+ * - MIME type whitelist/blacklist support
848
+ * - File extension whitelist/blacklist support
849
+ * - File name pattern validation
850
+ * - Predefined file category filters (image, document, video, audio, archive)
851
+ * - Case-sensitive/insensitive extension matching
852
+ * - Custom transformation functions
853
+ * - Comprehensive internationalization
854
+ *
855
+ * @example
856
+ * ```typescript
857
+ * // Basic file validation
858
+ * const basicSchema = file() // optional by default
859
+ * basicSchema.parse(new File(["content"], "test.txt"))
860
+ * basicSchema.parse(null) // ✓ Valid (optional)
861
+ *
862
+ * // Required validation
863
+ * const requiredSchema = parse(new File(["content"], "test.txt"))
864
+ (true)
865
+ * requiredSchema.parse(null) // ✗ Invalid (required)
866
+ *
867
+ *
868
+ * // Size restrictions
869
+ * const sizeSchema = file(false, {
870
+ * maxSize: 1024 * 1024, // 1MB
871
+ * minSize: 1024 // 1KB
872
+ * })
873
+ *
874
+ * // Extension restrictions
875
+ * const imageSchema = file(false, {
876
+ * extension: [".jpg", ".png", ".gif"],
877
+ * maxSize: 5 * 1024 * 1024 // 5MB
878
+ * })
879
+ *
880
+ * // MIME type restrictions
881
+ * const documentSchema = file(false, {
882
+ * type: ["application/pdf", "application/msword"],
883
+ * maxSize: 10 * 1024 * 1024 // 10MB
884
+ * })
885
+ *
886
+ * // Image files only
887
+ * const imageOnlySchema = file(false, { imageOnly: true })
888
+ *
889
+ * // Document files only
890
+ * const docOnlySchema = file(false, { documentOnly: true })
891
+ *
892
+ * // Name pattern validation
893
+ * const patternSchema = file(false, {
894
+ * namePattern: /^[a-zA-Z0-9_-]+\.(pdf|doc|docx)$/,
895
+ * maxSize: 5 * 1024 * 1024
896
+ * })
897
+ *
898
+ * // Optional with default
899
+ * const optionalSchema = file(false, {
900
+ * defaultValue: null
901
+ * })
902
+ * ```
903
+ *
904
+ * @throws {z.ZodError} When validation fails with specific error messages
905
+ * @see {@link FileOptions} for all available configuration options
906
+ */
907
+ declare function file<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<FileOptions<IsRequired>, 'required'>): FileSchema<IsRequired>;
908
+
909
+ /**
910
+ * @fileoverview ID validator for Zod Kit
911
+ *
912
+ * Provides comprehensive ID validation with support for multiple ID formats,
913
+ * auto-detection, custom patterns, and flexible validation options.
914
+ *
915
+ * @author Ong Hoe Yuan
916
+ * @version 0.0.5
917
+ */
92
918
 
919
+ /**
920
+ * Type definition for ID validation error messages
921
+ *
922
+ * @interface IdMessages
923
+ * @property {string} [required] - Message when field is required but empty
924
+ * @property {string} [invalid] - Message when ID format is invalid
925
+ * @property {string} [minLength] - Message when ID is too short
926
+ * @property {string} [maxLength] - Message when ID is too long
927
+ * @property {string} [numeric] - Message when numeric ID format is invalid
928
+ * @property {string} [uuid] - Message when UUID format is invalid
929
+ * @property {string} [objectId] - Message when MongoDB ObjectId format is invalid
930
+ * @property {string} [nanoid] - Message when Nano ID format is invalid
931
+ * @property {string} [snowflake] - Message when Snowflake ID format is invalid
932
+ * @property {string} [cuid] - Message when CUID format is invalid
933
+ * @property {string} [ulid] - Message when ULID format is invalid
934
+ * @property {string} [shortid] - Message when ShortId format is invalid
935
+ * @property {string} [customFormat] - Message when custom regex format is invalid
936
+ * @property {string} [includes] - Message when ID doesn't contain required string
937
+ * @property {string} [excludes] - Message when ID contains forbidden string
938
+ * @property {string} [startsWith] - Message when ID doesn't start with required string
939
+ * @property {string} [endsWith] - Message when ID doesn't end with required string
940
+ */
93
941
  type IdMessages = {
94
942
  required?: string;
95
943
  invalid?: string;
@@ -109,9 +957,45 @@ type IdMessages = {
109
957
  startsWith?: string;
110
958
  endsWith?: string;
111
959
  };
960
+ /**
961
+ * Supported ID types for validation
962
+ *
963
+ * @typedef {string} IdType
964
+ *
965
+ * Available types:
966
+ * - numeric: Pure numeric IDs (1, 123, 999999)
967
+ * - uuid: UUID v4 format (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)
968
+ * - objectId: MongoDB ObjectId (24-character hexadecimal)
969
+ * - nanoid: Nano ID format (21-character URL-safe)
970
+ * - snowflake: Twitter Snowflake (19-digit number)
971
+ * - cuid: CUID format (25-character starting with 'c')
972
+ * - ulid: ULID format (26-character case-insensitive)
973
+ * - shortid: ShortId format (7-14 character URL-safe)
974
+ * - auto: Auto-detect format from the value
975
+ */
112
976
  type IdType = "numeric" | "uuid" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
977
+ /**
978
+ * Configuration options for ID validation
979
+ *
980
+ * @template IsRequired - Whether the field is required (affects return type)
981
+ *
982
+ * @interface IdOptions
983
+ * @property {IsRequired} [required=true] - Whether the field is required
984
+ * @property {IdType} [type="auto"] - Expected ID type or auto-detection
985
+ * @property {number} [minLength] - Minimum length of ID
986
+ * @property {number} [maxLength] - Maximum length of ID
987
+ * @property {IdType[]} [allowedTypes] - Multiple allowed ID types (overrides type)
988
+ * @property {RegExp} [customRegex] - Custom regex pattern (overrides type validation)
989
+ * @property {string} [includes] - String that must be included in ID
990
+ * @property {string | string[]} [excludes] - String(s) that must not be included
991
+ * @property {string} [startsWith] - String that ID must start with
992
+ * @property {string} [endsWith] - String that ID must end with
993
+ * @property {boolean} [caseSensitive=true] - Whether validation is case-sensitive
994
+ * @property {Function} [transform] - Custom transformation function for ID
995
+ * @property {string | null} [defaultValue] - Default value when input is empty
996
+ * @property {Record<Locale, IdMessages>} [i18n] - Custom error messages for different locales
997
+ */
113
998
  type IdOptions<IsRequired extends boolean = true> = {
114
- required?: IsRequired;
115
999
  type?: IdType;
116
1000
  minLength?: number;
117
1001
  maxLength?: number;
@@ -126,7 +1010,20 @@ type IdOptions<IsRequired extends boolean = true> = {
126
1010
  defaultValue?: IsRequired extends true ? string : string | null;
127
1011
  i18n?: Record<Locale, IdMessages>;
128
1012
  };
1013
+ /**
1014
+ * Type alias for ID validation schema based on required flag
1015
+ *
1016
+ * @template IsRequired - Whether the field is required
1017
+ * @typedef IdSchema
1018
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
1019
+ */
129
1020
  type IdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
1021
+ /**
1022
+ * Regular expression patterns for different ID formats
1023
+ *
1024
+ * @constant {Record<string, RegExp>} ID_PATTERNS
1025
+ * @description Maps each ID type to its corresponding regex pattern
1026
+ */
130
1027
  declare const ID_PATTERNS: {
131
1028
  readonly numeric: RegExp;
132
1029
  readonly uuid: RegExp;
@@ -137,10 +1034,151 @@ declare const ID_PATTERNS: {
137
1034
  readonly ulid: RegExp;
138
1035
  readonly shortid: RegExp;
139
1036
  };
1037
+ /**
1038
+ * Detects the ID type of a given value using pattern matching
1039
+ *
1040
+ * @param {string} value - The ID value to analyze
1041
+ * @returns {IdType | null} The detected ID type or null if no pattern matches
1042
+ *
1043
+ * @description
1044
+ * Attempts to identify the ID type by testing against known patterns.
1045
+ * Patterns are ordered by specificity to avoid false positives.
1046
+ * More specific patterns (UUID, ObjectId) are tested before generic ones (numeric, shortid).
1047
+ *
1048
+ * @example
1049
+ * ```typescript
1050
+ * detectIdType("550e8400-e29b-41d4-a716-446655440000") // "uuid"
1051
+ * detectIdType("507f1f77bcf86cd799439011") // "objectId"
1052
+ * detectIdType("V1StGXR8_Z5jdHi6B-myT") // "nanoid"
1053
+ * detectIdType("123456789") // "numeric"
1054
+ * detectIdType("invalid-id") // null
1055
+ * ```
1056
+ */
140
1057
  declare const detectIdType: (value: string) => IdType | null;
1058
+ /**
1059
+ * Validates if a value matches the specified ID type
1060
+ *
1061
+ * @param {string} value - The ID value to validate
1062
+ * @param {IdType} type - The expected ID type
1063
+ * @returns {boolean} True if the value matches the specified type
1064
+ *
1065
+ * @description
1066
+ * Validates a specific ID type using regex patterns or auto-detection.
1067
+ * For "auto" type, uses detectIdType to check if any known pattern matches.
1068
+ *
1069
+ * @example
1070
+ * ```typescript
1071
+ * validateIdType("123456", "numeric") // true
1072
+ * validateIdType("abc123", "numeric") // false
1073
+ * validateIdType("550e8400-e29b-41d4-a716-446655440000", "uuid") // true
1074
+ * validateIdType("invalid-uuid", "uuid") // false
1075
+ * ```
1076
+ */
141
1077
  declare const validateIdType: (value: string, type: IdType) => boolean;
142
- declare function id<IsRequired extends boolean = true>(options?: IdOptions<IsRequired>): IdSchema<IsRequired>;
1078
+ /**
1079
+ * Creates a Zod schema for ID validation with comprehensive format support
1080
+ *
1081
+ * @template IsRequired - Whether the field is required (affects return type)
1082
+ * @param {IsRequired} [required=false] - Whether the field is required
1083
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
1084
+ * @returns {IdSchema<IsRequired>} Zod schema for ID validation
1085
+ *
1086
+ * @description
1087
+ * Creates a comprehensive ID validator with support for multiple ID formats,
1088
+ * auto-detection, custom patterns, and flexible validation options.
1089
+ *
1090
+ * Features:
1091
+ * - Multiple ID format support (UUID, ObjectId, Snowflake, etc.)
1092
+ * - Auto-detection of ID types
1093
+ * - Custom regex pattern support
1094
+ * - Length validation
1095
+ * - Content validation (includes, excludes, startsWith, endsWith)
1096
+ * - Case sensitivity control
1097
+ * - Multiple allowed types
1098
+ * - Custom transformation functions
1099
+ * - Comprehensive internationalization
1100
+ *
1101
+ * @example
1102
+ * ```typescript
1103
+ * // Auto-detect ID format
1104
+ * const autoSchema = id()
1105
+ * autoSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
1106
+ * autoSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
1107
+ * autoSchema.parse("123456") // ✓ Valid (numeric)
1108
+ *
1109
+ * // Specific ID type
1110
+ * const uuidSchema = id(false, { type: "uuid" })
1111
+ * uuidSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid
1112
+ * uuidSchema.parse("invalid-uuid") // ✗ Invalid
1113
+ *
1114
+ * // Multiple allowed types
1115
+ * const multiSchema = id(false, { allowedTypes: ["uuid", "objectId"] })
1116
+ * multiSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
1117
+ * multiSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
1118
+ * multiSchema.parse("123456") // ✗ Invalid (numeric not allowed)
1119
+ *
1120
+ * // Custom regex pattern
1121
+ * const customSchema = id(false, { customRegex: /^CUST_\d{6}$/ })
1122
+ * customSchema.parse("CUST_123456") // ✓ Valid
1123
+ * customSchema.parse("invalid") // ✗ Invalid
1124
+ *
1125
+ * // Content validation
1126
+ * const prefixSchema = id(false, {
1127
+ * type: "auto",
1128
+ * startsWith: "user_",
1129
+ * minLength: 10
1130
+ * })
1131
+ * prefixSchema.parse("user_123456") // ✓ Valid
1132
+ *
1133
+ * // Case insensitive
1134
+ * const caseInsensitiveSchema = id(false, {
1135
+ * type: "uuid",
1136
+ * caseSensitive: false
1137
+ * })
1138
+ * caseInsensitiveSchema.parse("550E8400-E29B-41D4-A716-446655440000") // ✓ Valid
1139
+ *
1140
+ * // Optional with default
1141
+ * const optionalSchema = id(false, {
1142
+ * defaultValue: null
1143
+ * })
1144
+ * ```
1145
+ *
1146
+ * @throws {z.ZodError} When validation fails with specific error messages
1147
+ * @see {@link IdOptions} for all available configuration options
1148
+ * @see {@link IdType} for supported ID types
1149
+ * @see {@link detectIdType} for auto-detection logic
1150
+ * @see {@link validateIdType} for type-specific validation
1151
+ */
1152
+ declare function id<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<IdOptions<IsRequired>, 'required'>): IdSchema<IsRequired>;
1153
+
1154
+ /**
1155
+ * @fileoverview Number validator for Zod Kit
1156
+ *
1157
+ * Provides comprehensive number validation with type constraints, range validation,
1158
+ * precision control, and advanced parsing features including comma-separated numbers.
1159
+ *
1160
+ * @author Ong Hoe Yuan
1161
+ * @version 0.0.5
1162
+ */
143
1163
 
1164
+ /**
1165
+ * Type definition for number validation error messages
1166
+ *
1167
+ * @interface NumberMessages
1168
+ * @property {string} [required] - Message when field is required but empty
1169
+ * @property {string} [invalid] - Message when value is not a valid number
1170
+ * @property {string} [integer] - Message when integer is required but float provided
1171
+ * @property {string} [float] - Message when float is required but integer provided
1172
+ * @property {string} [min] - Message when number is below minimum value
1173
+ * @property {string} [max] - Message when number exceeds maximum value
1174
+ * @property {string} [positive] - Message when positive number is required
1175
+ * @property {string} [negative] - Message when negative number is required
1176
+ * @property {string} [nonNegative] - Message when non-negative number is required
1177
+ * @property {string} [nonPositive] - Message when non-positive number is required
1178
+ * @property {string} [multipleOf] - Message when number is not a multiple of specified value
1179
+ * @property {string} [finite] - Message when finite number is required
1180
+ * @property {string} [precision] - Message when number has too many decimal places
1181
+ */
144
1182
  type NumberMessages = {
145
1183
  required?: string;
146
1184
  invalid?: string;
@@ -156,8 +1194,29 @@ type NumberMessages = {
156
1194
  finite?: string;
157
1195
  precision?: string;
158
1196
  };
1197
+ /**
1198
+ * Configuration options for number validation
1199
+ *
1200
+ * @template IsRequired - Whether the field is required (affects return type)
1201
+ *
1202
+ * @interface NumberOptions
1203
+ * @property {IsRequired} [required=true] - Whether the field is required
1204
+ * @property {number} [min] - Minimum allowed value
1205
+ * @property {number} [max] - Maximum allowed value
1206
+ * @property {number | null} [defaultValue] - Default value when input is empty
1207
+ * @property {"integer" | "float" | "both"} [type="both"] - Type constraint for the number
1208
+ * @property {boolean} [positive] - Whether number must be positive (> 0)
1209
+ * @property {boolean} [negative] - Whether number must be negative (< 0)
1210
+ * @property {boolean} [nonNegative] - Whether number must be non-negative (>= 0)
1211
+ * @property {boolean} [nonPositive] - Whether number must be non-positive (<= 0)
1212
+ * @property {number} [multipleOf] - Number must be a multiple of this value
1213
+ * @property {number} [precision] - Maximum number of decimal places allowed
1214
+ * @property {boolean} [finite=true] - Whether to reject Infinity and -Infinity
1215
+ * @property {Function} [transform] - Custom transformation function for number values
1216
+ * @property {boolean} [parseCommas=false] - Whether to parse comma-separated numbers (e.g., "1,234")
1217
+ * @property {Record<Locale, NumberMessages>} [i18n] - Custom error messages for different locales
1218
+ */
159
1219
  type NumberOptions<IsRequired extends boolean = true> = {
160
- required?: IsRequired;
161
1220
  min?: number;
162
1221
  max?: number;
163
1222
  defaultValue?: IsRequired extends true ? number : number | null;
@@ -173,9 +1232,116 @@ type NumberOptions<IsRequired extends boolean = true> = {
173
1232
  parseCommas?: boolean;
174
1233
  i18n?: Record<Locale, NumberMessages>;
175
1234
  };
1235
+ /**
1236
+ * Type alias for number validation schema based on required flag
1237
+ *
1238
+ * @template IsRequired - Whether the field is required
1239
+ * @typedef NumberSchema
1240
+ * @description Returns ZodNumber if required, ZodNullable<ZodNumber> if optional
1241
+ */
176
1242
  type NumberSchema<IsRequired extends boolean> = IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber>;
177
- declare function number<IsRequired extends boolean = true>(options?: NumberOptions<IsRequired>): NumberSchema<IsRequired>;
1243
+ /**
1244
+ * Creates a Zod schema for number validation with comprehensive constraints
1245
+ *
1246
+ * @template IsRequired - Whether the field is required (affects return type)
1247
+ * @param {NumberOptions<IsRequired>} [options] - Configuration options for number validation
1248
+ * @returns {NumberSchema<IsRequired>} Zod schema for number validation
1249
+ *
1250
+ * @description
1251
+ * Creates a comprehensive number validator with type constraints, range validation,
1252
+ * precision control, and advanced parsing features including comma-separated numbers.
1253
+ *
1254
+ * Features:
1255
+ * - Type constraints (integer, float, or both)
1256
+ * - Range validation (min/max)
1257
+ * - Sign constraints (positive, negative, non-negative, non-positive)
1258
+ * - Multiple-of validation
1259
+ * - Precision control (decimal places)
1260
+ * - Finite number validation
1261
+ * - Comma-separated number parsing
1262
+ * - Custom transformation functions
1263
+ * - Comprehensive internationalization
1264
+ *
1265
+ * @example
1266
+ * ```typescript
1267
+ * // Basic number validation (optional by default)
1268
+ * const basicSchema = number()
1269
+ * basicSchema.parse(42) // ✓ Valid
1270
+ * basicSchema.parse("42") // ✓ Valid (converted to number)
1271
+ * basicSchema.parse(null) // ✓ Valid (optional)
1272
+ *
1273
+ * // Required number
1274
+ * const requiredSchema = number(true)
1275
+ * requiredSchema.parse(42) // ✓ Valid
1276
+ * requiredSchema.parse(null) // ✗ Invalid (required)
1277
+ *
1278
+ * // Integer only
1279
+ * const integerSchema = number(false, { type: "integer" })
1280
+ * integerSchema.parse(42) // ✓ Valid
1281
+ * integerSchema.parse(42.5) // ✗ Invalid
1282
+ *
1283
+ * // Range validation
1284
+ * const rangeSchema = number(true, { min: 0, max: 100 })
1285
+ * rangeSchema.parse(50) // ✓ Valid
1286
+ * rangeSchema.parse(150) // ✗ Invalid
1287
+ *
1288
+ * // Positive numbers only
1289
+ * const positiveSchema = number(true, { positive: true })
1290
+ * positiveSchema.parse(5) // ✓ Valid
1291
+ * positiveSchema.parse(-5) // ✗ Invalid
1292
+ *
1293
+ * // Multiple of constraint
1294
+ * const multipleSchema = number(true, { multipleOf: 5 })
1295
+ * multipleSchema.parse(10) // ✓ Valid
1296
+ * multipleSchema.parse(7) // ✗ Invalid
1297
+ *
1298
+ * // Precision control
1299
+ * const precisionSchema = number(true, { precision: 2 })
1300
+ * precisionSchema.parse(3.14) // ✓ Valid
1301
+ * precisionSchema.parse(3.14159) // ✗ Invalid
1302
+ *
1303
+ * // Comma-separated parsing
1304
+ * const commaSchema = number(false, { parseCommas: true })
1305
+ * commaSchema.parse("1,234.56") // ✓ Valid (parsed as 1234.56)
1306
+ *
1307
+ * // Optional with default
1308
+ * const optionalSchema = number(false, { defaultValue: 0 })
1309
+ * ```
1310
+ *
1311
+ * @throws {z.ZodError} When validation fails with specific error messages
1312
+ * @see {@link NumberOptions} for all available configuration options
1313
+ */
1314
+ declare function number<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NumberOptions<IsRequired>, 'required'>): NumberSchema<IsRequired>;
178
1315
 
1316
+ /**
1317
+ * @fileoverview Password validator for Zod Kit
1318
+ *
1319
+ * Provides comprehensive password validation with strength analysis, character requirements,
1320
+ * security checks, and protection against common weak passwords.
1321
+ *
1322
+ * @author Ong Hoe Yuan
1323
+ * @version 0.0.5
1324
+ */
1325
+
1326
+ /**
1327
+ * Type definition for password validation error messages
1328
+ *
1329
+ * @interface PasswordMessages
1330
+ * @property {string} [required] - Message when field is required but empty
1331
+ * @property {string} [min] - Message when password is too short
1332
+ * @property {string} [max] - Message when password is too long
1333
+ * @property {string} [uppercase] - Message when uppercase letters are required
1334
+ * @property {string} [lowercase] - Message when lowercase letters are required
1335
+ * @property {string} [digits] - Message when digits are required
1336
+ * @property {string} [special] - Message when special characters are required
1337
+ * @property {string} [noRepeating] - Message when repeating characters are forbidden
1338
+ * @property {string} [noSequential] - Message when sequential characters are forbidden
1339
+ * @property {string} [noCommonWords] - Message when common passwords are forbidden
1340
+ * @property {string} [minStrength] - Message when password strength is insufficient
1341
+ * @property {string} [excludes] - Message when password contains forbidden strings
1342
+ * @property {string} [includes] - Message when password doesn't contain required string
1343
+ * @property {string} [invalid] - Message when password doesn't match custom regex
1344
+ */
179
1345
  type PasswordMessages = {
180
1346
  required?: string;
181
1347
  min?: string;
@@ -192,9 +1358,42 @@ type PasswordMessages = {
192
1358
  includes?: string;
193
1359
  invalid?: string;
194
1360
  };
1361
+ /**
1362
+ * Password strength levels used for validation
1363
+ *
1364
+ * @typedef {"weak" | "medium" | "strong" | "very-strong"} PasswordStrength
1365
+ * @description
1366
+ * - weak: Basic passwords with minimal requirements
1367
+ * - medium: Passwords with some character variety
1368
+ * - strong: Passwords with good character variety and length
1369
+ * - very-strong: Passwords with excellent character variety, length, and complexity
1370
+ */
195
1371
  type PasswordStrength = "weak" | "medium" | "strong" | "very-strong";
1372
+ /**
1373
+ * Configuration options for password validation
1374
+ *
1375
+ * @template IsRequired - Whether the field is required (affects return type)
1376
+ *
1377
+ * @interface PasswordOptions
1378
+ * @property {IsRequired} [required=true] - Whether the field is required
1379
+ * @property {number} [min] - Minimum length of password
1380
+ * @property {number} [max] - Maximum length of password
1381
+ * @property {boolean} [uppercase] - Whether uppercase letters are required
1382
+ * @property {boolean} [lowercase] - Whether lowercase letters are required
1383
+ * @property {boolean} [digits] - Whether digits are required
1384
+ * @property {boolean} [special] - Whether special characters are required
1385
+ * @property {boolean} [noRepeating] - Whether to forbid repeating characters (3+ in a row)
1386
+ * @property {boolean} [noSequential] - Whether to forbid sequential characters (abc, 123)
1387
+ * @property {boolean} [noCommonWords] - Whether to forbid common weak passwords
1388
+ * @property {PasswordStrength} [minStrength] - Minimum required password strength
1389
+ * @property {string | string[]} [excludes] - String(s) that must not be included
1390
+ * @property {string} [includes] - String that must be included in password
1391
+ * @property {RegExp} [regex] - Custom regex pattern for validation
1392
+ * @property {Function} [transform] - Custom transformation function for password
1393
+ * @property {string | null} [defaultValue] - Default value when input is empty
1394
+ * @property {Record<Locale, PasswordMessages>} [i18n] - Custom error messages for different locales
1395
+ */
196
1396
  type PasswordOptions<IsRequired extends boolean = true> = {
197
- required?: IsRequired;
198
1397
  min?: number;
199
1398
  max?: number;
200
1399
  uppercase?: boolean;
@@ -212,9 +1411,120 @@ type PasswordOptions<IsRequired extends boolean = true> = {
212
1411
  defaultValue?: IsRequired extends true ? string : string | null;
213
1412
  i18n?: Record<Locale, PasswordMessages>;
214
1413
  };
1414
+ /**
1415
+ * Type alias for password validation schema based on required flag
1416
+ *
1417
+ * @template IsRequired - Whether the field is required
1418
+ * @typedef PasswordSchema
1419
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
1420
+ */
215
1421
  type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
216
- declare function password<IsRequired extends boolean = true>(options?: PasswordOptions<IsRequired>): PasswordSchema<IsRequired>;
1422
+ /**
1423
+ * Creates a Zod schema for password validation with comprehensive security checks
1424
+ *
1425
+ * @template IsRequired - Whether the field is required (affects return type)
1426
+ * @param {IsRequired} [required=false] - Whether the field is required
1427
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
1428
+ * @returns {PasswordSchema<IsRequired>} Zod schema for password validation
1429
+ *
1430
+ * @description
1431
+ * Creates a comprehensive password validator with strength analysis, character requirements,
1432
+ * security checks, and protection against common weak passwords.
1433
+ *
1434
+ * Features:
1435
+ * - Length validation (min/max)
1436
+ * - Character requirements (uppercase, lowercase, digits, special)
1437
+ * - Security checks (no repeating, no sequential patterns)
1438
+ * - Common password detection
1439
+ * - Strength analysis with configurable minimum levels
1440
+ * - Content inclusion/exclusion
1441
+ * - Custom regex patterns
1442
+ * - Custom transformation functions
1443
+ * - Comprehensive internationalization
1444
+ *
1445
+ * @example
1446
+ * ```typescript
1447
+ * // Basic password validation
1448
+ * const basicSchema = password() // optional by default
1449
+ * basicSchema.parse("MyPassword123!") // ✓ Valid
1450
+ * basicSchema.parse(null) // ✓ Valid (optional)
1451
+ *
1452
+ * // Required validation
1453
+ * const requiredSchema = parse("MyPassword123!") // ✓ Valid
1454
+ (true)
1455
+ * requiredSchema.parse(null) // ✗ Invalid (required)
1456
+ *
1457
+ *
1458
+ * // Strong password requirements
1459
+ * const strongSchema = password(false, {
1460
+ * min: 12,
1461
+ * uppercase: true,
1462
+ * lowercase: true,
1463
+ * digits: true,
1464
+ * special: true,
1465
+ * minStrength: "strong"
1466
+ * })
1467
+ *
1468
+ * // No common passwords
1469
+ * const secureSchema = password(false, {
1470
+ * noCommonWords: true,
1471
+ * noRepeating: true,
1472
+ * noSequential: true
1473
+ * })
1474
+ * secureSchema.parse("password123") // ✗ Invalid (common password)
1475
+ * secureSchema.parse("aaa123") // ✗ Invalid (repeating characters)
1476
+ * secureSchema.parse("abc123") // ✗ Invalid (sequential characters)
1477
+ *
1478
+ * // Custom requirements
1479
+ * const customSchema = password(false, {
1480
+ * min: 8,
1481
+ * includes: "@", // Must contain @
1482
+ * excludes: ["admin", "user"], // Cannot contain these words
1483
+ * regex: /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)/ // Custom pattern
1484
+ * })
1485
+ *
1486
+ * // Minimum strength requirement
1487
+ * const strengthSchema = password(false, { minStrength: "very-strong" })
1488
+ * strengthSchema.parse("weak") // ✗ Invalid (insufficient strength)
1489
+ * strengthSchema.parse("MyVeryStr0ng!P@ssw0rd2024") // ✓ Valid
1490
+ *
1491
+ * // Optional with default
1492
+ * const optionalSchema = password(false, {
1493
+ * defaultValue: null
1494
+ * })
1495
+ * ```
1496
+ *
1497
+ * @throws {z.ZodError} When validation fails with specific error messages
1498
+ * @see {@link PasswordOptions} for all available configuration options
1499
+ * @see {@link PasswordStrength} for strength level definitions
1500
+ * @see {@link calculatePasswordStrength} for strength calculation logic
1501
+ */
1502
+ declare function password<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<PasswordOptions<IsRequired>, 'required'>): PasswordSchema<IsRequired>;
1503
+
1504
+ /**
1505
+ * @fileoverview Text validator for Zod Kit
1506
+ *
1507
+ * Provides comprehensive text validation with length constraints, content validation,
1508
+ * flexible trimming and casing options, and advanced transformation features.
1509
+ *
1510
+ * @author Ong Hoe Yuan
1511
+ * @version 0.0.5
1512
+ */
217
1513
 
1514
+ /**
1515
+ * Type definition for text validation error messages
1516
+ *
1517
+ * @interface TextMessages
1518
+ * @property {string} [required] - Message when field is required but empty
1519
+ * @property {string} [notEmpty] - Message when field must not be empty (whitespace-only)
1520
+ * @property {string} [minLength] - Message when text is shorter than minimum length
1521
+ * @property {string} [maxLength] - Message when text exceeds maximum length
1522
+ * @property {string} [startsWith] - Message when text doesn't start with required string
1523
+ * @property {string} [endsWith] - Message when text doesn't end with required string
1524
+ * @property {string} [includes] - Message when text doesn't contain required string
1525
+ * @property {string} [excludes] - Message when text contains forbidden string
1526
+ * @property {string} [invalid] - Message when text doesn't match regex pattern
1527
+ */
218
1528
  type TextMessages = {
219
1529
  required?: string;
220
1530
  notEmpty?: string;
@@ -226,8 +1536,28 @@ type TextMessages = {
226
1536
  excludes?: string;
227
1537
  invalid?: string;
228
1538
  };
1539
+ /**
1540
+ * Configuration options for text validation
1541
+ *
1542
+ * @template IsRequired - Whether the field is required (affects return type)
1543
+ *
1544
+ * @interface TextOptions
1545
+ * @property {IsRequired} [required=true] - Whether the field is required
1546
+ * @property {number} [minLength] - Minimum length of text
1547
+ * @property {number} [maxLength] - Maximum length of text
1548
+ * @property {string} [startsWith] - String that text must start with
1549
+ * @property {string} [endsWith] - String that text must end with
1550
+ * @property {string} [includes] - String that must be included in text
1551
+ * @property {string | string[]} [excludes] - String(s) that must not be included
1552
+ * @property {RegExp} [regex] - Regular expression pattern for validation
1553
+ * @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
1554
+ * @property {"upper" | "lower" | "title" | "none"} [casing="none"] - Case transformation
1555
+ * @property {Function} [transform] - Custom transformation function for text
1556
+ * @property {boolean} [notEmpty] - Whether to reject whitespace-only strings
1557
+ * @property {string | null} [defaultValue] - Default value when input is empty
1558
+ * @property {Record<Locale, TextMessages>} [i18n] - Custom error messages for different locales
1559
+ */
229
1560
  type TextOptions<IsRequired extends boolean = true> = {
230
- required?: IsRequired;
231
1561
  minLength?: number;
232
1562
  maxLength?: number;
233
1563
  startsWith?: string;
@@ -242,9 +1572,384 @@ type TextOptions<IsRequired extends boolean = true> = {
242
1572
  defaultValue?: IsRequired extends true ? string : string | null;
243
1573
  i18n?: Record<Locale, TextMessages>;
244
1574
  };
1575
+ /**
1576
+ * Type alias for text validation schema based on required flag
1577
+ *
1578
+ * @template IsRequired - Whether the field is required
1579
+ * @typedef TextSchema
1580
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
1581
+ */
245
1582
  type TextSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
246
- declare function text<IsRequired extends boolean = true>(options?: TextOptions<IsRequired>): TextSchema<IsRequired>;
1583
+ /**
1584
+ * Creates a Zod schema for text validation with comprehensive string processing
1585
+ *
1586
+ * @template IsRequired - Whether the field is required (affects return type)
1587
+ * @param {TextOptions<IsRequired>} [options] - Configuration options for text validation
1588
+ * @returns {TextSchema<IsRequired>} Zod schema for text validation
1589
+ *
1590
+ * @description
1591
+ * Creates a comprehensive text validator with length constraints, content validation,
1592
+ * flexible trimming and casing options, and advanced transformation features.
1593
+ *
1594
+ * Features:
1595
+ * - Length validation (min/max)
1596
+ * - Content validation (startsWith, endsWith, includes, excludes)
1597
+ * - Regular expression pattern matching
1598
+ * - Flexible trimming options (trim, trimStart, trimEnd, none)
1599
+ * - Case transformation (upper, lower, title, none)
1600
+ * - Empty string vs whitespace-only validation
1601
+ * - Custom transformation functions
1602
+ * - Comprehensive internationalization
1603
+ *
1604
+ * @example
1605
+ * ```typescript
1606
+ * // Basic text validation (optional by default)
1607
+ * const basicSchema = text()
1608
+ * basicSchema.parse("Hello World") // ✓ Valid
1609
+ * basicSchema.parse(null) // ✓ Valid (optional)
1610
+ *
1611
+ * // Required text
1612
+ * const requiredSchema = text(true)
1613
+ * requiredSchema.parse("Hello") // ✓ Valid
1614
+ * requiredSchema.parse(null) // ✗ Invalid (required)
1615
+ *
1616
+ * // Length constraints
1617
+ * const lengthSchema = text(true, { minLength: 3, maxLength: 50 })
1618
+ * lengthSchema.parse("Hello") // ✓ Valid
1619
+ * lengthSchema.parse("Hi") // ✗ Invalid (too short)
1620
+ *
1621
+ * // Content validation
1622
+ * const contentSchema = text(true, {
1623
+ * startsWith: "Hello",
1624
+ * endsWith: "!",
1625
+ * includes: "World"
1626
+ * })
1627
+ * contentSchema.parse("Hello World!") // ✓ Valid
1628
+ *
1629
+ * // Case transformation
1630
+ * const upperSchema = text(false, { casing: "upper" })
1631
+ * upperSchema.parse("hello") // ✓ Valid (converted to "HELLO")
1632
+ *
1633
+ * // Trim modes
1634
+ * const trimStartSchema = text(false, { trimMode: "trimStart" })
1635
+ * trimStartSchema.parse(" hello ") // ✓ Valid (result: "hello ")
1636
+ *
1637
+ * // Regex validation
1638
+ * const regexSchema = text(true, { regex: /^[a-zA-Z]+$/ })
1639
+ * regexSchema.parse("hello") // ✓ Valid
1640
+ * regexSchema.parse("hello123") // ✗ Invalid
1641
+ *
1642
+ * // Not empty (rejects whitespace-only)
1643
+ * const notEmptySchema = text(true, { notEmpty: true })
1644
+ * notEmptySchema.parse("hello") // ✓ Valid
1645
+ * notEmptySchema.parse(" ") // ✗ Invalid
1646
+ *
1647
+ * // Optional with default
1648
+ * const optionalSchema = text(false, { defaultValue: "default text" })
1649
+ * ```
1650
+ *
1651
+ * @throws {z.ZodError} When validation fails with specific error messages
1652
+ * @see {@link TextOptions} for all available configuration options
1653
+ */
1654
+ declare function text<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TextOptions<IsRequired>, 'required'>): TextSchema<IsRequired>;
1655
+
1656
+ /**
1657
+ * @fileoverview Time validator for Zod Kit
1658
+ *
1659
+ * Provides comprehensive time validation with support for multiple time formats,
1660
+ * hour/minute constraints, and advanced time-based validation options.
1661
+ *
1662
+ * @author Ong Hoe Yuan
1663
+ * @version 0.0.5
1664
+ */
1665
+
1666
+ /**
1667
+ * Type definition for time validation error messages
1668
+ *
1669
+ * @interface TimeMessages
1670
+ * @property {string} [required] - Message when field is required but empty
1671
+ * @property {string} [invalid] - Message when time format is invalid
1672
+ * @property {string} [format] - Message when time doesn't match expected format
1673
+ * @property {string} [min] - Message when time is before minimum allowed
1674
+ * @property {string} [max] - Message when time is after maximum allowed
1675
+ * @property {string} [hour] - Message when hour is outside allowed range
1676
+ * @property {string} [minute] - Message when minute doesn't match step requirement
1677
+ * @property {string} [second] - Message when second doesn't match step requirement
1678
+ * @property {string} [includes] - Message when time doesn't contain required string
1679
+ * @property {string} [excludes] - Message when time contains forbidden string
1680
+ * @property {string} [customRegex] - Message when custom regex validation fails
1681
+ * @property {string} [notInWhitelist] - Message when value is not in whitelist
1682
+ */
1683
+ type TimeMessages = {
1684
+ required?: string;
1685
+ invalid?: string;
1686
+ format?: string;
1687
+ min?: string;
1688
+ max?: string;
1689
+ hour?: string;
1690
+ minute?: string;
1691
+ second?: string;
1692
+ includes?: string;
1693
+ excludes?: string;
1694
+ customRegex?: string;
1695
+ notInWhitelist?: string;
1696
+ };
1697
+ /**
1698
+ * Supported time formats for validation
1699
+ *
1700
+ * @typedef {string} TimeFormat
1701
+ *
1702
+ * Available formats:
1703
+ * - HH:mm: 24-hour format with leading zeros (14:30, 09:30)
1704
+ * - HH:mm:ss: 24-hour format with seconds (14:30:45, 09:30:15)
1705
+ * - hh:mm A: 12-hour format with AM/PM (02:30 PM, 09:30 AM)
1706
+ * - hh:mm:ss A: 12-hour format with seconds and AM/PM (02:30:45 PM)
1707
+ * - H:mm: 24-hour format without leading zeros (14:30, 9:30)
1708
+ * - h:mm A: 12-hour format without leading zeros (2:30 PM, 9:30 AM)
1709
+ */
1710
+ type TimeFormat = "HH:mm" | "HH:mm:ss" | "hh:mm A" | "hh:mm:ss A" | "H:mm" | "h:mm A";
1711
+ /**
1712
+ * Configuration options for time validation
1713
+ *
1714
+ * @template IsRequired - Whether the field is required (affects return type)
1715
+ *
1716
+ * @interface TimeOptions
1717
+ * @property {IsRequired} [required=true] - Whether the field is required
1718
+ * @property {TimeFormat} [format="HH:mm"] - Expected time format
1719
+ * @property {string} [min] - Minimum allowed time (e.g., "09:00")
1720
+ * @property {string} [max] - Maximum allowed time (e.g., "17:00")
1721
+ * @property {number} [minHour] - Minimum allowed hour (0-23)
1722
+ * @property {number} [maxHour] - Maximum allowed hour (0-23)
1723
+ * @property {number[]} [allowedHours] - Specific hours that are allowed
1724
+ * @property {number} [minuteStep] - Required minute intervals (e.g., 15 for :00, :15, :30, :45)
1725
+ * @property {number} [secondStep] - Required second intervals
1726
+ * @property {string} [includes] - String that must be included in the time
1727
+ * @property {string | string[]} [excludes] - String(s) that must not be included
1728
+ * @property {RegExp} [regex] - Custom regex for validation (overrides format validation)
1729
+ * @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
1730
+ * @property {"upper" | "lower" | "none"} [casing="none"] - Case transformation
1731
+ * @property {string[]} [whitelist] - Specific time strings that are always allowed
1732
+ * @property {boolean} [whitelistOnly=false] - If true, only values in whitelist are allowed
1733
+ * @property {Function} [transform] - Custom transformation function applied before validation
1734
+ * @property {string | null} [defaultValue] - Default value when input is empty
1735
+ * @property {Record<Locale, TimeMessages>} [i18n] - Custom error messages for different locales
1736
+ */
1737
+ type TimeOptions<IsRequired extends boolean = true> = {
1738
+ format?: TimeFormat;
1739
+ min?: string;
1740
+ max?: string;
1741
+ minHour?: number;
1742
+ maxHour?: number;
1743
+ allowedHours?: number[];
1744
+ minuteStep?: number;
1745
+ secondStep?: number;
1746
+ includes?: string;
1747
+ excludes?: string | string[];
1748
+ regex?: RegExp;
1749
+ trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
1750
+ casing?: "upper" | "lower" | "none";
1751
+ whitelist?: string[];
1752
+ whitelistOnly?: boolean;
1753
+ transform?: (value: string) => string;
1754
+ defaultValue?: IsRequired extends true ? string : string | null;
1755
+ i18n?: Record<Locale, TimeMessages>;
1756
+ };
1757
+ /**
1758
+ * Type alias for time validation schema based on required flag
1759
+ *
1760
+ * @template IsRequired - Whether the field is required
1761
+ * @typedef TimeSchema
1762
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
1763
+ */
1764
+ type TimeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
1765
+ /**
1766
+ * Regular expression patterns for time format validation
1767
+ *
1768
+ * @constant {Record<TimeFormat, RegExp>} TIME_PATTERNS
1769
+ * @description Maps each supported time format to its corresponding regex pattern
1770
+ */
1771
+ declare const TIME_PATTERNS: Record<TimeFormat, RegExp>;
1772
+ /**
1773
+ * Parses a time string to minutes since midnight for comparison
1774
+ *
1775
+ * @param {string} timeStr - The time string to parse
1776
+ * @param {TimeFormat} format - The expected time format
1777
+ * @returns {number | null} Minutes since midnight (0-1439) or null if parsing fails
1778
+ *
1779
+ * @description
1780
+ * Converts time strings to minutes since midnight for easy comparison and validation.
1781
+ * Handles both 12-hour and 24-hour formats with proper AM/PM conversion.
1782
+ *
1783
+ * @example
1784
+ * ```typescript
1785
+ * parseTimeToMinutes("14:30", "HH:mm") // 870 (14*60 + 30)
1786
+ * parseTimeToMinutes("2:30 PM", "h:mm A") // 870 (14*60 + 30)
1787
+ * parseTimeToMinutes("12:00 AM", "hh:mm A") // 0 (midnight)
1788
+ * parseTimeToMinutes("12:00 PM", "hh:mm A") // 720 (noon)
1789
+ * ```
1790
+ */
1791
+ declare const parseTimeToMinutes: (timeStr: string, format: TimeFormat) => number | null;
1792
+ /**
1793
+ * Validates if a time string matches the specified format pattern
1794
+ *
1795
+ * @param {string} value - The time string to validate
1796
+ * @param {TimeFormat} format - The expected time format
1797
+ * @returns {boolean} True if the time matches the format pattern
1798
+ *
1799
+ * @description
1800
+ * Performs regex pattern matching to validate time format.
1801
+ * Does not validate actual time values (e.g., 25:00 would pass pattern but fail logic).
1802
+ *
1803
+ * @example
1804
+ * ```typescript
1805
+ * validateTimeFormat("14:30", "HH:mm") // true
1806
+ * validateTimeFormat("2:30 PM", "h:mm A") // true
1807
+ * validateTimeFormat("25:00", "HH:mm") // true (pattern matches)
1808
+ * validateTimeFormat("14:30", "h:mm A") // false (wrong format)
1809
+ * ```
1810
+ */
1811
+ declare const validateTimeFormat: (value: string, format: TimeFormat) => boolean;
1812
+ /**
1813
+ * Normalizes time to 24-hour format for internal processing
1814
+ *
1815
+ * @param {string} timeStr - The time string to normalize
1816
+ * @param {TimeFormat} format - The current time format
1817
+ * @returns {string | null} Normalized time string or null if parsing fails
1818
+ *
1819
+ * @description
1820
+ * Converts time strings to a standardized 24-hour format for consistent processing.
1821
+ * Handles AM/PM conversion and leading zero normalization.
1822
+ *
1823
+ * @example
1824
+ * ```typescript
1825
+ * normalizeTime("2:30 PM", "h:mm A") // "14:30"
1826
+ * normalizeTime("12:00 AM", "hh:mm A") // "00:00"
1827
+ * normalizeTime("9:30", "H:mm") // "09:30"
1828
+ * normalizeTime("14:30:45", "HH:mm:ss") // "14:30:45"
1829
+ * ```
1830
+ */
1831
+ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | null;
1832
+ /**
1833
+ * Creates a Zod schema for time validation with comprehensive options
1834
+ *
1835
+ * @template IsRequired - Whether the field is required (affects return type)
1836
+ * @param {IsRequired} [required=false] - Whether the field is required
1837
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
1838
+ * @returns {TimeSchema<IsRequired>} Zod schema for time validation
1839
+ *
1840
+ * @description
1841
+ * Creates a comprehensive time validator that supports multiple time formats,
1842
+ * hour/minute constraints, step validation, and extensive customization options.
1843
+ *
1844
+ * Features:
1845
+ * - Multiple time formats (24-hour, 12-hour, with/without seconds)
1846
+ * - Time range validation (min/max)
1847
+ * - Hour and minute constraints
1848
+ * - Step validation (e.g., 15-minute intervals)
1849
+ * - Whitelist/blacklist support
1850
+ * - Custom regex patterns
1851
+ * - String transformation and case handling
1852
+ * - Comprehensive internationalization
1853
+ *
1854
+ * @example
1855
+ * ```typescript
1856
+ * // Basic time validation (24-hour format)
1857
+ * const basicSchema = time()
1858
+ * basicSchema.parse("14:30") // ✓ Valid
1859
+ * basicSchema.parse(null) // ✓ Valid (optional)
1860
+ *
1861
+ * // Required validation
1862
+ * const requiredSchema = parse("14:30") // ✓ Valid
1863
+ (true)
1864
+ * requiredSchema.parse(null) // ✗ Invalid (required)
1865
+ *
1866
+ * basicSchema.parse("2:30 PM") // ✗ Invalid (wrong format)
1867
+ *
1868
+ * // 12-hour format with AM/PM
1869
+ * const ampmSchema = time(false, { format: "hh:mm A" })
1870
+ * ampmSchema.parse("02:30 PM") // ✓ Valid
1871
+ * ampmSchema.parse("14:30") // ✗ Invalid (wrong format)
1872
+ *
1873
+ * // Business hours validation
1874
+ * const businessHours = time({
1875
+ * format: "HH:mm",
1876
+ * minHour: 9,
1877
+ * maxHour: 17,
1878
+ * minuteStep: 15 // Only :00, :15, :30, :45
1879
+ * })
1880
+ * businessHours.parse("09:15") // ✓ Valid
1881
+ * businessHours.parse("18:00") // ✗ Invalid (after maxHour)
1882
+ * businessHours.parse("09:05") // ✗ Invalid (not 15-minute step)
1883
+ *
1884
+ * // Time range validation
1885
+ * const timeRangeSchema = time(false, {
1886
+ * min: "09:00",
1887
+ * max: "17:00"
1888
+ * })
1889
+ * timeRangeSchema.parse("12:30") // ✓ Valid
1890
+ * timeRangeSchema.parse("08:00") // ✗ Invalid (before min)
1891
+ *
1892
+ * // Allowed hours only
1893
+ * const specificHours = time({
1894
+ * allowedHours: [9, 12, 15, 18]
1895
+ * })
1896
+ * specificHours.parse("12:30") // ✓ Valid
1897
+ * specificHours.parse("11:30") // ✗ Invalid (hour not allowed)
1898
+ *
1899
+ * // Whitelist specific times
1900
+ * const whitelistSchema = time(false, {
1901
+ * whitelist: ["09:00", "12:00", "17:00"],
1902
+ * whitelistOnly: true
1903
+ * })
1904
+ * whitelistSchema.parse("12:00") // ✓ Valid (in whitelist)
1905
+ * whitelistSchema.parse("13:00") // ✗ Invalid (not in whitelist)
1906
+ *
1907
+ * // Optional with default
1908
+ * const optionalSchema = time(false, {
1909
+ * defaultValue: "09:00"
1910
+ * })
1911
+ * optionalSchema.parse("") // ✓ Valid (returns "09:00")
1912
+ * ```
1913
+ *
1914
+ * @throws {z.ZodError} When validation fails with specific error messages
1915
+ * @see {@link TimeOptions} for all available configuration options
1916
+ * @see {@link TimeFormat} for supported time formats
1917
+ */
1918
+ declare function time<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TimeOptions<IsRequired>, 'required'>): TimeSchema<IsRequired>;
1919
+
1920
+ /**
1921
+ * @fileoverview URL validator for Zod Kit
1922
+ *
1923
+ * Provides comprehensive URL validation with protocol filtering, domain control,
1924
+ * port validation, path constraints, and localhost handling.
1925
+ *
1926
+ * @author Ong Hoe Yuan
1927
+ * @version 0.0.5
1928
+ */
247
1929
 
1930
+ /**
1931
+ * Type definition for URL validation error messages
1932
+ *
1933
+ * @interface UrlMessages
1934
+ * @property {string} [required] - Message when field is required but empty
1935
+ * @property {string} [invalid] - Message when URL format is invalid
1936
+ * @property {string} [min] - Message when URL is too short
1937
+ * @property {string} [max] - Message when URL is too long
1938
+ * @property {string} [includes] - Message when URL doesn't contain required string
1939
+ * @property {string} [excludes] - Message when URL contains forbidden string
1940
+ * @property {string} [protocol] - Message when protocol is not allowed
1941
+ * @property {string} [domain] - Message when domain is not allowed
1942
+ * @property {string} [domainBlacklist] - Message when domain is blacklisted
1943
+ * @property {string} [port] - Message when port is not allowed
1944
+ * @property {string} [pathStartsWith] - Message when path doesn't start with required string
1945
+ * @property {string} [pathEndsWith] - Message when path doesn't end with required string
1946
+ * @property {string} [hasQuery] - Message when query parameters are required
1947
+ * @property {string} [noQuery] - Message when query parameters are forbidden
1948
+ * @property {string} [hasFragment] - Message when fragment is required
1949
+ * @property {string} [noFragment] - Message when fragment is forbidden
1950
+ * @property {string} [localhost] - Message when localhost is forbidden
1951
+ * @property {string} [noLocalhost] - Message when localhost is required
1952
+ */
248
1953
  type UrlMessages = {
249
1954
  required?: string;
250
1955
  invalid?: string;
@@ -265,8 +1970,35 @@ type UrlMessages = {
265
1970
  localhost?: string;
266
1971
  noLocalhost?: string;
267
1972
  };
1973
+ /**
1974
+ * Configuration options for URL validation
1975
+ *
1976
+ * @template IsRequired - Whether the field is required (affects return type)
1977
+ *
1978
+ * @interface UrlOptions
1979
+ * @property {IsRequired} [required=true] - Whether the field is required
1980
+ * @property {number} [min] - Minimum length of URL
1981
+ * @property {number} [max] - Maximum length of URL
1982
+ * @property {string} [includes] - String that must be included in URL
1983
+ * @property {string | string[]} [excludes] - String(s) that must not be included
1984
+ * @property {string[]} [protocols] - Allowed protocols (e.g., ["https", "http"])
1985
+ * @property {string[]} [allowedDomains] - Domains that are allowed
1986
+ * @property {string[]} [blockedDomains] - Domains that are blocked
1987
+ * @property {number[]} [allowedPorts] - Ports that are allowed
1988
+ * @property {number[]} [blockedPorts] - Ports that are blocked
1989
+ * @property {string} [pathStartsWith] - Path must start with this string
1990
+ * @property {string} [pathEndsWith] - Path must end with this string
1991
+ * @property {boolean} [mustHaveQuery] - Whether URL must have query parameters
1992
+ * @property {boolean} [mustNotHaveQuery] - Whether URL must not have query parameters
1993
+ * @property {boolean} [mustHaveFragment] - Whether URL must have fragment
1994
+ * @property {boolean} [mustNotHaveFragment] - Whether URL must not have fragment
1995
+ * @property {boolean} [allowLocalhost=true] - Whether to allow localhost URLs
1996
+ * @property {boolean} [blockLocalhost] - Whether to explicitly block localhost URLs
1997
+ * @property {Function} [transform] - Custom transformation function for URL strings
1998
+ * @property {string | null} [defaultValue] - Default value when input is empty
1999
+ * @property {Record<Locale, UrlMessages>} [i18n] - Custom error messages for different locales
2000
+ */
268
2001
  type UrlOptions<IsRequired extends boolean = true> = {
269
- required?: IsRequired;
270
2002
  min?: number;
271
2003
  max?: number;
272
2004
  includes?: string;
@@ -288,89 +2020,1120 @@ type UrlOptions<IsRequired extends boolean = true> = {
288
2020
  defaultValue?: IsRequired extends true ? string : string | null;
289
2021
  i18n?: Record<Locale, UrlMessages>;
290
2022
  };
2023
+ /**
2024
+ * Type alias for URL validation schema based on required flag
2025
+ *
2026
+ * @template IsRequired - Whether the field is required
2027
+ * @typedef UrlSchema
2028
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
2029
+ */
291
2030
  type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
292
- declare function url<IsRequired extends boolean = true>(options?: UrlOptions<IsRequired>): UrlSchema<IsRequired>;
2031
+ /**
2032
+ * Creates a Zod schema for URL validation with comprehensive constraints
2033
+ *
2034
+ * @template IsRequired - Whether the field is required (affects return type)
2035
+ * @param {IsRequired} [required=false] - Whether the field is required
2036
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
2037
+ * @returns {UrlSchema<IsRequired>} Zod schema for URL validation
2038
+ *
2039
+ * @description
2040
+ * Creates a comprehensive URL validator with protocol filtering, domain control,
2041
+ * port validation, path constraints, and localhost handling.
2042
+ *
2043
+ * Features:
2044
+ * - RFC-compliant URL format validation
2045
+ * - Protocol whitelist/blacklist (http, https, ftp, etc.)
2046
+ * - Domain whitelist/blacklist with subdomain support
2047
+ * - Port validation and filtering
2048
+ * - Path prefix/suffix validation
2049
+ * - Query parameter requirements
2050
+ * - Fragment requirements
2051
+ * - Localhost detection and control
2052
+ * - Length validation
2053
+ * - Content inclusion/exclusion
2054
+ * - Custom transformation functions
2055
+ * - Comprehensive internationalization
2056
+ *
2057
+ * @example
2058
+ * ```typescript
2059
+ * // Basic URL validation
2060
+ * const basicSchema = url() // optional by default
2061
+ * basicSchema.parse("https://example.com") // ✓ Valid
2062
+ * basicSchema.parse(null) // ✓ Valid (optional)
2063
+ *
2064
+ * // Required validation
2065
+ * const requiredSchema = parse("https://example.com") // ✓ Valid
2066
+ (true)
2067
+ * requiredSchema.parse(null) // ✗ Invalid (required)
2068
+ *
2069
+ *
2070
+ * // HTTPS only
2071
+ * const httpsSchema = url(false, { protocols: ["https"] })
2072
+ * httpsSchema.parse("https://example.com") // ✓ Valid
2073
+ * httpsSchema.parse("http://example.com") // ✗ Invalid
2074
+ *
2075
+ * // Domain restriction
2076
+ * const domainSchema = url(false, {
2077
+ * allowedDomains: ["company.com", "trusted.org"]
2078
+ * })
2079
+ * domainSchema.parse("https://app.company.com") // ✓ Valid (subdomain)
2080
+ * domainSchema.parse("https://example.com") // ✗ Invalid
2081
+ *
2082
+ * // Block localhost
2083
+ * const noLocalhostSchema = url(false, { blockLocalhost: true })
2084
+ * noLocalhostSchema.parse("https://example.com") // ✓ Valid
2085
+ * noLocalhostSchema.parse("http://localhost:3000") // ✗ Invalid
2086
+ *
2087
+ * // API endpoints with path requirements
2088
+ * const apiSchema = url(false, {
2089
+ * pathStartsWith: "/api/",
2090
+ * mustHaveQuery: true
2091
+ * })
2092
+ * apiSchema.parse("https://api.com/api/users?page=1") // ✓ Valid
2093
+ *
2094
+ * // Port restrictions
2095
+ * const portSchema = url(false, {
2096
+ * allowedPorts: [80, 443, 8080]
2097
+ * })
2098
+ * portSchema.parse("https://example.com:443") // ✓ Valid
2099
+ * portSchema.parse("https://example.com:3000") // ✗ Invalid
2100
+ *
2101
+ * // Optional with default
2102
+ * const optionalSchema = url(false, {
2103
+ * defaultValue: null
2104
+ * })
2105
+ * ```
2106
+ *
2107
+ * @throws {z.ZodError} When validation fails with specific error messages
2108
+ * @see {@link UrlOptions} for all available configuration options
2109
+ */
2110
+ declare function url<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<UrlOptions<IsRequired>, 'required'>): UrlSchema<IsRequired>;
2111
+
2112
+ /**
2113
+ * @fileoverview Taiwan Business ID (統一編號) validator for Zod Kit
2114
+ *
2115
+ * Provides validation for Taiwan Business Identification Numbers (統一編號) with
2116
+ * support for both new (2023+) and legacy validation rules.
2117
+ *
2118
+ * @author Ong Hoe Yuan
2119
+ * @version 0.0.5
2120
+ */
293
2121
 
2122
+ /**
2123
+ * Type definition for business ID validation error messages
2124
+ *
2125
+ * @interface BusinessIdMessages
2126
+ * @property {string} [required] - Message when field is required but empty
2127
+ * @property {string} [invalid] - Message when business ID format or checksum is invalid
2128
+ */
294
2129
  type BusinessIdMessages = {
295
2130
  required?: string;
296
2131
  invalid?: string;
297
2132
  };
2133
+ /**
2134
+ * Configuration options for Taiwan business ID validation
2135
+ *
2136
+ * @template IsRequired - Whether the field is required (affects return type)
2137
+ *
2138
+ * @interface BusinessIdOptions
2139
+ * @property {IsRequired} [required=true] - Whether the field is required
2140
+ * @property {Function} [transform] - Custom transformation function for business ID
2141
+ * @property {string | null} [defaultValue] - Default value when input is empty
2142
+ * @property {Record<Locale, BusinessIdMessages>} [i18n] - Custom error messages for different locales
2143
+ */
298
2144
  type BusinessIdOptions<IsRequired extends boolean = true> = {
299
- required?: IsRequired;
300
2145
  transform?: (value: string) => string;
301
2146
  defaultValue?: IsRequired extends true ? string : string | null;
302
2147
  i18n?: Record<Locale, BusinessIdMessages>;
303
2148
  };
2149
+ /**
2150
+ * Type alias for business ID validation schema based on required flag
2151
+ *
2152
+ * @template IsRequired - Whether the field is required
2153
+ * @typedef BusinessIdSchema
2154
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
2155
+ */
304
2156
  type BusinessIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
2157
+ /**
2158
+ * Validates Taiwan Business Identification Number (統一編號)
2159
+ *
2160
+ * @param {string} value - The business ID to validate
2161
+ * @returns {boolean} True if the business ID is valid
2162
+ *
2163
+ * @description
2164
+ * Validates Taiwan Business ID using both new (2023+) and legacy validation rules.
2165
+ * The validation includes format checking (8 digits) and checksum verification.
2166
+ *
2167
+ * Validation rules:
2168
+ * 1. Must be exactly 8 digits
2169
+ * 2. Weighted sum calculation using coefficients [1,2,1,2,1,2,4] for first 7 digits
2170
+ * 3. New rules (2023+): Sum + 8th digit must be divisible by 5
2171
+ * 4. Legacy rules: Sum + 8th digit must be divisible by 10
2172
+ * 5. Special case: If 7th digit is 7, try alternative calculation with +1
2173
+ *
2174
+ * @example
2175
+ * ```typescript
2176
+ * validateTaiwanBusinessId("12345675") // true (if valid checksum)
2177
+ * validateTaiwanBusinessId("1234567") // false (not 8 digits)
2178
+ * validateTaiwanBusinessId("abcd1234") // false (not all digits)
2179
+ * ```
2180
+ */
305
2181
  declare const validateTaiwanBusinessId: (value: string) => boolean;
306
- declare function businessId<IsRequired extends boolean = true>(options?: BusinessIdOptions<IsRequired>): BusinessIdSchema<IsRequired>;
2182
+ /**
2183
+ * Creates a Zod schema for Taiwan Business ID validation
2184
+ *
2185
+ * @template IsRequired - Whether the field is required (affects return type)
2186
+ * @param {BusinessIdOptions<IsRequired>} [options] - Configuration options for business ID validation
2187
+ * @returns {BusinessIdSchema<IsRequired>} Zod schema for business ID validation
2188
+ *
2189
+ * @description
2190
+ * Creates a comprehensive Taiwan Business ID validator that validates the format
2191
+ * and checksum according to Taiwan government specifications.
2192
+ *
2193
+ * Features:
2194
+ * - 8-digit format validation
2195
+ * - Checksum verification (supports both new 2023+ and legacy rules)
2196
+ * - Automatic trimming and preprocessing
2197
+ * - Custom transformation functions
2198
+ * - Comprehensive internationalization
2199
+ * - Optional field support
2200
+ *
2201
+ * @example
2202
+ * ```typescript
2203
+ * // Basic business ID validation
2204
+ * const basicSchema = businessId() // optional by default
2205
+ * basicSchema.parse("12345675") // ✓ Valid (if checksum correct)
2206
+ * basicSchema.parse(null) // ✓ Valid (optional)
2207
+ *
2208
+ * // Required validation
2209
+ * const requiredSchema = parse("12345675") // ✓ Valid (if checksum correct)
2210
+ (true)
2211
+ * requiredSchema.parse(null) // ✗ Invalid (required)
2212
+ *
2213
+ * basicSchema.parse("1234567") // ✗ Invalid (not 8 digits)
2214
+ *
2215
+ * // Optional business ID
2216
+ * const optionalSchema = businessId(false)
2217
+ * optionalSchema.parse("") // ✓ Valid (returns null)
2218
+ * optionalSchema.parse("12345675") // ✓ Valid (if checksum correct)
2219
+ *
2220
+ * // With custom transformation
2221
+ * const transformSchema = businessId(false, {
2222
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
2223
+ * })
2224
+ * transformSchema.parse("1234-5675") // ✓ Valid (if checksum correct after cleaning)
2225
+ *
2226
+ * // With custom error messages
2227
+ * const customSchema = businessId(false, {
2228
+ * i18n: {
2229
+ * en: { invalid: "Please enter a valid Taiwan Business ID" },
2230
+ * 'zh-TW': { invalid: "請輸入有效的統一編號" }
2231
+ * }
2232
+ * })
2233
+ * ```
2234
+ *
2235
+ * @throws {z.ZodError} When validation fails with specific error messages
2236
+ * @see {@link BusinessIdOptions} for all available configuration options
2237
+ * @see {@link validateTaiwanBusinessId} for validation logic details
2238
+ */
2239
+ declare function businessId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<BusinessIdOptions<IsRequired>, 'required'>): BusinessIdSchema<IsRequired>;
307
2240
 
2241
+ /**
2242
+ * @fileoverview Taiwan National ID (身分證/居留證) validator for Zod Kit
2243
+ *
2244
+ * Provides validation for Taiwan National ID cards (身分證) and
2245
+ * Resident Certificates (居留證) with support for both old and new formats.
2246
+ *
2247
+ * @author Ong Hoe Yuan
2248
+ * @version 0.0.5
2249
+ */
2250
+
2251
+ /**
2252
+ * Type definition for national ID validation error messages
2253
+ *
2254
+ * @interface NationalIdMessages
2255
+ * @property {string} [required] - Message when field is required but empty
2256
+ * @property {string} [invalid] - Message when national ID format or checksum is invalid
2257
+ */
308
2258
  type NationalIdMessages = {
309
2259
  required?: string;
310
2260
  invalid?: string;
311
2261
  };
2262
+ /**
2263
+ * Types of Taiwan national identification documents
2264
+ *
2265
+ * @typedef {"citizen" | "resident" | "both"} NationalIdType
2266
+ *
2267
+ * Available types:
2268
+ * - citizen: National ID card (身分證字號) for Taiwan citizens
2269
+ * - resident: Resident certificate (居留證號) for foreign residents
2270
+ * - both: Accept both citizen and resident IDs
2271
+ */
312
2272
  type NationalIdType = "citizen" | "resident" | "both";
2273
+ /**
2274
+ * Configuration options for Taiwan national ID validation
2275
+ *
2276
+ * @template IsRequired - Whether the field is required (affects return type)
2277
+ *
2278
+ * @interface NationalIdOptions
2279
+ * @property {IsRequired} [required=true] - Whether the field is required
2280
+ * @property {NationalIdType} [type="both"] - Type of ID to accept
2281
+ * @property {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
2282
+ * @property {Function} [transform] - Custom transformation function for ID
2283
+ * @property {string | null} [defaultValue] - Default value when input is empty
2284
+ * @property {Record<Locale, NationalIdMessages>} [i18n] - Custom error messages for different locales
2285
+ */
313
2286
  type NationalIdOptions<IsRequired extends boolean = true> = {
314
- required?: IsRequired;
315
2287
  type?: NationalIdType;
316
2288
  allowOldResident?: boolean;
317
2289
  transform?: (value: string) => string;
318
2290
  defaultValue?: IsRequired extends true ? string : string | null;
319
2291
  i18n?: Record<Locale, NationalIdMessages>;
320
2292
  };
2293
+ /**
2294
+ * Type alias for national ID validation schema based on required flag
2295
+ *
2296
+ * @template IsRequired - Whether the field is required
2297
+ * @typedef NationalIdSchema
2298
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
2299
+ */
321
2300
  type NationalIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
2301
+ /**
2302
+ * Validates Taiwan citizen national ID card (身分證字號)
2303
+ *
2304
+ * @param {string} value - The citizen ID to validate
2305
+ * @returns {boolean} True if the citizen ID is valid
2306
+ *
2307
+ * @description
2308
+ * Validates Taiwan citizen ID format: 1 letter + 1 gender digit (1-2) + 8 digits
2309
+ * Uses checksum algorithm with city code conversion and weighted sum.
2310
+ *
2311
+ * Format: [A-Z][1-2]XXXXXXXX
2312
+ * - First letter: City/county code
2313
+ * - Second digit: Gender (1=male, 2=female)
2314
+ * - Last 8 digits: Serial number + checksum
2315
+ *
2316
+ * @example
2317
+ * ```typescript
2318
+ * validateCitizenId("A123456789") // true/false based on checksum
2319
+ * validateCitizenId("A323456789") // false (invalid gender digit)
2320
+ * ```
2321
+ */
322
2322
  declare const validateCitizenId: (value: string) => boolean;
2323
+ /**
2324
+ * Validates old-style Taiwan resident certificate (舊式居留證號)
2325
+ *
2326
+ * @param {string} value - The old-style resident ID to validate
2327
+ * @returns {boolean} True if the old-style resident ID is valid
2328
+ *
2329
+ * @description
2330
+ * Validates old-style resident ID format: 1 letter + 1 gender letter + 8 digits
2331
+ * Uses checksum algorithm with city code and gender code conversion.
2332
+ *
2333
+ * Format: [A-Z][ABCD]XXXXXXXX
2334
+ * - First letter: City/county code
2335
+ * - Second letter: Gender code (A/C=male, B/D=female)
2336
+ * - Last 8 digits: Serial number + checksum
2337
+ *
2338
+ * @example
2339
+ * ```typescript
2340
+ * validateOldResidentId("AA12345678") // true/false based on checksum
2341
+ * validateOldResidentId("AE12345678") // false (invalid gender letter)
2342
+ * ```
2343
+ */
323
2344
  declare const validateOldResidentId: (value: string) => boolean;
2345
+ /**
2346
+ * Validates new-style Taiwan resident certificate (新式居留證號)
2347
+ *
2348
+ * @param {string} value - The new-style resident ID to validate
2349
+ * @returns {boolean} True if the new-style resident ID is valid
2350
+ *
2351
+ * @description
2352
+ * Validates new-style resident ID format: 1 letter + 1 type digit + 8 digits
2353
+ * Uses the same checksum algorithm as citizen IDs.
2354
+ *
2355
+ * Format: [A-Z][89]XXXXXXXX
2356
+ * - First letter: City/county code
2357
+ * - Second digit: Type indicator (8 or 9)
2358
+ * - Last 8 digits: Serial number + checksum
2359
+ *
2360
+ * @example
2361
+ * ```typescript
2362
+ * validateNewResidentId("A812345678") // true/false based on checksum
2363
+ * validateNewResidentId("A712345678") // false (invalid type digit)
2364
+ * ```
2365
+ */
324
2366
  declare const validateNewResidentId: (value: string) => boolean;
2367
+ /**
2368
+ * Main validation function for Taiwan national IDs
2369
+ *
2370
+ * @param {string} value - The national ID to validate
2371
+ * @param {NationalIdType} [type="both"] - Type of ID to accept
2372
+ * @param {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
2373
+ * @returns {boolean} True if the national ID is valid
2374
+ *
2375
+ * @description
2376
+ * Validates Taiwan national IDs based on the specified type and options.
2377
+ * Supports citizen IDs, resident certificates (both old and new styles).
2378
+ *
2379
+ * @example
2380
+ * ```typescript
2381
+ * validateTaiwanNationalId("A123456789", "citizen") // Citizen ID only
2382
+ * validateTaiwanNationalId("A812345678", "resident") // Resident ID only
2383
+ * validateTaiwanNationalId("A123456789", "both") // Accept any valid format
2384
+ * validateTaiwanNationalId("AA12345678", "both", false) // Reject old resident format
2385
+ * ```
2386
+ */
325
2387
  declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, allowOldResident?: boolean) => boolean;
326
- declare function nationalId<IsRequired extends boolean = true>(options?: NationalIdOptions<IsRequired>): NationalIdSchema<IsRequired>;
2388
+ /**
2389
+ * Creates a Zod schema for Taiwan National ID validation
2390
+ *
2391
+ * @template IsRequired - Whether the field is required (affects return type)
2392
+ * @param {NationalIdOptions<IsRequired>} [options] - Configuration options for national ID validation
2393
+ * @returns {NationalIdSchema<IsRequired>} Zod schema for national ID validation
2394
+ *
2395
+ * @description
2396
+ * Creates a comprehensive Taiwan National ID validator that supports both
2397
+ * citizen IDs and resident certificates with configurable validation rules.
2398
+ *
2399
+ * Features:
2400
+ * - Citizen ID validation (身分證字號)
2401
+ * - Resident certificate validation (居留證號, old and new formats)
2402
+ * - Configurable ID type acceptance
2403
+ * - Automatic case conversion to uppercase
2404
+ * - Checksum verification
2405
+ * - Custom transformation functions
2406
+ * - Comprehensive internationalization
2407
+ * - Optional field support
2408
+ *
2409
+ * @example
2410
+ * ```typescript
2411
+ * // Accept any valid Taiwan ID
2412
+ * const anyIdSchema = nationalId()
2413
+ * anyIdSchema.parse("A123456789") // ✓ Valid citizen ID
2414
+ * anyIdSchema.parse("A812345678") // ✓ Valid new resident ID
2415
+ * anyIdSchema.parse("AA12345678") // ✓ Valid old resident ID
2416
+ *
2417
+ * // Citizen IDs only
2418
+ * const citizenSchema = nationalId(false, { type: "citizen" })
2419
+ * citizenSchema.parse("A123456789") // ✓ Valid
2420
+ * citizenSchema.parse("A812345678") // ✗ Invalid (resident ID)
2421
+ *
2422
+ * // Resident IDs only (new format only)
2423
+ * const residentSchema = nationalId(false, {
2424
+ * type: "resident",
2425
+ * allowOldResident: false
2426
+ * })
2427
+ * residentSchema.parse("A812345678") // ✓ Valid
2428
+ * residentSchema.parse("AA12345678") // ✗ Invalid (old format)
2429
+ *
2430
+ * // Optional with custom transformation
2431
+ * const optionalSchema = nationalId(false, {
2432
+ * transform: (value) => value.replace(/[^A-Z0-9]/g, '') // Remove special chars
2433
+ * })
2434
+ *
2435
+ * // With custom error messages
2436
+ * const customSchema = nationalId(false, {
2437
+ * i18n: {
2438
+ * en: { invalid: "Please enter a valid Taiwan National ID" },
2439
+ * 'zh-TW': { invalid: "請輸入有效的身分證或居留證號碼" }
2440
+ * }
2441
+ * })
2442
+ * ```
2443
+ *
2444
+ * @throws {z.ZodError} When validation fails with specific error messages
2445
+ * @see {@link NationalIdOptions} for all available configuration options
2446
+ * @see {@link NationalIdType} for supported ID types
2447
+ * @see {@link validateTaiwanNationalId} for validation logic details
2448
+ */
2449
+ declare function nationalId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NationalIdOptions<IsRequired>, 'required'>): NationalIdSchema<IsRequired>;
2450
+
2451
+ /**
2452
+ * @fileoverview Taiwan Mobile Phone Number validator for Zod Kit
2453
+ *
2454
+ * Provides validation for Taiwan mobile phone numbers with support for
2455
+ * all Taiwan mobile network operators and whitelist functionality.
2456
+ *
2457
+ * @author Ong Hoe Yuan
2458
+ * @version 0.0.5
2459
+ */
327
2460
 
2461
+ /**
2462
+ * Type definition for mobile phone validation error messages
2463
+ *
2464
+ * @interface MobileMessages
2465
+ * @property {string} [required] - Message when field is required but empty
2466
+ * @property {string} [invalid] - Message when mobile number format is invalid
2467
+ * @property {string} [notInWhitelist] - Message when mobile number is not in whitelist
2468
+ */
328
2469
  type MobileMessages = {
329
2470
  required?: string;
330
2471
  invalid?: string;
331
2472
  notInWhitelist?: string;
332
2473
  };
2474
+ /**
2475
+ * Configuration options for Taiwan mobile phone validation
2476
+ *
2477
+ * @template IsRequired - Whether the field is required (affects return type)
2478
+ *
2479
+ * @interface MobileOptions
2480
+ * @property {IsRequired} [required=true] - Whether the field is required
2481
+ * @property {string[]} [whitelist] - Array of specific mobile numbers that are always allowed
2482
+ * @property {Function} [transform] - Custom transformation function for mobile number
2483
+ * @property {string | null} [defaultValue] - Default value when input is empty
2484
+ * @property {Record<Locale, MobileMessages>} [i18n] - Custom error messages for different locales
2485
+ */
333
2486
  type MobileOptions<IsRequired extends boolean = true> = {
334
- required?: IsRequired;
335
2487
  whitelist?: string[];
336
2488
  transform?: (value: string) => string;
337
2489
  defaultValue?: IsRequired extends true ? string : string | null;
338
2490
  i18n?: Record<Locale, MobileMessages>;
339
2491
  };
2492
+ /**
2493
+ * Type alias for mobile phone validation schema based on required flag
2494
+ *
2495
+ * @template IsRequired - Whether the field is required
2496
+ * @typedef MobileSchema
2497
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
2498
+ */
340
2499
  type MobileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
2500
+ /**
2501
+ * Validates Taiwan mobile phone number format
2502
+ *
2503
+ * @param {string} value - The mobile phone number to validate
2504
+ * @returns {boolean} True if the mobile number is valid
2505
+ *
2506
+ * @description
2507
+ * Validates Taiwan mobile phone numbers according to the official numbering plan.
2508
+ * Taiwan mobile numbers use the format: 09X-XXXX-XXXX (10 digits total).
2509
+ *
2510
+ * Valid prefixes: 090, 091, 092, 093, 094, 095, 096, 097, 098, 099
2511
+ * - All major Taiwan mobile operators are covered
2512
+ * - Format: 09[0-9] followed by 7 additional digits
2513
+ *
2514
+ * @example
2515
+ * ```typescript
2516
+ * validateTaiwanMobile("0912345678") // true
2517
+ * validateTaiwanMobile("0987654321") // true
2518
+ * validateTaiwanMobile("0812345678") // false (invalid prefix)
2519
+ * validateTaiwanMobile("091234567") // false (too short)
2520
+ * ```
2521
+ */
341
2522
  declare const validateTaiwanMobile: (value: string) => boolean;
342
- declare function mobile<IsRequired extends boolean = true>(options?: MobileOptions<IsRequired>): MobileSchema<IsRequired>;
2523
+ /**
2524
+ * Creates a Zod schema for Taiwan mobile phone number validation
2525
+ *
2526
+ * @template IsRequired - Whether the field is required (affects return type)
2527
+ * @param {IsRequired} [required=false] - Whether the field is required
2528
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
2529
+ * @returns {MobileSchema<IsRequired>} Zod schema for mobile phone validation
2530
+ *
2531
+ * @description
2532
+ * Creates a comprehensive Taiwan mobile phone number validator with support for
2533
+ * all Taiwan mobile network operators and optional whitelist functionality.
2534
+ *
2535
+ * Features:
2536
+ * - Taiwan mobile number format validation (09X-XXXX-XXXX)
2537
+ * - Support for all Taiwan mobile operators (090-099 prefixes)
2538
+ * - Whitelist functionality for specific allowed numbers
2539
+ * - Automatic trimming and preprocessing
2540
+ * - Custom transformation functions
2541
+ * - Comprehensive internationalization
2542
+ * - Optional field support
2543
+ *
2544
+ * @example
2545
+ * ```typescript
2546
+ * // Basic mobile number validation
2547
+ * const basicSchema = mobile() // optional by default
2548
+ * basicSchema.parse("0912345678") // ✓ Valid
2549
+ * basicSchema.parse(null) // ✓ Valid (optional)
2550
+ *
2551
+ * // Required validation
2552
+ * const requiredSchema = parse("0912345678") // ✓ Valid
2553
+ (true)
2554
+ * requiredSchema.parse(null) // ✗ Invalid (required)
2555
+ *
2556
+ * basicSchema.parse("0987654321") // ✓ Valid
2557
+ * basicSchema.parse("0812345678") // ✗ Invalid (wrong prefix)
2558
+ *
2559
+ * // With whitelist (only specific numbers allowed)
2560
+ * const whitelistSchema = mobile(false, {
2561
+ * whitelist: ["0912345678", "0987654321"]
2562
+ * })
2563
+ * whitelistSchema.parse("0912345678") // ✓ Valid (in whitelist)
2564
+ * whitelistSchema.parse("0911111111") // ✗ Invalid (not in whitelist)
2565
+ *
2566
+ * // Optional mobile number
2567
+ * const optionalSchema = mobile(false)
2568
+ * optionalSchema.parse("") // ✓ Valid (returns null)
2569
+ * optionalSchema.parse("0912345678") // ✓ Valid
2570
+ *
2571
+ * // With custom transformation
2572
+ * const transformSchema = mobile(false, {
2573
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
2574
+ * })
2575
+ * transformSchema.parse("091-234-5678") // ✓ Valid (formatted input)
2576
+ * transformSchema.parse("091 234 5678") // ✓ Valid (spaced input)
2577
+ *
2578
+ * // With custom error messages
2579
+ * const customSchema = mobile(false, {
2580
+ * i18n: {
2581
+ * en: { invalid: "Please enter a valid Taiwan mobile number" },
2582
+ * 'zh-TW': { invalid: "請輸入有效的台灣手機號碼" }
2583
+ * }
2584
+ * })
2585
+ * ```
2586
+ *
2587
+ * @throws {z.ZodError} When validation fails with specific error messages
2588
+ * @see {@link MobileOptions} for all available configuration options
2589
+ * @see {@link validateTaiwanMobile} for validation logic details
2590
+ */
2591
+ declare function mobile<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<MobileOptions<IsRequired>, 'required'>): MobileSchema<IsRequired>;
343
2592
 
2593
+ /**
2594
+ * @fileoverview Taiwan Postal Code validator for Zod Kit
2595
+ *
2596
+ * Provides comprehensive validation for Taiwan postal codes with support for
2597
+ * 3-digit, 5-digit (legacy), and 6-digit (current) formats based on official
2598
+ * Chunghwa Post specifications.
2599
+ *
2600
+ * @author Ong Hoe Yuan
2601
+ * @version 0.0.5
2602
+ */
2603
+
2604
+ /**
2605
+ * Type definition for postal code validation error messages
2606
+ *
2607
+ * @interface PostalCodeMessages
2608
+ * @property {string} [required] - Message when field is required but empty
2609
+ * @property {string} [invalid] - Message when postal code format is invalid
2610
+ * @property {string} [invalidFormat] - Message when format doesn't match expected pattern
2611
+ * @property {string} [invalidRange] - Message when postal code is outside valid range
2612
+ * @property {string} [legacy5DigitWarning] - Warning message for 5-digit legacy format
2613
+ * @property {string} [format3Only] - Message when only 3-digit format is allowed
2614
+ * @property {string} [format5Only] - Message when only 5-digit format is allowed
2615
+ * @property {string} [format6Only] - Message when only 6-digit format is allowed
2616
+ */
2617
+ type PostalCodeMessages = {
2618
+ required?: string;
2619
+ invalid?: string;
2620
+ invalidFormat?: string;
2621
+ invalidRange?: string;
2622
+ legacy5DigitWarning?: string;
2623
+ format3Only?: string;
2624
+ format5Only?: string;
2625
+ format6Only?: string;
2626
+ invalidSuffix?: string;
2627
+ deprecated5Digit?: string;
2628
+ };
2629
+ /**
2630
+ * Postal code format types supported in Taiwan
2631
+ *
2632
+ * @typedef {"3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all"} PostalCodeFormat
2633
+ *
2634
+ * Available formats:
2635
+ * - "3": 3-digit basic postal codes (100-982)
2636
+ * - "5": 5-digit postal codes (3+2 format, legacy)
2637
+ * - "6": 6-digit postal codes (3+3 format, current standard)
2638
+ * - "3+5": Accept both 3-digit and 5-digit formats
2639
+ * - "3+6": Accept both 3-digit and 6-digit formats (recommended)
2640
+ * - "5+6": Accept both 5-digit and 6-digit formats
2641
+ * - "all": Accept all formats (3, 5, and 6 digits)
2642
+ */
2643
+ type PostalCodeFormat = "3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all";
2644
+ /**
2645
+ * Configuration options for Taiwan postal code validation
2646
+ *
2647
+ * @template IsRequired - Whether the field is required (affects return type)
2648
+ *
2649
+ * @interface PostalCodeOptions
2650
+ * @property {IsRequired} [required=true] - Whether the field is required
2651
+ * @property {PostalCodeFormat} [format="3+6"] - Which postal code formats to accept
2652
+ * @property {boolean} [strictValidation=true] - Enable strict validation against known postal code ranges
2653
+ * @property {boolean} [allowDashes=true] - Whether to allow dashes in postal codes (e.g., "100-01" or "100-001")
2654
+ * @property {boolean} [warn5Digit=true] - Whether to show warning for 5-digit legacy format
2655
+ * @property {string[]} [allowedPrefixes] - Specific 3-digit prefixes to allow (if strictValidation is true)
2656
+ * @property {string[]} [blockedPrefixes] - Specific 3-digit prefixes to block
2657
+ * @property {Function} [transform] - Custom transformation function for postal codes
2658
+ * @property {string | null} [defaultValue] - Default value when input is empty
2659
+ * @property {Record<Locale, PostalCodeMessages>} [i18n] - Custom error messages for different locales
2660
+ */
2661
+ type PostalCodeOptions<IsRequired extends boolean = true> = {
2662
+ format?: PostalCodeFormat;
2663
+ strictValidation?: boolean;
2664
+ allowDashes?: boolean;
2665
+ warn5Digit?: boolean;
2666
+ allowedPrefixes?: string[];
2667
+ blockedPrefixes?: string[];
2668
+ transform?: (value: string) => string;
2669
+ defaultValue?: IsRequired extends true ? string : string | null;
2670
+ i18n?: Record<Locale, PostalCodeMessages>;
2671
+ strictSuffixValidation?: boolean;
2672
+ deprecate5Digit?: boolean;
2673
+ };
2674
+ /**
2675
+ * Type alias for postal code validation schema based on required flag
2676
+ *
2677
+ * @template IsRequired - Whether the field is required
2678
+ * @typedef PostalCodeSchema
2679
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
2680
+ */
2681
+ type PostalCodeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
2682
+ /**
2683
+ * Valid 3-digit postal code prefixes for Taiwan
2684
+ * Based on official Chunghwa Post data (2024)
2685
+ */
2686
+ declare const VALID_3_DIGIT_PREFIXES: string[];
2687
+ /**
2688
+ * Validates 3-digit Taiwan postal code
2689
+ *
2690
+ * @param {string} value - The 3-digit postal code to validate
2691
+ * @param {boolean} strictValidation - Whether to validate against known postal code list
2692
+ * @param {string[]} allowedPrefixes - Specific prefixes to allow (overrides strictValidation)
2693
+ * @param {string[]} blockedPrefixes - Specific prefixes to block
2694
+ * @returns {boolean} True if the postal code is valid
2695
+ */
2696
+ declare const validate3DigitPostalCode: (value: string, strictValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
2697
+ /**
2698
+ * Validates 5-digit Taiwan postal code (legacy format)
2699
+ *
2700
+ * @param {string} value - The 5-digit postal code to validate
2701
+ * @param {boolean} strictValidation - Whether to validate the 3-digit prefix
2702
+ * @param {boolean} strictSuffixValidation - Whether to validate the 2-digit suffix
2703
+ * @param {string[]} allowedPrefixes - Specific prefixes to allow
2704
+ * @param {string[]} blockedPrefixes - Specific prefixes to block
2705
+ * @returns {boolean} True if the postal code is valid
2706
+ */
2707
+ declare const validate5DigitPostalCode: (value: string, strictValidation?: boolean, strictSuffixValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
2708
+ /**
2709
+ * Validates 6-digit Taiwan postal code (current format)
2710
+ *
2711
+ * @param {string} value - The 6-digit postal code to validate
2712
+ * @param {boolean} strictValidation - Whether to validate the 3-digit prefix
2713
+ * @param {boolean} strictSuffixValidation - Whether to validate the 3-digit suffix
2714
+ * @param {string[]} allowedPrefixes - Specific prefixes to allow
2715
+ * @param {string[]} blockedPrefixes - Specific prefixes to block
2716
+ * @returns {boolean} True if the postal code is valid
2717
+ */
2718
+ declare const validate6DigitPostalCode: (value: string, strictValidation?: boolean, strictSuffixValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
2719
+ /**
2720
+ * Main validation function for Taiwan postal codes
2721
+ *
2722
+ * @param {string} value - The postal code to validate
2723
+ * @param {PostalCodeFormat} format - Which formats to accept
2724
+ * @param {boolean} strictValidation - Whether to validate against known postal codes
2725
+ * @param {boolean} strictSuffixValidation - Whether to validate suffix ranges
2726
+ * @param {boolean} allowDashes - Whether dashes/spaces are allowed and should be removed
2727
+ * @param {string[]} allowedPrefixes - Specific prefixes to allow
2728
+ * @param {string[]} blockedPrefixes - Specific prefixes to block
2729
+ * @returns {boolean} True if the postal code is valid
2730
+ */
2731
+ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeFormat, strictValidation?: boolean, strictSuffixValidation?: boolean, allowDashes?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
2732
+ /**
2733
+ * Creates a Zod schema for Taiwan postal code validation
2734
+ *
2735
+ * @template IsRequired - Whether the field is required (affects return type)
2736
+ * @param {PostalCodeOptions<IsRequired>} [options] - Configuration options for postal code validation
2737
+ * @returns {PostalCodeSchema<IsRequired>} Zod schema for postal code validation
2738
+ *
2739
+ * @description
2740
+ * Creates a comprehensive Taiwan postal code validator that supports multiple formats
2741
+ * and provides extensive configuration options for different validation scenarios.
2742
+ *
2743
+ * Features:
2744
+ * - 3-digit, 5-digit, and 6-digit postal code format support
2745
+ * - Strict validation against official postal code ranges
2746
+ * - Legacy 5-digit format with optional warnings
2747
+ * - Custom prefix allowlist/blocklist support
2748
+ * - Dash and space handling in postal codes
2749
+ * - Automatic normalization and formatting
2750
+ * - Custom transformation functions
2751
+ * - Comprehensive internationalization
2752
+ * - Optional field support
2753
+ *
2754
+ * @example
2755
+ * ```typescript
2756
+ * // Accept 3-digit or 6-digit formats (recommended)
2757
+ * const modernSchema = postalCode()
2758
+ * modernSchema.parse("100") // ✓ Valid 3-digit
2759
+ * modernSchema.parse("100001") // ✓ Valid 6-digit
2760
+ * modernSchema.parse("10001") // ✗ Invalid (5-digit not allowed)
2761
+ *
2762
+ * // Accept all formats
2763
+ * const flexibleSchema = postalCode(false, { format: "all" })
2764
+ * flexibleSchema.parse("100") // ✓ Valid
2765
+ * flexibleSchema.parse("10001") // ✓ Valid
2766
+ * flexibleSchema.parse("100001") // ✓ Valid
2767
+ *
2768
+ * // Only 6-digit format (current standard)
2769
+ * const modernOnlySchema = postalCode(false, { format: "6" })
2770
+ * modernOnlySchema.parse("100001") // ✓ Valid
2771
+ * modernOnlySchema.parse("100") // ✗ Invalid
2772
+ *
2773
+ * // With dashes allowed
2774
+ * const dashSchema = postalCode(false, { allowDashes: true })
2775
+ * dashSchema.parse("100-001") // ✓ Valid (normalized to "100001")
2776
+ * dashSchema.parse("100-01") // ✓ Valid if 5-digit format allowed
2777
+ *
2778
+ * // Specific areas only
2779
+ * const taipeiSchema = postalCode(false, {
2780
+ * allowedPrefixes: ["100", "103", "104", "105", "106"]
2781
+ * })
2782
+ * taipeiSchema.parse("100001") // ✓ Valid (Taipei area)
2783
+ * taipeiSchema.parse("200001") // ✗ Invalid (not in allowlist)
2784
+ *
2785
+ * // Block specific areas
2786
+ * const blockedSchema = postalCode(false, {
2787
+ * blockedPrefixes: ["999"] // Block test codes
2788
+ * })
2789
+ *
2790
+ * // With warning for legacy format
2791
+ * const warnSchema = postalCode(false, {
2792
+ * format: "all",
2793
+ * warn5Digit: true
2794
+ * })
2795
+ * // Will validate but may show warning for 5-digit codes
2796
+ *
2797
+ * // Optional with custom transformation
2798
+ * const optionalSchema = postalCode(false, {
2799
+ * transform: (value) => value.replace(/\D/g, '') // Remove non-digits
2800
+ * })
2801
+ *
2802
+ * // Strict suffix validation for real postal codes
2803
+ * const strictSchema = postalCode(false, {
2804
+ * format: "6",
2805
+ * strictSuffixValidation: true // Validates suffix range 001-999
2806
+ * })
2807
+ * strictSchema.parse("100001") // ✓ Valid
2808
+ * strictSchema.parse("100000") // ✗ Invalid (suffix 000 not allowed)
2809
+ *
2810
+ * // Deprecate 5-digit codes entirely
2811
+ * const modern2024Schema = postalCode(false, {
2812
+ * format: "all",
2813
+ * deprecate5Digit: true // Throws error for any 5-digit code
2814
+ * })
2815
+ * modern2024Schema.parse("100001") // ✓ Valid 6-digit
2816
+ * modern2024Schema.parse("10001") // ✗ Error: deprecated format
2817
+ * ```
2818
+ *
2819
+ * @throws {z.ZodError} When validation fails with specific error messages
2820
+ * @see {@link PostalCodeOptions} for all available configuration options
2821
+ * @see {@link PostalCodeFormat} for supported formats
2822
+ * @see {@link validateTaiwanPostalCode} for validation logic details
2823
+ */
2824
+ declare function postalCode<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<PostalCodeOptions<IsRequired>, 'required'>): PostalCodeSchema<IsRequired>;
2825
+
2826
+ /**
2827
+ * @fileoverview Taiwan Landline Telephone Number validator for Zod Kit
2828
+ *
2829
+ * Provides validation for Taiwan landline telephone numbers according to the
2830
+ * official 2024 telecom numbering plan with comprehensive area code support.
2831
+ *
2832
+ * @author Ong Hoe Yuan
2833
+ * @version 0.0.5
2834
+ */
2835
+
2836
+ /**
2837
+ * Type definition for telephone validation error messages
2838
+ *
2839
+ * @interface TelMessages
2840
+ * @property {string} [required] - Message when field is required but empty
2841
+ * @property {string} [invalid] - Message when telephone number format is invalid
2842
+ * @property {string} [notInWhitelist] - Message when telephone number is not in whitelist
2843
+ */
344
2844
  type TelMessages = {
345
2845
  required?: string;
346
2846
  invalid?: string;
347
2847
  notInWhitelist?: string;
348
2848
  };
2849
+ /**
2850
+ * Configuration options for Taiwan landline telephone validation
2851
+ *
2852
+ * @template IsRequired - Whether the field is required (affects return type)
2853
+ *
2854
+ * @interface TelOptions
2855
+ * @property {IsRequired} [required=true] - Whether the field is required
2856
+ * @property {string[]} [whitelist] - Array of specific telephone numbers that are always allowed
2857
+ * @property {Function} [transform] - Custom transformation function for telephone number
2858
+ * @property {string | null} [defaultValue] - Default value when input is empty
2859
+ * @property {Record<Locale, TelMessages>} [i18n] - Custom error messages for different locales
2860
+ */
349
2861
  type TelOptions<IsRequired extends boolean = true> = {
350
- required?: IsRequired;
351
2862
  whitelist?: string[];
352
2863
  transform?: (value: string) => string;
353
2864
  defaultValue?: IsRequired extends true ? string : string | null;
354
2865
  i18n?: Record<Locale, TelMessages>;
355
2866
  };
2867
+ /**
2868
+ * Type alias for telephone validation schema based on required flag
2869
+ *
2870
+ * @template IsRequired - Whether the field is required
2871
+ * @typedef TelSchema
2872
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
2873
+ */
356
2874
  type TelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
2875
+ /**
2876
+ * Validates Taiwan landline telephone number format (Official 2024 rules)
2877
+ *
2878
+ * @param {string} value - The telephone number to validate
2879
+ * @returns {boolean} True if the telephone number is valid
2880
+ *
2881
+ * @description
2882
+ * Validates Taiwan landline telephone numbers according to the official 2024
2883
+ * telecom numbering plan. Supports all Taiwan area codes and their specific
2884
+ * number patterns.
2885
+ *
2886
+ * Supported area codes and formats:
2887
+ * - 02: Taipei, New Taipei, Keelung - 8 digits (2&3&5~8+7D)
2888
+ * - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
2889
+ * - 037: Miaoli - 6 digits (2~9+5D)
2890
+ * - 04: Taichung, Changhua - 7 digits
2891
+ * - 049: Nantou - 7 digits (2~9+6D)
2892
+ * - 05: Yunlin, Chiayi - 7 digits
2893
+ * - 06: Tainan - 7 digits
2894
+ * - 07: Kaohsiung - 7 digits (2~9+6D)
2895
+ * - 08: Pingtung - 7 digits (4&7&8+6D)
2896
+ * - 082: Kinmen - 6 digits (2~5&7~9+5D)
2897
+ * - 0826: Wuqiu - 5 digits (6+4D)
2898
+ * - 0836: Matsu - 5 digits (2~9+4D)
2899
+ * - 089: Taitung - 6 digits (2~9+5D)
2900
+ *
2901
+ * @example
2902
+ * ```typescript
2903
+ * validateTaiwanTel("0223456789") // true (Taipei area)
2904
+ * validateTaiwanTel("0312345678") // true (Taoyuan area)
2905
+ * validateTaiwanTel("037234567") // true (Miaoli area)
2906
+ * validateTaiwanTel("082234567") // true (Kinmen area)
2907
+ * validateTaiwanTel("02-2345-6789") // true (with separators)
2908
+ * validateTaiwanTel("0812345678") // false (invalid for 08 area)
2909
+ * ```
2910
+ */
357
2911
  declare const validateTaiwanTel: (value: string) => boolean;
358
- declare function tel<IsRequired extends boolean = true>(options?: TelOptions<IsRequired>): TelSchema<IsRequired>;
2912
+ /**
2913
+ * Creates a Zod schema for Taiwan landline telephone number validation
2914
+ *
2915
+ * @template IsRequired - Whether the field is required (affects return type)
2916
+ * @param {IsRequired} [required=false] - Whether the field is required
2917
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
2918
+ * @returns {TelSchema<IsRequired>} Zod schema for telephone number validation
2919
+ *
2920
+ * @description
2921
+ * Creates a comprehensive Taiwan landline telephone number validator with support for
2922
+ * all Taiwan area codes according to the official 2024 telecom numbering plan.
2923
+ *
2924
+ * Features:
2925
+ * - Complete Taiwan area code support (02, 03, 037, 04, 049, 05, 06, 07, 08, 082, 0826, 0836, 089)
2926
+ * - Automatic separator handling (hyphens and spaces)
2927
+ * - Area-specific number length and pattern validation
2928
+ * - Whitelist functionality for specific allowed numbers
2929
+ * - Automatic trimming and preprocessing
2930
+ * - Custom transformation functions
2931
+ * - Comprehensive internationalization
2932
+ * - Optional field support
2933
+ *
2934
+ * @example
2935
+ * ```typescript
2936
+ * // Basic telephone number validation
2937
+ * const basicSchema = tel() // optional by default
2938
+ * basicSchema.parse("0223456789") // ✓ Valid (Taipei)
2939
+ * basicSchema.parse(null) // ✓ Valid (optional)
2940
+ *
2941
+ * // Required validation
2942
+ * const requiredSchema = parse("0223456789") // ✓ Valid (Taipei)
2943
+ (true)
2944
+ * requiredSchema.parse(null) // ✗ Invalid (required)
2945
+ *
2946
+ * basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
2947
+ * basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
2948
+ * basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
2949
+ *
2950
+ * // With whitelist (only specific numbers allowed)
2951
+ * const whitelistSchema = tel(false, {
2952
+ * whitelist: ["0223456789", "0312345678"]
2953
+ * })
2954
+ * whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
2955
+ * whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
2956
+ *
2957
+ * // Optional telephone number
2958
+ * const optionalSchema = tel(false)
2959
+ * optionalSchema.parse("") // ✓ Valid (returns null)
2960
+ * optionalSchema.parse("0223456789") // ✓ Valid
2961
+ *
2962
+ * // With custom transformation (remove separators)
2963
+ * const transformSchema = tel(false, {
2964
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
2965
+ * })
2966
+ * transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
2967
+ * transformSchema.parse("02 2345 6789") // ✓ Valid (spaces removed)
2968
+ *
2969
+ * // With custom error messages
2970
+ * const customSchema = tel(false, {
2971
+ * i18n: {
2972
+ * en: { invalid: "Please enter a valid Taiwan landline number" },
2973
+ * 'zh-TW': { invalid: "請輸入有效的台灣市話號碼" }
2974
+ * }
2975
+ * })
2976
+ * ```
2977
+ *
2978
+ * @throws {z.ZodError} When validation fails with specific error messages
2979
+ * @see {@link TelOptions} for all available configuration options
2980
+ * @see {@link validateTaiwanTel} for validation logic details
2981
+ */
2982
+ declare function tel<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TelOptions<IsRequired>, 'required'>): TelSchema<IsRequired>;
2983
+
2984
+ /**
2985
+ * @fileoverview Taiwan Fax Number validator for Zod Kit
2986
+ *
2987
+ * Provides validation for Taiwan fax numbers according to the official 2024
2988
+ * telecom numbering plan. Uses the same format as landline telephone numbers.
2989
+ *
2990
+ * @author Ong Hoe Yuan
2991
+ * @version 0.0.5
2992
+ */
359
2993
 
2994
+ /**
2995
+ * Type definition for fax number validation error messages
2996
+ *
2997
+ * @interface FaxMessages
2998
+ * @property {string} [required] - Message when field is required but empty
2999
+ * @property {string} [invalid] - Message when fax number format is invalid
3000
+ * @property {string} [notInWhitelist] - Message when fax number is not in whitelist
3001
+ */
360
3002
  type FaxMessages = {
361
3003
  required?: string;
362
3004
  invalid?: string;
363
3005
  notInWhitelist?: string;
364
3006
  };
3007
+ /**
3008
+ * Configuration options for Taiwan fax number validation
3009
+ *
3010
+ * @template IsRequired - Whether the field is required (affects return type)
3011
+ *
3012
+ * @interface FaxOptions
3013
+ * @property {IsRequired} [required=true] - Whether the field is required
3014
+ * @property {string[]} [whitelist] - Array of specific fax numbers that are always allowed
3015
+ * @property {Function} [transform] - Custom transformation function for fax number
3016
+ * @property {string | null} [defaultValue] - Default value when input is empty
3017
+ * @property {Record<Locale, FaxMessages>} [i18n] - Custom error messages for different locales
3018
+ */
365
3019
  type FaxOptions<IsRequired extends boolean = true> = {
366
- required?: IsRequired;
367
3020
  whitelist?: string[];
368
3021
  transform?: (value: string) => string;
369
3022
  defaultValue?: IsRequired extends true ? string : string | null;
370
3023
  i18n?: Record<Locale, FaxMessages>;
371
3024
  };
3025
+ /**
3026
+ * Type alias for fax number validation schema based on required flag
3027
+ *
3028
+ * @template IsRequired - Whether the field is required
3029
+ * @typedef FaxSchema
3030
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
3031
+ */
372
3032
  type FaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
3033
+ /**
3034
+ * Validates Taiwan fax number format (Official 2024 rules - same as landline)
3035
+ *
3036
+ * @param {string} value - The fax number to validate
3037
+ * @returns {boolean} True if the fax number is valid
3038
+ *
3039
+ * @description
3040
+ * Validates Taiwan fax numbers according to the official 2024 telecom numbering plan.
3041
+ * Fax numbers follow the same format as landline telephone numbers in Taiwan.
3042
+ *
3043
+ * Supported area codes and formats (same as landline):
3044
+ * - 02: Taipei, New Taipei, Keelung - 8 digits (2&3&5~8+7D)
3045
+ * - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7 digits
3046
+ * - 037: Miaoli - 6 digits (2~9+5D)
3047
+ * - 04: Taichung, Changhua - 7 digits
3048
+ * - 049: Nantou - 7 digits (2~9+6D)
3049
+ * - 05: Yunlin, Chiayi - 7 digits
3050
+ * - 06: Tainan - 7 digits
3051
+ * - 07: Kaohsiung - 7 digits (2~9+6D)
3052
+ * - 08: Pingtung - 7 digits (4&7&8+6D)
3053
+ * - 082: Kinmen - 6 digits (2~5&7~9+5D)
3054
+ * - 0826: Wuqiu - 5 digits (6+4D)
3055
+ * - 0836: Matsu - 5 digits (2~9+4D)
3056
+ * - 089: Taitung - 6 digits (2~9+5D)
3057
+ *
3058
+ * @example
3059
+ * ```typescript
3060
+ * validateTaiwanFax("0223456789") // true (Taipei area)
3061
+ * validateTaiwanFax("0312345678") // true (Taoyuan area)
3062
+ * validateTaiwanFax("037234567") // true (Miaoli area)
3063
+ * validateTaiwanFax("02-2345-6789") // true (with separators)
3064
+ * validateTaiwanFax("0812345678") // false (invalid for 08 area)
3065
+ * ```
3066
+ */
373
3067
  declare const validateTaiwanFax: (value: string) => boolean;
374
- declare function fax<IsRequired extends boolean = true>(options?: FaxOptions<IsRequired>): FaxSchema<IsRequired>;
3068
+ /**
3069
+ * Creates a Zod schema for Taiwan fax number validation
3070
+ *
3071
+ * @template IsRequired - Whether the field is required (affects return type)
3072
+ * @param {IsRequired} [required=false] - Whether the field is required
3073
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
3074
+ * @returns {FaxSchema<IsRequired>} Zod schema for fax number validation
3075
+ *
3076
+ * @description
3077
+ * Creates a comprehensive Taiwan fax number validator with support for all Taiwan
3078
+ * area codes. Fax numbers follow the same format as landline telephone numbers.
3079
+ *
3080
+ * Features:
3081
+ * - Complete Taiwan area code support (same as landline)
3082
+ * - Automatic separator handling (hyphens and spaces)
3083
+ * - Area-specific number length and pattern validation
3084
+ * - Whitelist functionality for specific allowed numbers
3085
+ * - Automatic trimming and preprocessing
3086
+ * - Custom transformation functions
3087
+ * - Comprehensive internationalization
3088
+ * - Optional field support
3089
+ *
3090
+ * @example
3091
+ * ```typescript
3092
+ * // Basic fax number validation
3093
+ * const basicSchema = fax() // optional by default
3094
+ * basicSchema.parse("0223456789") // ✓ Valid (Taipei)
3095
+ * basicSchema.parse(null) // ✓ Valid (optional)
3096
+ *
3097
+ * // Required validation
3098
+ * const requiredSchema = parse("0223456789") // ✓ Valid (Taipei)
3099
+ (true)
3100
+ * requiredSchema.parse(null) // ✗ Invalid (required)
3101
+ *
3102
+ * basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
3103
+ * basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
3104
+ * basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
3105
+ *
3106
+ * // With whitelist (only specific numbers allowed)
3107
+ * const whitelistSchema = fax(false, {
3108
+ * whitelist: ["0223456789", "0312345678"]
3109
+ * })
3110
+ * whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
3111
+ * whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
3112
+ *
3113
+ * // Optional fax number
3114
+ * const optionalSchema = fax(false)
3115
+ * optionalSchema.parse("") // ✓ Valid (returns null)
3116
+ * optionalSchema.parse("0223456789") // ✓ Valid
3117
+ *
3118
+ * // With custom transformation
3119
+ * const transformSchema = fax(false, {
3120
+ * transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
3121
+ * })
3122
+ * transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
3123
+ *
3124
+ * // With custom error messages
3125
+ * const customSchema = fax(false, {
3126
+ * i18n: {
3127
+ * en: { invalid: "Please enter a valid Taiwan fax number" },
3128
+ * 'zh-TW': { invalid: "請輸入有效的台灣傳真號碼" }
3129
+ * }
3130
+ * })
3131
+ * ```
3132
+ *
3133
+ * @throws {z.ZodError} When validation fails with specific error messages
3134
+ * @see {@link FaxOptions} for all available configuration options
3135
+ * @see {@link validateTaiwanFax} for validation logic details
3136
+ */
3137
+ declare function fax<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<FaxOptions<IsRequired>, 'required'>): FaxSchema<IsRequired>;
375
3138
 
376
- export { type BooleanMessages, type BooleanOptions, type BooleanSchema, type BusinessIdMessages, type BusinessIdOptions, type BusinessIdSchema, type DateMessages, type DateOptions, type DateSchema, type EmailMessages, type EmailOptions, type EmailSchema, type FaxMessages, type FaxOptions, type FaxSchema, ID_PATTERNS, type IdMessages, type IdOptions, type IdSchema, type IdType, type Locale, type MobileMessages, type MobileOptions, type MobileSchema, type NationalIdMessages, type NationalIdOptions, type NationalIdSchema, type NationalIdType, type NumberMessages, type NumberOptions, type NumberSchema, type PasswordMessages, type PasswordOptions, type PasswordSchema, type PasswordStrength, type TelMessages, type TelOptions, type TelSchema, type TextMessages, type TextOptions, type TextSchema, type UrlMessages, type UrlOptions, type UrlSchema, boolean, businessId, date, detectIdType, email, fax, getLocale, id, mobile, nationalId, number, password, setLocale, tel, text, url, validateCitizenId, validateIdType, validateNewResidentId, validateOldResidentId, validateTaiwanBusinessId, validateTaiwanFax, validateTaiwanMobile, validateTaiwanNationalId, validateTaiwanTel };
3139
+ export { type BooleanMessages, type BooleanOptions, type BooleanSchema, type BusinessIdMessages, type BusinessIdOptions, type BusinessIdSchema, DATETIME_PATTERNS, type DateMessages, type DateOptions, type DateSchema, type DateTimeFormat, type DateTimeMessages, type DateTimeOptions, type DateTimeSchema, type EmailMessages, type EmailOptions, type EmailSchema, type FaxMessages, type FaxOptions, type FaxSchema, type FileMessages, type FileOptions, type FileSchema, ID_PATTERNS, type IdMessages, type IdOptions, type IdSchema, type IdType, type Locale, type MobileMessages, type MobileOptions, type MobileSchema, type NationalIdMessages, type NationalIdOptions, type NationalIdSchema, type NationalIdType, type NumberMessages, type NumberOptions, type NumberSchema, type PasswordMessages, type PasswordOptions, type PasswordSchema, type PasswordStrength, type PostalCodeFormat, type PostalCodeMessages, type PostalCodeOptions, type PostalCodeSchema, TIME_PATTERNS, type TelMessages, type TelOptions, type TelSchema, type TextMessages, type TextOptions, type TextSchema, type TimeFormat, type TimeMessages, type TimeOptions, type TimeSchema, type UrlMessages, type UrlOptions, type UrlSchema, VALID_3_DIGIT_PREFIXES, boolean, businessId, date, datetime, detectIdType, email, fax, file, getLocale, id, mobile, nationalId, normalizeDateTimeValue, normalizeTime, number, parseDateTimeValue, parseTimeToMinutes, password, postalCode, setLocale, tel, text, time, url, validate3DigitPostalCode, validate5DigitPostalCode, validate6DigitPostalCode, validateCitizenId, validateDateTimeFormat, validateIdType, validateNewResidentId, validateOldResidentId, validateTaiwanBusinessId, validateTaiwanFax, validateTaiwanMobile, validateTaiwanNationalId, validateTaiwanPostalCode, validateTaiwanTel, validateTimeFormat };