@hy_ong/zod-kit 0.0.6 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +4 -1
- package/README.md +134 -68
- package/dist/index.cjs +93 -89
- package/dist/index.d.cts +235 -169
- package/dist/index.d.ts +235 -169
- package/dist/index.js +93 -89
- package/package.json +15 -5
- package/src/validators/common/boolean.ts +17 -14
- package/src/validators/common/date.ts +21 -14
- package/src/validators/common/datetime.ts +21 -14
- package/src/validators/common/email.ts +18 -15
- package/src/validators/common/file.ts +20 -13
- package/src/validators/common/id.ts +14 -14
- package/src/validators/common/number.ts +18 -15
- package/src/validators/common/password.ts +21 -14
- package/src/validators/common/text.ts +21 -17
- package/src/validators/common/time.ts +21 -14
- package/src/validators/common/url.ts +22 -15
- package/src/validators/taiwan/business-id.ts +18 -11
- package/src/validators/taiwan/fax.ts +23 -14
- package/src/validators/taiwan/mobile.ts +23 -14
- package/src/validators/taiwan/national-id.ts +11 -12
- package/src/validators/taiwan/postal-code.ts +16 -17
- package/src/validators/taiwan/tel.ts +23 -14
- package/tests/common/boolean.test.ts +38 -38
- package/tests/common/date.test.ts +65 -65
- package/tests/common/datetime.test.ts +100 -118
- package/tests/common/email.test.ts +24 -28
- package/tests/common/file.test.ts +47 -51
- package/tests/common/id.test.ts +80 -113
- package/tests/common/number.test.ts +24 -25
- package/tests/common/password.test.ts +28 -35
- package/tests/common/text.test.ts +36 -37
- package/tests/common/time.test.ts +64 -82
- package/tests/common/url.test.ts +67 -67
- package/tests/taiwan/business-id.test.ts +22 -22
- package/tests/taiwan/fax.test.ts +33 -42
- package/tests/taiwan/mobile.test.ts +32 -41
- package/tests/taiwan/national-id.test.ts +31 -31
- package/tests/taiwan/postal-code.test.ts +142 -96
- package/tests/taiwan/tel.test.ts +33 -42
- package/debug.js +0 -21
- package/debug.ts +0 -16
package/dist/index.d.cts
CHANGED
|
@@ -36,7 +36,6 @@ type BooleanMessages = {
|
|
|
36
36
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
37
37
|
*
|
|
38
38
|
* @interface BooleanOptions
|
|
39
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
40
39
|
* @property {boolean | null} [defaultValue] - Default value when input is empty
|
|
41
40
|
* @property {boolean} [shouldBe] - Specific boolean value that must be matched
|
|
42
41
|
* @property {unknown[]} [truthyValues] - Array of values that should be treated as true
|
|
@@ -46,7 +45,6 @@ type BooleanMessages = {
|
|
|
46
45
|
* @property {Record<Locale, BooleanMessages>} [i18n] - Custom error messages for different locales
|
|
47
46
|
*/
|
|
48
47
|
type BooleanOptions<IsRequired extends boolean = true> = {
|
|
49
|
-
required?: IsRequired;
|
|
50
48
|
defaultValue?: IsRequired extends true ? boolean : boolean | null;
|
|
51
49
|
shouldBe?: boolean;
|
|
52
50
|
truthyValues?: unknown[];
|
|
@@ -67,7 +65,8 @@ type BooleanSchema<IsRequired extends boolean> = IsRequired extends true ? ZodBo
|
|
|
67
65
|
* Creates a Zod schema for boolean validation with flexible value interpretation
|
|
68
66
|
*
|
|
69
67
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
70
|
-
* @param {
|
|
68
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
69
|
+
* @param {Omit<BooleanOptions<IsRequired>, 'required'>} [options] - Configuration options for boolean validation
|
|
71
70
|
* @returns {BooleanSchema<IsRequired>} Zod schema for boolean validation
|
|
72
71
|
*
|
|
73
72
|
* @description
|
|
@@ -84,39 +83,42 @@ type BooleanSchema<IsRequired extends boolean> = IsRequired extends true ? ZodBo
|
|
|
84
83
|
*
|
|
85
84
|
* @example
|
|
86
85
|
* ```typescript
|
|
87
|
-
* // Basic boolean validation
|
|
86
|
+
* // Basic boolean validation (optional by default)
|
|
88
87
|
* const basicSchema = boolean()
|
|
89
88
|
* basicSchema.parse(true) // ✓ Valid
|
|
90
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)
|
|
91
96
|
*
|
|
92
97
|
* // Strict mode (only actual booleans)
|
|
93
|
-
* const strictSchema = boolean({ strict: true })
|
|
98
|
+
* const strictSchema = boolean(false, { strict: true })
|
|
94
99
|
* strictSchema.parse(true) // ✓ Valid
|
|
95
100
|
* strictSchema.parse("true") // ✗ Invalid
|
|
96
101
|
*
|
|
97
102
|
* // Must be true
|
|
98
|
-
* const mustBeTrueSchema = boolean({ shouldBe: true })
|
|
103
|
+
* const mustBeTrueSchema = boolean(true, { shouldBe: true })
|
|
99
104
|
* mustBeTrueSchema.parse(true) // ✓ Valid
|
|
100
105
|
* mustBeTrueSchema.parse(false) // ✗ Invalid
|
|
101
106
|
*
|
|
102
107
|
* // Custom truthy/falsy values
|
|
103
|
-
* const customSchema = boolean({
|
|
108
|
+
* const customSchema = boolean(false, {
|
|
104
109
|
* truthyValues: ["yes", "on", 1],
|
|
105
110
|
* falsyValues: ["no", "off", 0]
|
|
106
111
|
* })
|
|
107
112
|
* customSchema.parse("yes") // ✓ Valid (converted to true)
|
|
108
113
|
*
|
|
109
114
|
* // Optional with default
|
|
110
|
-
* const optionalSchema = boolean({
|
|
111
|
-
* required: false,
|
|
112
|
-
* defaultValue: false
|
|
113
|
-
* })
|
|
115
|
+
* const optionalSchema = boolean(false, { defaultValue: false })
|
|
114
116
|
* ```
|
|
115
117
|
*
|
|
116
118
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
117
119
|
* @see {@link BooleanOptions} for all available configuration options
|
|
118
120
|
*/
|
|
119
|
-
declare function boolean<IsRequired extends boolean =
|
|
121
|
+
declare function boolean<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<BooleanOptions<IsRequired>, 'required'>): BooleanSchema<IsRequired>;
|
|
120
122
|
|
|
121
123
|
/**
|
|
122
124
|
* @fileoverview Date validator for Zod Kit
|
|
@@ -188,7 +190,6 @@ type DateMessages = {
|
|
|
188
190
|
* @property {Record<Locale, DateMessages>} [i18n] - Custom error messages for different locales
|
|
189
191
|
*/
|
|
190
192
|
type DateOptions<IsRequired extends boolean = true> = {
|
|
191
|
-
required?: IsRequired;
|
|
192
193
|
min?: string;
|
|
193
194
|
max?: string;
|
|
194
195
|
format?: string;
|
|
@@ -216,7 +217,8 @@ type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStrin
|
|
|
216
217
|
* Creates a Zod schema for date validation with temporal constraints
|
|
217
218
|
*
|
|
218
219
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
219
|
-
* @param {
|
|
220
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
221
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
220
222
|
* @returns {DateSchema<IsRequired>} Zod schema for date validation
|
|
221
223
|
*
|
|
222
224
|
* @description
|
|
@@ -238,15 +240,22 @@ type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStrin
|
|
|
238
240
|
* // Basic date validation (YYYY-MM-DD)
|
|
239
241
|
* const basicSchema = date()
|
|
240
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
|
+
*
|
|
241
250
|
* basicSchema.parse("2024-13-01") // ✗ Invalid (month 13)
|
|
242
251
|
*
|
|
243
252
|
* // Custom format
|
|
244
|
-
* const customFormatSchema = date({ format: "DD/MM/YYYY" })
|
|
253
|
+
* const customFormatSchema = date(false, { format: "DD/MM/YYYY" })
|
|
245
254
|
* customFormatSchema.parse("15/03/2024") // ✓ Valid
|
|
246
255
|
* customFormatSchema.parse("2024-03-15") // ✗ Invalid (wrong format)
|
|
247
256
|
*
|
|
248
257
|
* // Date range validation
|
|
249
|
-
* const rangeSchema = date({
|
|
258
|
+
* const rangeSchema = date(false, {
|
|
250
259
|
* min: "2024-01-01",
|
|
251
260
|
* max: "2024-12-31"
|
|
252
261
|
* })
|
|
@@ -254,25 +263,24 @@ type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStrin
|
|
|
254
263
|
* rangeSchema.parse("2023-12-31") // ✗ Invalid (before min)
|
|
255
264
|
*
|
|
256
265
|
* // Future dates only
|
|
257
|
-
* const futureSchema = date({ mustBeFuture: true })
|
|
266
|
+
* const futureSchema = date(false, { mustBeFuture: true })
|
|
258
267
|
* futureSchema.parse("2030-01-01") // ✓ Valid (assuming current date < 2030)
|
|
259
268
|
* futureSchema.parse("2020-01-01") // ✗ Invalid (past date)
|
|
260
269
|
*
|
|
261
270
|
* // Weekdays only (Monday-Friday)
|
|
262
|
-
* const weekdaySchema = date({ weekdaysOnly: true })
|
|
271
|
+
* const weekdaySchema = date(false, { weekdaysOnly: true })
|
|
263
272
|
* weekdaySchema.parse("2024-03-15") // ✓ Valid (if Friday)
|
|
264
273
|
* weekdaySchema.parse("2024-03-16") // ✗ Invalid (if Saturday)
|
|
265
274
|
*
|
|
266
275
|
* // Business date validation
|
|
267
|
-
* const businessSchema = date({
|
|
276
|
+
* const businessSchema = date(false, {
|
|
268
277
|
* format: "YYYY-MM-DD",
|
|
269
278
|
* mustBeFuture: true,
|
|
270
279
|
* weekdaysOnly: true
|
|
271
280
|
* })
|
|
272
281
|
*
|
|
273
282
|
* // Optional with default
|
|
274
|
-
* const optionalSchema = date({
|
|
275
|
-
* required: false,
|
|
283
|
+
* const optionalSchema = date(false, {
|
|
276
284
|
* defaultValue: "2024-01-01"
|
|
277
285
|
* })
|
|
278
286
|
* ```
|
|
@@ -280,7 +288,7 @@ type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStrin
|
|
|
280
288
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
281
289
|
* @see {@link DateOptions} for all available configuration options
|
|
282
290
|
*/
|
|
283
|
-
declare function date<IsRequired extends boolean =
|
|
291
|
+
declare function date<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateOptions<IsRequired>, 'required'>): DateSchema<IsRequired>;
|
|
284
292
|
|
|
285
293
|
/**
|
|
286
294
|
* @fileoverview DateTime validator for Zod Kit
|
|
@@ -393,7 +401,6 @@ type DateTimeFormat = "YYYY-MM-DD HH:mm" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM-DD h
|
|
|
393
401
|
* @property {Record<Locale, DateTimeMessages>} [i18n] - Custom error messages for different locales
|
|
394
402
|
*/
|
|
395
403
|
type DateTimeOptions<IsRequired extends boolean = true> = {
|
|
396
|
-
required?: IsRequired;
|
|
397
404
|
format?: DateTimeFormat;
|
|
398
405
|
min?: string | Date;
|
|
399
406
|
max?: string | Date;
|
|
@@ -514,7 +521,8 @@ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, ti
|
|
|
514
521
|
* Creates a Zod schema for datetime validation with comprehensive options
|
|
515
522
|
*
|
|
516
523
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
517
|
-
* @param {
|
|
524
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
525
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
518
526
|
* @returns {DateTimeSchema<IsRequired>} Zod schema for datetime validation
|
|
519
527
|
*
|
|
520
528
|
* @description
|
|
@@ -536,8 +544,15 @@ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, ti
|
|
|
536
544
|
* @example
|
|
537
545
|
* ```typescript
|
|
538
546
|
* // Basic datetime validation
|
|
539
|
-
* const basicSchema = datetime()
|
|
547
|
+
* const basicSchema = datetime() // optional by default
|
|
540
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
|
+
*
|
|
541
556
|
*
|
|
542
557
|
* // Business hours validation
|
|
543
558
|
* const businessHours = datetime({
|
|
@@ -548,20 +563,19 @@ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, ti
|
|
|
548
563
|
* })
|
|
549
564
|
*
|
|
550
565
|
* // Timezone-aware validation
|
|
551
|
-
* const timezoneSchema = datetime({
|
|
566
|
+
* const timezoneSchema = datetime(false, {
|
|
552
567
|
* timezone: "Asia/Taipei",
|
|
553
568
|
* mustBeFuture: true
|
|
554
569
|
* })
|
|
555
570
|
*
|
|
556
571
|
* // Multiple format support
|
|
557
|
-
* const flexibleSchema = datetime({
|
|
572
|
+
* const flexibleSchema = datetime(false, {
|
|
558
573
|
* format: "DD/MM/YYYY HH:mm"
|
|
559
574
|
* })
|
|
560
575
|
* flexibleSchema.parse("15/03/2024 14:30") // ✓ Valid
|
|
561
576
|
*
|
|
562
577
|
* // Optional with default
|
|
563
|
-
* const optionalSchema = datetime({
|
|
564
|
-
* required: false,
|
|
578
|
+
* const optionalSchema = datetime(false, {
|
|
565
579
|
* defaultValue: "2024-01-01 00:00"
|
|
566
580
|
* })
|
|
567
581
|
* ```
|
|
@@ -570,7 +584,7 @@ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, ti
|
|
|
570
584
|
* @see {@link DateTimeOptions} for all available configuration options
|
|
571
585
|
* @see {@link DateTimeFormat} for supported datetime formats
|
|
572
586
|
*/
|
|
573
|
-
declare function datetime<IsRequired extends boolean =
|
|
587
|
+
declare function datetime<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateTimeOptions<IsRequired>, 'required'>): DateTimeSchema<IsRequired>;
|
|
574
588
|
|
|
575
589
|
/**
|
|
576
590
|
* @fileoverview Email validator for Zod Kit
|
|
@@ -613,7 +627,6 @@ type EmailMessages = {
|
|
|
613
627
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
614
628
|
*
|
|
615
629
|
* @interface EmailOptions
|
|
616
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
617
630
|
* @property {string | string[]} [domain] - Allowed domain(s) for email addresses
|
|
618
631
|
* @property {string[]} [domainBlacklist] - Domains that are not allowed
|
|
619
632
|
* @property {number} [minLength] - Minimum length of email address
|
|
@@ -629,7 +642,6 @@ type EmailMessages = {
|
|
|
629
642
|
* @property {Record<Locale, EmailMessages>} [i18n] - Custom error messages for different locales
|
|
630
643
|
*/
|
|
631
644
|
type EmailOptions<IsRequired extends boolean = true> = {
|
|
632
|
-
required?: IsRequired;
|
|
633
645
|
domain?: string | string[];
|
|
634
646
|
domainBlacklist?: string[];
|
|
635
647
|
minLength?: number;
|
|
@@ -656,7 +668,8 @@ type EmailSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
656
668
|
* Creates a Zod schema for email validation with comprehensive filtering options
|
|
657
669
|
*
|
|
658
670
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
659
|
-
* @param {
|
|
671
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
672
|
+
* @param {Omit<EmailOptions<IsRequired>, 'required'>} [options] - Configuration options for email validation
|
|
660
673
|
* @returns {EmailSchema<IsRequired>} Zod schema for email validation
|
|
661
674
|
*
|
|
662
675
|
* @description
|
|
@@ -677,43 +690,46 @@ type EmailSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
677
690
|
*
|
|
678
691
|
* @example
|
|
679
692
|
* ```typescript
|
|
680
|
-
* // Basic email validation
|
|
693
|
+
* // Basic email validation (optional by default)
|
|
681
694
|
* const basicSchema = email()
|
|
682
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)
|
|
683
702
|
*
|
|
684
703
|
* // Domain restriction
|
|
685
|
-
* const domainSchema = email({
|
|
704
|
+
* const domainSchema = email(false, {
|
|
686
705
|
* domain: ["company.com", "organization.org"]
|
|
687
706
|
* })
|
|
688
707
|
* domainSchema.parse("user@company.com") // ✓ Valid
|
|
689
708
|
* domainSchema.parse("user@gmail.com") // ✗ Invalid
|
|
690
709
|
*
|
|
691
710
|
* // Business emails only (no free providers)
|
|
692
|
-
* const businessSchema = email({ businessOnly: true })
|
|
711
|
+
* const businessSchema = email(true, { businessOnly: true })
|
|
693
712
|
* businessSchema.parse("user@company.com") // ✓ Valid
|
|
694
713
|
* businessSchema.parse("user@gmail.com") // ✗ Invalid
|
|
695
714
|
*
|
|
696
715
|
* // No disposable emails
|
|
697
|
-
* const noDisposableSchema = email({ noDisposable: true })
|
|
716
|
+
* const noDisposableSchema = email(true, { noDisposable: true })
|
|
698
717
|
* noDisposableSchema.parse("user@company.com") // ✓ Valid
|
|
699
718
|
* noDisposableSchema.parse("user@10minutemail.com") // ✗ Invalid
|
|
700
719
|
*
|
|
701
720
|
* // Domain blacklist
|
|
702
|
-
* const blacklistSchema = email({
|
|
721
|
+
* const blacklistSchema = email(false, {
|
|
703
722
|
* domainBlacklist: ["spam.com", "blocked.org"]
|
|
704
723
|
* })
|
|
705
724
|
*
|
|
706
725
|
* // Optional with default
|
|
707
|
-
* const optionalSchema = email({
|
|
708
|
-
* required: false,
|
|
709
|
-
* defaultValue: null
|
|
710
|
-
* })
|
|
726
|
+
* const optionalSchema = email(false, { defaultValue: null })
|
|
711
727
|
* ```
|
|
712
728
|
*
|
|
713
729
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
714
730
|
* @see {@link EmailOptions} for all available configuration options
|
|
715
731
|
*/
|
|
716
|
-
declare function email<IsRequired extends boolean =
|
|
732
|
+
declare function email<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<EmailOptions<IsRequired>, 'required'>): EmailSchema<IsRequired>;
|
|
717
733
|
|
|
718
734
|
/**
|
|
719
735
|
* @fileoverview File validator for Zod Kit
|
|
@@ -788,7 +804,6 @@ type FileMessages = {
|
|
|
788
804
|
* @property {Record<Locale, FileMessages>} [i18n] - Custom error messages for different locales
|
|
789
805
|
*/
|
|
790
806
|
type FileOptions<IsRequired extends boolean = true> = {
|
|
791
|
-
required?: IsRequired;
|
|
792
807
|
maxSize?: number;
|
|
793
808
|
minSize?: number;
|
|
794
809
|
type?: string | string[];
|
|
@@ -819,7 +834,8 @@ type FileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodType<
|
|
|
819
834
|
* Creates a Zod schema for file validation with comprehensive filtering options
|
|
820
835
|
*
|
|
821
836
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
822
|
-
* @param {
|
|
837
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
838
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
823
839
|
* @returns {FileSchema<IsRequired>} Zod schema for file validation
|
|
824
840
|
*
|
|
825
841
|
* @description
|
|
@@ -839,42 +855,48 @@ type FileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodType<
|
|
|
839
855
|
* @example
|
|
840
856
|
* ```typescript
|
|
841
857
|
* // Basic file validation
|
|
842
|
-
* const basicSchema = file()
|
|
858
|
+
* const basicSchema = file() // optional by default
|
|
843
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
|
+
*
|
|
844
867
|
*
|
|
845
868
|
* // Size restrictions
|
|
846
|
-
* const sizeSchema = file({
|
|
869
|
+
* const sizeSchema = file(false, {
|
|
847
870
|
* maxSize: 1024 * 1024, // 1MB
|
|
848
871
|
* minSize: 1024 // 1KB
|
|
849
872
|
* })
|
|
850
873
|
*
|
|
851
874
|
* // Extension restrictions
|
|
852
|
-
* const imageSchema = file({
|
|
875
|
+
* const imageSchema = file(false, {
|
|
853
876
|
* extension: [".jpg", ".png", ".gif"],
|
|
854
877
|
* maxSize: 5 * 1024 * 1024 // 5MB
|
|
855
878
|
* })
|
|
856
879
|
*
|
|
857
880
|
* // MIME type restrictions
|
|
858
|
-
* const documentSchema = file({
|
|
881
|
+
* const documentSchema = file(false, {
|
|
859
882
|
* type: ["application/pdf", "application/msword"],
|
|
860
883
|
* maxSize: 10 * 1024 * 1024 // 10MB
|
|
861
884
|
* })
|
|
862
885
|
*
|
|
863
886
|
* // Image files only
|
|
864
|
-
* const imageOnlySchema = file({ imageOnly: true })
|
|
887
|
+
* const imageOnlySchema = file(false, { imageOnly: true })
|
|
865
888
|
*
|
|
866
889
|
* // Document files only
|
|
867
|
-
* const docOnlySchema = file({ documentOnly: true })
|
|
890
|
+
* const docOnlySchema = file(false, { documentOnly: true })
|
|
868
891
|
*
|
|
869
892
|
* // Name pattern validation
|
|
870
|
-
* const patternSchema = file({
|
|
893
|
+
* const patternSchema = file(false, {
|
|
871
894
|
* namePattern: /^[a-zA-Z0-9_-]+\.(pdf|doc|docx)$/,
|
|
872
895
|
* maxSize: 5 * 1024 * 1024
|
|
873
896
|
* })
|
|
874
897
|
*
|
|
875
898
|
* // Optional with default
|
|
876
|
-
* const optionalSchema = file({
|
|
877
|
-
* required: false,
|
|
899
|
+
* const optionalSchema = file(false, {
|
|
878
900
|
* defaultValue: null
|
|
879
901
|
* })
|
|
880
902
|
* ```
|
|
@@ -882,7 +904,7 @@ type FileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodType<
|
|
|
882
904
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
883
905
|
* @see {@link FileOptions} for all available configuration options
|
|
884
906
|
*/
|
|
885
|
-
declare function file<IsRequired extends boolean =
|
|
907
|
+
declare function file<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<FileOptions<IsRequired>, 'required'>): FileSchema<IsRequired>;
|
|
886
908
|
|
|
887
909
|
/**
|
|
888
910
|
* @fileoverview ID validator for Zod Kit
|
|
@@ -974,7 +996,6 @@ type IdType = "numeric" | "uuid" | "objectId" | "nanoid" | "snowflake" | "cuid"
|
|
|
974
996
|
* @property {Record<Locale, IdMessages>} [i18n] - Custom error messages for different locales
|
|
975
997
|
*/
|
|
976
998
|
type IdOptions<IsRequired extends boolean = true> = {
|
|
977
|
-
required?: IsRequired;
|
|
978
999
|
type?: IdType;
|
|
979
1000
|
minLength?: number;
|
|
980
1001
|
maxLength?: number;
|
|
@@ -1058,7 +1079,8 @@ declare const validateIdType: (value: string, type: IdType) => boolean;
|
|
|
1058
1079
|
* Creates a Zod schema for ID validation with comprehensive format support
|
|
1059
1080
|
*
|
|
1060
1081
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
1061
|
-
* @param {
|
|
1082
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
1083
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
1062
1084
|
* @returns {IdSchema<IsRequired>} Zod schema for ID validation
|
|
1063
1085
|
*
|
|
1064
1086
|
* @description
|
|
@@ -1085,23 +1107,23 @@ declare const validateIdType: (value: string, type: IdType) => boolean;
|
|
|
1085
1107
|
* autoSchema.parse("123456") // ✓ Valid (numeric)
|
|
1086
1108
|
*
|
|
1087
1109
|
* // Specific ID type
|
|
1088
|
-
* const uuidSchema = id({ type: "uuid" })
|
|
1110
|
+
* const uuidSchema = id(false, { type: "uuid" })
|
|
1089
1111
|
* uuidSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid
|
|
1090
1112
|
* uuidSchema.parse("invalid-uuid") // ✗ Invalid
|
|
1091
1113
|
*
|
|
1092
1114
|
* // Multiple allowed types
|
|
1093
|
-
* const multiSchema = id({ allowedTypes: ["uuid", "objectId"] })
|
|
1115
|
+
* const multiSchema = id(false, { allowedTypes: ["uuid", "objectId"] })
|
|
1094
1116
|
* multiSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
|
|
1095
1117
|
* multiSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
|
|
1096
1118
|
* multiSchema.parse("123456") // ✗ Invalid (numeric not allowed)
|
|
1097
1119
|
*
|
|
1098
1120
|
* // Custom regex pattern
|
|
1099
|
-
* const customSchema = id({ customRegex: /^CUST_\d{6}$/ })
|
|
1121
|
+
* const customSchema = id(false, { customRegex: /^CUST_\d{6}$/ })
|
|
1100
1122
|
* customSchema.parse("CUST_123456") // ✓ Valid
|
|
1101
1123
|
* customSchema.parse("invalid") // ✗ Invalid
|
|
1102
1124
|
*
|
|
1103
1125
|
* // Content validation
|
|
1104
|
-
* const prefixSchema = id({
|
|
1126
|
+
* const prefixSchema = id(false, {
|
|
1105
1127
|
* type: "auto",
|
|
1106
1128
|
* startsWith: "user_",
|
|
1107
1129
|
* minLength: 10
|
|
@@ -1109,15 +1131,14 @@ declare const validateIdType: (value: string, type: IdType) => boolean;
|
|
|
1109
1131
|
* prefixSchema.parse("user_123456") // ✓ Valid
|
|
1110
1132
|
*
|
|
1111
1133
|
* // Case insensitive
|
|
1112
|
-
* const caseInsensitiveSchema = id({
|
|
1134
|
+
* const caseInsensitiveSchema = id(false, {
|
|
1113
1135
|
* type: "uuid",
|
|
1114
1136
|
* caseSensitive: false
|
|
1115
1137
|
* })
|
|
1116
1138
|
* caseInsensitiveSchema.parse("550E8400-E29B-41D4-A716-446655440000") // ✓ Valid
|
|
1117
1139
|
*
|
|
1118
1140
|
* // Optional with default
|
|
1119
|
-
* const optionalSchema = id({
|
|
1120
|
-
* required: false,
|
|
1141
|
+
* const optionalSchema = id(false, {
|
|
1121
1142
|
* defaultValue: null
|
|
1122
1143
|
* })
|
|
1123
1144
|
* ```
|
|
@@ -1128,7 +1149,7 @@ declare const validateIdType: (value: string, type: IdType) => boolean;
|
|
|
1128
1149
|
* @see {@link detectIdType} for auto-detection logic
|
|
1129
1150
|
* @see {@link validateIdType} for type-specific validation
|
|
1130
1151
|
*/
|
|
1131
|
-
declare function id<IsRequired extends boolean =
|
|
1152
|
+
declare function id<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<IdOptions<IsRequired>, 'required'>): IdSchema<IsRequired>;
|
|
1132
1153
|
|
|
1133
1154
|
/**
|
|
1134
1155
|
* @fileoverview Number validator for Zod Kit
|
|
@@ -1196,7 +1217,6 @@ type NumberMessages = {
|
|
|
1196
1217
|
* @property {Record<Locale, NumberMessages>} [i18n] - Custom error messages for different locales
|
|
1197
1218
|
*/
|
|
1198
1219
|
type NumberOptions<IsRequired extends boolean = true> = {
|
|
1199
|
-
required?: IsRequired;
|
|
1200
1220
|
min?: number;
|
|
1201
1221
|
max?: number;
|
|
1202
1222
|
defaultValue?: IsRequired extends true ? number : number | null;
|
|
@@ -1244,51 +1264,54 @@ type NumberSchema<IsRequired extends boolean> = IsRequired extends true ? ZodNum
|
|
|
1244
1264
|
*
|
|
1245
1265
|
* @example
|
|
1246
1266
|
* ```typescript
|
|
1247
|
-
* // Basic number validation
|
|
1267
|
+
* // Basic number validation (optional by default)
|
|
1248
1268
|
* const basicSchema = number()
|
|
1249
1269
|
* basicSchema.parse(42) // ✓ Valid
|
|
1250
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)
|
|
1251
1277
|
*
|
|
1252
1278
|
* // Integer only
|
|
1253
|
-
* const integerSchema = number({ type: "integer" })
|
|
1279
|
+
* const integerSchema = number(false, { type: "integer" })
|
|
1254
1280
|
* integerSchema.parse(42) // ✓ Valid
|
|
1255
1281
|
* integerSchema.parse(42.5) // ✗ Invalid
|
|
1256
1282
|
*
|
|
1257
1283
|
* // Range validation
|
|
1258
|
-
* const rangeSchema = number({ min: 0, max: 100 })
|
|
1284
|
+
* const rangeSchema = number(true, { min: 0, max: 100 })
|
|
1259
1285
|
* rangeSchema.parse(50) // ✓ Valid
|
|
1260
1286
|
* rangeSchema.parse(150) // ✗ Invalid
|
|
1261
1287
|
*
|
|
1262
1288
|
* // Positive numbers only
|
|
1263
|
-
* const positiveSchema = number({ positive: true })
|
|
1289
|
+
* const positiveSchema = number(true, { positive: true })
|
|
1264
1290
|
* positiveSchema.parse(5) // ✓ Valid
|
|
1265
1291
|
* positiveSchema.parse(-5) // ✗ Invalid
|
|
1266
1292
|
*
|
|
1267
1293
|
* // Multiple of constraint
|
|
1268
|
-
* const multipleSchema = number({ multipleOf: 5 })
|
|
1294
|
+
* const multipleSchema = number(true, { multipleOf: 5 })
|
|
1269
1295
|
* multipleSchema.parse(10) // ✓ Valid
|
|
1270
1296
|
* multipleSchema.parse(7) // ✗ Invalid
|
|
1271
1297
|
*
|
|
1272
1298
|
* // Precision control
|
|
1273
|
-
* const precisionSchema = number({ precision: 2 })
|
|
1299
|
+
* const precisionSchema = number(true, { precision: 2 })
|
|
1274
1300
|
* precisionSchema.parse(3.14) // ✓ Valid
|
|
1275
1301
|
* precisionSchema.parse(3.14159) // ✗ Invalid
|
|
1276
1302
|
*
|
|
1277
1303
|
* // Comma-separated parsing
|
|
1278
|
-
* const commaSchema = number({ parseCommas: true })
|
|
1304
|
+
* const commaSchema = number(false, { parseCommas: true })
|
|
1279
1305
|
* commaSchema.parse("1,234.56") // ✓ Valid (parsed as 1234.56)
|
|
1280
1306
|
*
|
|
1281
1307
|
* // Optional with default
|
|
1282
|
-
* const optionalSchema = number({
|
|
1283
|
-
* required: false,
|
|
1284
|
-
* defaultValue: 0
|
|
1285
|
-
* })
|
|
1308
|
+
* const optionalSchema = number(false, { defaultValue: 0 })
|
|
1286
1309
|
* ```
|
|
1287
1310
|
*
|
|
1288
1311
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1289
1312
|
* @see {@link NumberOptions} for all available configuration options
|
|
1290
1313
|
*/
|
|
1291
|
-
declare function number<IsRequired extends boolean =
|
|
1314
|
+
declare function number<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NumberOptions<IsRequired>, 'required'>): NumberSchema<IsRequired>;
|
|
1292
1315
|
|
|
1293
1316
|
/**
|
|
1294
1317
|
* @fileoverview Password validator for Zod Kit
|
|
@@ -1371,7 +1394,6 @@ type PasswordStrength = "weak" | "medium" | "strong" | "very-strong";
|
|
|
1371
1394
|
* @property {Record<Locale, PasswordMessages>} [i18n] - Custom error messages for different locales
|
|
1372
1395
|
*/
|
|
1373
1396
|
type PasswordOptions<IsRequired extends boolean = true> = {
|
|
1374
|
-
required?: IsRequired;
|
|
1375
1397
|
min?: number;
|
|
1376
1398
|
max?: number;
|
|
1377
1399
|
uppercase?: boolean;
|
|
@@ -1401,7 +1423,8 @@ type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodS
|
|
|
1401
1423
|
* Creates a Zod schema for password validation with comprehensive security checks
|
|
1402
1424
|
*
|
|
1403
1425
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
1404
|
-
* @param {
|
|
1426
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
1427
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
1405
1428
|
* @returns {PasswordSchema<IsRequired>} Zod schema for password validation
|
|
1406
1429
|
*
|
|
1407
1430
|
* @description
|
|
@@ -1422,11 +1445,18 @@ type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodS
|
|
|
1422
1445
|
* @example
|
|
1423
1446
|
* ```typescript
|
|
1424
1447
|
* // Basic password validation
|
|
1425
|
-
* const basicSchema = password()
|
|
1448
|
+
* const basicSchema = password() // optional by default
|
|
1426
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
|
+
*
|
|
1427
1457
|
*
|
|
1428
1458
|
* // Strong password requirements
|
|
1429
|
-
* const strongSchema = password({
|
|
1459
|
+
* const strongSchema = password(false, {
|
|
1430
1460
|
* min: 12,
|
|
1431
1461
|
* uppercase: true,
|
|
1432
1462
|
* lowercase: true,
|
|
@@ -1436,7 +1466,7 @@ type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodS
|
|
|
1436
1466
|
* })
|
|
1437
1467
|
*
|
|
1438
1468
|
* // No common passwords
|
|
1439
|
-
* const secureSchema = password({
|
|
1469
|
+
* const secureSchema = password(false, {
|
|
1440
1470
|
* noCommonWords: true,
|
|
1441
1471
|
* noRepeating: true,
|
|
1442
1472
|
* noSequential: true
|
|
@@ -1446,7 +1476,7 @@ type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodS
|
|
|
1446
1476
|
* secureSchema.parse("abc123") // ✗ Invalid (sequential characters)
|
|
1447
1477
|
*
|
|
1448
1478
|
* // Custom requirements
|
|
1449
|
-
* const customSchema = password({
|
|
1479
|
+
* const customSchema = password(false, {
|
|
1450
1480
|
* min: 8,
|
|
1451
1481
|
* includes: "@", // Must contain @
|
|
1452
1482
|
* excludes: ["admin", "user"], // Cannot contain these words
|
|
@@ -1454,13 +1484,12 @@ type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodS
|
|
|
1454
1484
|
* })
|
|
1455
1485
|
*
|
|
1456
1486
|
* // Minimum strength requirement
|
|
1457
|
-
* const strengthSchema = password({ minStrength: "very-strong" })
|
|
1487
|
+
* const strengthSchema = password(false, { minStrength: "very-strong" })
|
|
1458
1488
|
* strengthSchema.parse("weak") // ✗ Invalid (insufficient strength)
|
|
1459
1489
|
* strengthSchema.parse("MyVeryStr0ng!P@ssw0rd2024") // ✓ Valid
|
|
1460
1490
|
*
|
|
1461
1491
|
* // Optional with default
|
|
1462
|
-
* const optionalSchema = password({
|
|
1463
|
-
* required: false,
|
|
1492
|
+
* const optionalSchema = password(false, {
|
|
1464
1493
|
* defaultValue: null
|
|
1465
1494
|
* })
|
|
1466
1495
|
* ```
|
|
@@ -1470,7 +1499,7 @@ type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodS
|
|
|
1470
1499
|
* @see {@link PasswordStrength} for strength level definitions
|
|
1471
1500
|
* @see {@link calculatePasswordStrength} for strength calculation logic
|
|
1472
1501
|
*/
|
|
1473
|
-
declare function password<IsRequired extends boolean =
|
|
1502
|
+
declare function password<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<PasswordOptions<IsRequired>, 'required'>): PasswordSchema<IsRequired>;
|
|
1474
1503
|
|
|
1475
1504
|
/**
|
|
1476
1505
|
* @fileoverview Text validator for Zod Kit
|
|
@@ -1529,7 +1558,6 @@ type TextMessages = {
|
|
|
1529
1558
|
* @property {Record<Locale, TextMessages>} [i18n] - Custom error messages for different locales
|
|
1530
1559
|
*/
|
|
1531
1560
|
type TextOptions<IsRequired extends boolean = true> = {
|
|
1532
|
-
required?: IsRequired;
|
|
1533
1561
|
minLength?: number;
|
|
1534
1562
|
maxLength?: number;
|
|
1535
1563
|
startsWith?: string;
|
|
@@ -1575,17 +1603,23 @@ type TextSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStrin
|
|
|
1575
1603
|
*
|
|
1576
1604
|
* @example
|
|
1577
1605
|
* ```typescript
|
|
1578
|
-
* // Basic text validation
|
|
1606
|
+
* // Basic text validation (optional by default)
|
|
1579
1607
|
* const basicSchema = text()
|
|
1580
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)
|
|
1581
1615
|
*
|
|
1582
1616
|
* // Length constraints
|
|
1583
|
-
* const lengthSchema = text({ minLength: 3, maxLength: 50 })
|
|
1617
|
+
* const lengthSchema = text(true, { minLength: 3, maxLength: 50 })
|
|
1584
1618
|
* lengthSchema.parse("Hello") // ✓ Valid
|
|
1585
1619
|
* lengthSchema.parse("Hi") // ✗ Invalid (too short)
|
|
1586
1620
|
*
|
|
1587
1621
|
* // Content validation
|
|
1588
|
-
* const contentSchema = text({
|
|
1622
|
+
* const contentSchema = text(true, {
|
|
1589
1623
|
* startsWith: "Hello",
|
|
1590
1624
|
* endsWith: "!",
|
|
1591
1625
|
* includes: "World"
|
|
@@ -1593,34 +1627,31 @@ type TextSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStrin
|
|
|
1593
1627
|
* contentSchema.parse("Hello World!") // ✓ Valid
|
|
1594
1628
|
*
|
|
1595
1629
|
* // Case transformation
|
|
1596
|
-
* const upperSchema = text({ casing: "upper" })
|
|
1630
|
+
* const upperSchema = text(false, { casing: "upper" })
|
|
1597
1631
|
* upperSchema.parse("hello") // ✓ Valid (converted to "HELLO")
|
|
1598
1632
|
*
|
|
1599
1633
|
* // Trim modes
|
|
1600
|
-
* const trimStartSchema = text({ trimMode: "trimStart" })
|
|
1634
|
+
* const trimStartSchema = text(false, { trimMode: "trimStart" })
|
|
1601
1635
|
* trimStartSchema.parse(" hello ") // ✓ Valid (result: "hello ")
|
|
1602
1636
|
*
|
|
1603
1637
|
* // Regex validation
|
|
1604
|
-
* const regexSchema = text({ regex: /^[a-zA-Z]+$/ })
|
|
1638
|
+
* const regexSchema = text(true, { regex: /^[a-zA-Z]+$/ })
|
|
1605
1639
|
* regexSchema.parse("hello") // ✓ Valid
|
|
1606
1640
|
* regexSchema.parse("hello123") // ✗ Invalid
|
|
1607
1641
|
*
|
|
1608
1642
|
* // Not empty (rejects whitespace-only)
|
|
1609
|
-
* const notEmptySchema = text({ notEmpty: true })
|
|
1643
|
+
* const notEmptySchema = text(true, { notEmpty: true })
|
|
1610
1644
|
* notEmptySchema.parse("hello") // ✓ Valid
|
|
1611
1645
|
* notEmptySchema.parse(" ") // ✗ Invalid
|
|
1612
1646
|
*
|
|
1613
1647
|
* // Optional with default
|
|
1614
|
-
* const optionalSchema = text({
|
|
1615
|
-
* required: false,
|
|
1616
|
-
* defaultValue: "default text"
|
|
1617
|
-
* })
|
|
1648
|
+
* const optionalSchema = text(false, { defaultValue: "default text" })
|
|
1618
1649
|
* ```
|
|
1619
1650
|
*
|
|
1620
1651
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1621
1652
|
* @see {@link TextOptions} for all available configuration options
|
|
1622
1653
|
*/
|
|
1623
|
-
declare function text<IsRequired extends boolean =
|
|
1654
|
+
declare function text<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TextOptions<IsRequired>, 'required'>): TextSchema<IsRequired>;
|
|
1624
1655
|
|
|
1625
1656
|
/**
|
|
1626
1657
|
* @fileoverview Time validator for Zod Kit
|
|
@@ -1704,7 +1735,6 @@ type TimeFormat = "HH:mm" | "HH:mm:ss" | "hh:mm A" | "hh:mm:ss A" | "H:mm" | "h:
|
|
|
1704
1735
|
* @property {Record<Locale, TimeMessages>} [i18n] - Custom error messages for different locales
|
|
1705
1736
|
*/
|
|
1706
1737
|
type TimeOptions<IsRequired extends boolean = true> = {
|
|
1707
|
-
required?: IsRequired;
|
|
1708
1738
|
format?: TimeFormat;
|
|
1709
1739
|
min?: string;
|
|
1710
1740
|
max?: string;
|
|
@@ -1803,7 +1833,8 @@ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | n
|
|
|
1803
1833
|
* Creates a Zod schema for time validation with comprehensive options
|
|
1804
1834
|
*
|
|
1805
1835
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
1806
|
-
* @param {
|
|
1836
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
1837
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
1807
1838
|
* @returns {TimeSchema<IsRequired>} Zod schema for time validation
|
|
1808
1839
|
*
|
|
1809
1840
|
* @description
|
|
@@ -1825,10 +1856,17 @@ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | n
|
|
|
1825
1856
|
* // Basic time validation (24-hour format)
|
|
1826
1857
|
* const basicSchema = time()
|
|
1827
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
|
+
*
|
|
1828
1866
|
* basicSchema.parse("2:30 PM") // ✗ Invalid (wrong format)
|
|
1829
1867
|
*
|
|
1830
1868
|
* // 12-hour format with AM/PM
|
|
1831
|
-
* const ampmSchema = time({ format: "hh:mm A" })
|
|
1869
|
+
* const ampmSchema = time(false, { format: "hh:mm A" })
|
|
1832
1870
|
* ampmSchema.parse("02:30 PM") // ✓ Valid
|
|
1833
1871
|
* ampmSchema.parse("14:30") // ✗ Invalid (wrong format)
|
|
1834
1872
|
*
|
|
@@ -1844,7 +1882,7 @@ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | n
|
|
|
1844
1882
|
* businessHours.parse("09:05") // ✗ Invalid (not 15-minute step)
|
|
1845
1883
|
*
|
|
1846
1884
|
* // Time range validation
|
|
1847
|
-
* const timeRangeSchema = time({
|
|
1885
|
+
* const timeRangeSchema = time(false, {
|
|
1848
1886
|
* min: "09:00",
|
|
1849
1887
|
* max: "17:00"
|
|
1850
1888
|
* })
|
|
@@ -1859,7 +1897,7 @@ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | n
|
|
|
1859
1897
|
* specificHours.parse("11:30") // ✗ Invalid (hour not allowed)
|
|
1860
1898
|
*
|
|
1861
1899
|
* // Whitelist specific times
|
|
1862
|
-
* const whitelistSchema = time({
|
|
1900
|
+
* const whitelistSchema = time(false, {
|
|
1863
1901
|
* whitelist: ["09:00", "12:00", "17:00"],
|
|
1864
1902
|
* whitelistOnly: true
|
|
1865
1903
|
* })
|
|
@@ -1867,8 +1905,7 @@ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | n
|
|
|
1867
1905
|
* whitelistSchema.parse("13:00") // ✗ Invalid (not in whitelist)
|
|
1868
1906
|
*
|
|
1869
1907
|
* // Optional with default
|
|
1870
|
-
* const optionalSchema = time({
|
|
1871
|
-
* required: false,
|
|
1908
|
+
* const optionalSchema = time(false, {
|
|
1872
1909
|
* defaultValue: "09:00"
|
|
1873
1910
|
* })
|
|
1874
1911
|
* optionalSchema.parse("") // ✓ Valid (returns "09:00")
|
|
@@ -1878,7 +1915,7 @@ declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | n
|
|
|
1878
1915
|
* @see {@link TimeOptions} for all available configuration options
|
|
1879
1916
|
* @see {@link TimeFormat} for supported time formats
|
|
1880
1917
|
*/
|
|
1881
|
-
declare function time<IsRequired extends boolean =
|
|
1918
|
+
declare function time<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TimeOptions<IsRequired>, 'required'>): TimeSchema<IsRequired>;
|
|
1882
1919
|
|
|
1883
1920
|
/**
|
|
1884
1921
|
* @fileoverview URL validator for Zod Kit
|
|
@@ -1962,7 +1999,6 @@ type UrlMessages = {
|
|
|
1962
1999
|
* @property {Record<Locale, UrlMessages>} [i18n] - Custom error messages for different locales
|
|
1963
2000
|
*/
|
|
1964
2001
|
type UrlOptions<IsRequired extends boolean = true> = {
|
|
1965
|
-
required?: IsRequired;
|
|
1966
2002
|
min?: number;
|
|
1967
2003
|
max?: number;
|
|
1968
2004
|
includes?: string;
|
|
@@ -1996,7 +2032,8 @@ type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString
|
|
|
1996
2032
|
* Creates a Zod schema for URL validation with comprehensive constraints
|
|
1997
2033
|
*
|
|
1998
2034
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
1999
|
-
* @param {
|
|
2035
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2036
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2000
2037
|
* @returns {UrlSchema<IsRequired>} Zod schema for URL validation
|
|
2001
2038
|
*
|
|
2002
2039
|
* @description
|
|
@@ -2020,43 +2057,49 @@ type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString
|
|
|
2020
2057
|
* @example
|
|
2021
2058
|
* ```typescript
|
|
2022
2059
|
* // Basic URL validation
|
|
2023
|
-
* const basicSchema = url()
|
|
2060
|
+
* const basicSchema = url() // optional by default
|
|
2024
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
|
+
*
|
|
2025
2069
|
*
|
|
2026
2070
|
* // HTTPS only
|
|
2027
|
-
* const httpsSchema = url({ protocols: ["https"] })
|
|
2071
|
+
* const httpsSchema = url(false, { protocols: ["https"] })
|
|
2028
2072
|
* httpsSchema.parse("https://example.com") // ✓ Valid
|
|
2029
2073
|
* httpsSchema.parse("http://example.com") // ✗ Invalid
|
|
2030
2074
|
*
|
|
2031
2075
|
* // Domain restriction
|
|
2032
|
-
* const domainSchema = url({
|
|
2076
|
+
* const domainSchema = url(false, {
|
|
2033
2077
|
* allowedDomains: ["company.com", "trusted.org"]
|
|
2034
2078
|
* })
|
|
2035
2079
|
* domainSchema.parse("https://app.company.com") // ✓ Valid (subdomain)
|
|
2036
2080
|
* domainSchema.parse("https://example.com") // ✗ Invalid
|
|
2037
2081
|
*
|
|
2038
2082
|
* // Block localhost
|
|
2039
|
-
* const noLocalhostSchema = url({ blockLocalhost: true })
|
|
2083
|
+
* const noLocalhostSchema = url(false, { blockLocalhost: true })
|
|
2040
2084
|
* noLocalhostSchema.parse("https://example.com") // ✓ Valid
|
|
2041
2085
|
* noLocalhostSchema.parse("http://localhost:3000") // ✗ Invalid
|
|
2042
2086
|
*
|
|
2043
2087
|
* // API endpoints with path requirements
|
|
2044
|
-
* const apiSchema = url({
|
|
2088
|
+
* const apiSchema = url(false, {
|
|
2045
2089
|
* pathStartsWith: "/api/",
|
|
2046
2090
|
* mustHaveQuery: true
|
|
2047
2091
|
* })
|
|
2048
2092
|
* apiSchema.parse("https://api.com/api/users?page=1") // ✓ Valid
|
|
2049
2093
|
*
|
|
2050
2094
|
* // Port restrictions
|
|
2051
|
-
* const portSchema = url({
|
|
2095
|
+
* const portSchema = url(false, {
|
|
2052
2096
|
* allowedPorts: [80, 443, 8080]
|
|
2053
2097
|
* })
|
|
2054
2098
|
* portSchema.parse("https://example.com:443") // ✓ Valid
|
|
2055
2099
|
* portSchema.parse("https://example.com:3000") // ✗ Invalid
|
|
2056
2100
|
*
|
|
2057
2101
|
* // Optional with default
|
|
2058
|
-
* const optionalSchema = url({
|
|
2059
|
-
* required: false,
|
|
2102
|
+
* const optionalSchema = url(false, {
|
|
2060
2103
|
* defaultValue: null
|
|
2061
2104
|
* })
|
|
2062
2105
|
* ```
|
|
@@ -2064,7 +2107,7 @@ type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString
|
|
|
2064
2107
|
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2065
2108
|
* @see {@link UrlOptions} for all available configuration options
|
|
2066
2109
|
*/
|
|
2067
|
-
declare function url<IsRequired extends boolean =
|
|
2110
|
+
declare function url<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<UrlOptions<IsRequired>, 'required'>): UrlSchema<IsRequired>;
|
|
2068
2111
|
|
|
2069
2112
|
/**
|
|
2070
2113
|
* @fileoverview Taiwan Business ID (統一編號) validator for Zod Kit
|
|
@@ -2099,7 +2142,6 @@ type BusinessIdMessages = {
|
|
|
2099
2142
|
* @property {Record<Locale, BusinessIdMessages>} [i18n] - Custom error messages for different locales
|
|
2100
2143
|
*/
|
|
2101
2144
|
type BusinessIdOptions<IsRequired extends boolean = true> = {
|
|
2102
|
-
required?: IsRequired;
|
|
2103
2145
|
transform?: (value: string) => string;
|
|
2104
2146
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2105
2147
|
i18n?: Record<Locale, BusinessIdMessages>;
|
|
@@ -2159,23 +2201,30 @@ declare const validateTaiwanBusinessId: (value: string) => boolean;
|
|
|
2159
2201
|
* @example
|
|
2160
2202
|
* ```typescript
|
|
2161
2203
|
* // Basic business ID validation
|
|
2162
|
-
* const basicSchema = businessId()
|
|
2204
|
+
* const basicSchema = businessId() // optional by default
|
|
2163
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
|
+
*
|
|
2164
2213
|
* basicSchema.parse("1234567") // ✗ Invalid (not 8 digits)
|
|
2165
2214
|
*
|
|
2166
2215
|
* // Optional business ID
|
|
2167
|
-
* const optionalSchema = businessId(
|
|
2216
|
+
* const optionalSchema = businessId(false)
|
|
2168
2217
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2169
2218
|
* optionalSchema.parse("12345675") // ✓ Valid (if checksum correct)
|
|
2170
2219
|
*
|
|
2171
2220
|
* // With custom transformation
|
|
2172
|
-
* const transformSchema = businessId({
|
|
2221
|
+
* const transformSchema = businessId(false, {
|
|
2173
2222
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
2174
2223
|
* })
|
|
2175
2224
|
* transformSchema.parse("1234-5675") // ✓ Valid (if checksum correct after cleaning)
|
|
2176
2225
|
*
|
|
2177
2226
|
* // With custom error messages
|
|
2178
|
-
* const customSchema = businessId({
|
|
2227
|
+
* const customSchema = businessId(false, {
|
|
2179
2228
|
* i18n: {
|
|
2180
2229
|
* en: { invalid: "Please enter a valid Taiwan Business ID" },
|
|
2181
2230
|
* 'zh-TW': { invalid: "請輸入有效的統一編號" }
|
|
@@ -2187,7 +2236,7 @@ declare const validateTaiwanBusinessId: (value: string) => boolean;
|
|
|
2187
2236
|
* @see {@link BusinessIdOptions} for all available configuration options
|
|
2188
2237
|
* @see {@link validateTaiwanBusinessId} for validation logic details
|
|
2189
2238
|
*/
|
|
2190
|
-
declare function businessId<IsRequired extends boolean =
|
|
2239
|
+
declare function businessId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<BusinessIdOptions<IsRequired>, 'required'>): BusinessIdSchema<IsRequired>;
|
|
2191
2240
|
|
|
2192
2241
|
/**
|
|
2193
2242
|
* @fileoverview Taiwan National ID (身分證/居留證) validator for Zod Kit
|
|
@@ -2235,7 +2284,6 @@ type NationalIdType = "citizen" | "resident" | "both";
|
|
|
2235
2284
|
* @property {Record<Locale, NationalIdMessages>} [i18n] - Custom error messages for different locales
|
|
2236
2285
|
*/
|
|
2237
2286
|
type NationalIdOptions<IsRequired extends boolean = true> = {
|
|
2238
|
-
required?: IsRequired;
|
|
2239
2287
|
type?: NationalIdType;
|
|
2240
2288
|
allowOldResident?: boolean;
|
|
2241
2289
|
transform?: (value: string) => string;
|
|
@@ -2367,12 +2415,12 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2367
2415
|
* anyIdSchema.parse("AA12345678") // ✓ Valid old resident ID
|
|
2368
2416
|
*
|
|
2369
2417
|
* // Citizen IDs only
|
|
2370
|
-
* const citizenSchema = nationalId({ type: "citizen" })
|
|
2418
|
+
* const citizenSchema = nationalId(false, { type: "citizen" })
|
|
2371
2419
|
* citizenSchema.parse("A123456789") // ✓ Valid
|
|
2372
2420
|
* citizenSchema.parse("A812345678") // ✗ Invalid (resident ID)
|
|
2373
2421
|
*
|
|
2374
2422
|
* // Resident IDs only (new format only)
|
|
2375
|
-
* const residentSchema = nationalId({
|
|
2423
|
+
* const residentSchema = nationalId(false, {
|
|
2376
2424
|
* type: "resident",
|
|
2377
2425
|
* allowOldResident: false
|
|
2378
2426
|
* })
|
|
@@ -2380,13 +2428,12 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2380
2428
|
* residentSchema.parse("AA12345678") // ✗ Invalid (old format)
|
|
2381
2429
|
*
|
|
2382
2430
|
* // Optional with custom transformation
|
|
2383
|
-
* const optionalSchema = nationalId({
|
|
2384
|
-
* required: false,
|
|
2431
|
+
* const optionalSchema = nationalId(false, {
|
|
2385
2432
|
* transform: (value) => value.replace(/[^A-Z0-9]/g, '') // Remove special chars
|
|
2386
2433
|
* })
|
|
2387
2434
|
*
|
|
2388
2435
|
* // With custom error messages
|
|
2389
|
-
* const customSchema = nationalId({
|
|
2436
|
+
* const customSchema = nationalId(false, {
|
|
2390
2437
|
* i18n: {
|
|
2391
2438
|
* en: { invalid: "Please enter a valid Taiwan National ID" },
|
|
2392
2439
|
* 'zh-TW': { invalid: "請輸入有效的身分證或居留證號碼" }
|
|
@@ -2399,7 +2446,7 @@ declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, a
|
|
|
2399
2446
|
* @see {@link NationalIdType} for supported ID types
|
|
2400
2447
|
* @see {@link validateTaiwanNationalId} for validation logic details
|
|
2401
2448
|
*/
|
|
2402
|
-
declare function nationalId<IsRequired extends boolean =
|
|
2449
|
+
declare function nationalId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NationalIdOptions<IsRequired>, 'required'>): NationalIdSchema<IsRequired>;
|
|
2403
2450
|
|
|
2404
2451
|
/**
|
|
2405
2452
|
* @fileoverview Taiwan Mobile Phone Number validator for Zod Kit
|
|
@@ -2437,7 +2484,6 @@ type MobileMessages = {
|
|
|
2437
2484
|
* @property {Record<Locale, MobileMessages>} [i18n] - Custom error messages for different locales
|
|
2438
2485
|
*/
|
|
2439
2486
|
type MobileOptions<IsRequired extends boolean = true> = {
|
|
2440
|
-
required?: IsRequired;
|
|
2441
2487
|
whitelist?: string[];
|
|
2442
2488
|
transform?: (value: string) => string;
|
|
2443
2489
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
@@ -2478,7 +2524,8 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2478
2524
|
* Creates a Zod schema for Taiwan mobile phone number validation
|
|
2479
2525
|
*
|
|
2480
2526
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2481
|
-
* @param {
|
|
2527
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2528
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2482
2529
|
* @returns {MobileSchema<IsRequired>} Zod schema for mobile phone validation
|
|
2483
2530
|
*
|
|
2484
2531
|
* @description
|
|
@@ -2497,32 +2544,39 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2497
2544
|
* @example
|
|
2498
2545
|
* ```typescript
|
|
2499
2546
|
* // Basic mobile number validation
|
|
2500
|
-
* const basicSchema = mobile()
|
|
2547
|
+
* const basicSchema = mobile() // optional by default
|
|
2501
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
|
+
*
|
|
2502
2556
|
* basicSchema.parse("0987654321") // ✓ Valid
|
|
2503
2557
|
* basicSchema.parse("0812345678") // ✗ Invalid (wrong prefix)
|
|
2504
2558
|
*
|
|
2505
2559
|
* // With whitelist (only specific numbers allowed)
|
|
2506
|
-
* const whitelistSchema = mobile({
|
|
2560
|
+
* const whitelistSchema = mobile(false, {
|
|
2507
2561
|
* whitelist: ["0912345678", "0987654321"]
|
|
2508
2562
|
* })
|
|
2509
2563
|
* whitelistSchema.parse("0912345678") // ✓ Valid (in whitelist)
|
|
2510
2564
|
* whitelistSchema.parse("0911111111") // ✗ Invalid (not in whitelist)
|
|
2511
2565
|
*
|
|
2512
2566
|
* // Optional mobile number
|
|
2513
|
-
* const optionalSchema = mobile(
|
|
2567
|
+
* const optionalSchema = mobile(false)
|
|
2514
2568
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2515
2569
|
* optionalSchema.parse("0912345678") // ✓ Valid
|
|
2516
2570
|
*
|
|
2517
2571
|
* // With custom transformation
|
|
2518
|
-
* const transformSchema = mobile({
|
|
2572
|
+
* const transformSchema = mobile(false, {
|
|
2519
2573
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
2520
2574
|
* })
|
|
2521
2575
|
* transformSchema.parse("091-234-5678") // ✓ Valid (formatted input)
|
|
2522
2576
|
* transformSchema.parse("091 234 5678") // ✓ Valid (spaced input)
|
|
2523
2577
|
*
|
|
2524
2578
|
* // With custom error messages
|
|
2525
|
-
* const customSchema = mobile({
|
|
2579
|
+
* const customSchema = mobile(false, {
|
|
2526
2580
|
* i18n: {
|
|
2527
2581
|
* en: { invalid: "Please enter a valid Taiwan mobile number" },
|
|
2528
2582
|
* 'zh-TW': { invalid: "請輸入有效的台灣手機號碼" }
|
|
@@ -2534,7 +2588,7 @@ declare const validateTaiwanMobile: (value: string) => boolean;
|
|
|
2534
2588
|
* @see {@link MobileOptions} for all available configuration options
|
|
2535
2589
|
* @see {@link validateTaiwanMobile} for validation logic details
|
|
2536
2590
|
*/
|
|
2537
|
-
declare function mobile<IsRequired extends boolean =
|
|
2591
|
+
declare function mobile<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<MobileOptions<IsRequired>, 'required'>): MobileSchema<IsRequired>;
|
|
2538
2592
|
|
|
2539
2593
|
/**
|
|
2540
2594
|
* @fileoverview Taiwan Postal Code validator for Zod Kit
|
|
@@ -2605,7 +2659,6 @@ type PostalCodeFormat = "3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all";
|
|
|
2605
2659
|
* @property {Record<Locale, PostalCodeMessages>} [i18n] - Custom error messages for different locales
|
|
2606
2660
|
*/
|
|
2607
2661
|
type PostalCodeOptions<IsRequired extends boolean = true> = {
|
|
2608
|
-
required?: IsRequired;
|
|
2609
2662
|
format?: PostalCodeFormat;
|
|
2610
2663
|
strictValidation?: boolean;
|
|
2611
2664
|
allowDashes?: boolean;
|
|
@@ -2707,48 +2760,47 @@ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeForma
|
|
|
2707
2760
|
* modernSchema.parse("10001") // ✗ Invalid (5-digit not allowed)
|
|
2708
2761
|
*
|
|
2709
2762
|
* // Accept all formats
|
|
2710
|
-
* const flexibleSchema = postalCode({ format: "all" })
|
|
2763
|
+
* const flexibleSchema = postalCode(false, { format: "all" })
|
|
2711
2764
|
* flexibleSchema.parse("100") // ✓ Valid
|
|
2712
2765
|
* flexibleSchema.parse("10001") // ✓ Valid
|
|
2713
2766
|
* flexibleSchema.parse("100001") // ✓ Valid
|
|
2714
2767
|
*
|
|
2715
2768
|
* // Only 6-digit format (current standard)
|
|
2716
|
-
* const modernOnlySchema = postalCode({ format: "6" })
|
|
2769
|
+
* const modernOnlySchema = postalCode(false, { format: "6" })
|
|
2717
2770
|
* modernOnlySchema.parse("100001") // ✓ Valid
|
|
2718
2771
|
* modernOnlySchema.parse("100") // ✗ Invalid
|
|
2719
2772
|
*
|
|
2720
2773
|
* // With dashes allowed
|
|
2721
|
-
* const dashSchema = postalCode({ allowDashes: true })
|
|
2774
|
+
* const dashSchema = postalCode(false, { allowDashes: true })
|
|
2722
2775
|
* dashSchema.parse("100-001") // ✓ Valid (normalized to "100001")
|
|
2723
2776
|
* dashSchema.parse("100-01") // ✓ Valid if 5-digit format allowed
|
|
2724
2777
|
*
|
|
2725
2778
|
* // Specific areas only
|
|
2726
|
-
* const taipeiSchema = postalCode({
|
|
2779
|
+
* const taipeiSchema = postalCode(false, {
|
|
2727
2780
|
* allowedPrefixes: ["100", "103", "104", "105", "106"]
|
|
2728
2781
|
* })
|
|
2729
2782
|
* taipeiSchema.parse("100001") // ✓ Valid (Taipei area)
|
|
2730
2783
|
* taipeiSchema.parse("200001") // ✗ Invalid (not in allowlist)
|
|
2731
2784
|
*
|
|
2732
2785
|
* // Block specific areas
|
|
2733
|
-
* const blockedSchema = postalCode({
|
|
2786
|
+
* const blockedSchema = postalCode(false, {
|
|
2734
2787
|
* blockedPrefixes: ["999"] // Block test codes
|
|
2735
2788
|
* })
|
|
2736
2789
|
*
|
|
2737
2790
|
* // With warning for legacy format
|
|
2738
|
-
* const warnSchema = postalCode({
|
|
2791
|
+
* const warnSchema = postalCode(false, {
|
|
2739
2792
|
* format: "all",
|
|
2740
2793
|
* warn5Digit: true
|
|
2741
2794
|
* })
|
|
2742
2795
|
* // Will validate but may show warning for 5-digit codes
|
|
2743
2796
|
*
|
|
2744
2797
|
* // Optional with custom transformation
|
|
2745
|
-
* const optionalSchema = postalCode({
|
|
2746
|
-
* required: false,
|
|
2798
|
+
* const optionalSchema = postalCode(false, {
|
|
2747
2799
|
* transform: (value) => value.replace(/\D/g, '') // Remove non-digits
|
|
2748
2800
|
* })
|
|
2749
2801
|
*
|
|
2750
2802
|
* // Strict suffix validation for real postal codes
|
|
2751
|
-
* const strictSchema = postalCode({
|
|
2803
|
+
* const strictSchema = postalCode(false, {
|
|
2752
2804
|
* format: "6",
|
|
2753
2805
|
* strictSuffixValidation: true // Validates suffix range 001-999
|
|
2754
2806
|
* })
|
|
@@ -2756,7 +2808,7 @@ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeForma
|
|
|
2756
2808
|
* strictSchema.parse("100000") // ✗ Invalid (suffix 000 not allowed)
|
|
2757
2809
|
*
|
|
2758
2810
|
* // Deprecate 5-digit codes entirely
|
|
2759
|
-
* const modern2024Schema = postalCode({
|
|
2811
|
+
* const modern2024Schema = postalCode(false, {
|
|
2760
2812
|
* format: "all",
|
|
2761
2813
|
* deprecate5Digit: true // Throws error for any 5-digit code
|
|
2762
2814
|
* })
|
|
@@ -2769,7 +2821,7 @@ declare const validateTaiwanPostalCode: (value: string, format?: PostalCodeForma
|
|
|
2769
2821
|
* @see {@link PostalCodeFormat} for supported formats
|
|
2770
2822
|
* @see {@link validateTaiwanPostalCode} for validation logic details
|
|
2771
2823
|
*/
|
|
2772
|
-
declare function postalCode<IsRequired extends boolean =
|
|
2824
|
+
declare function postalCode<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<PostalCodeOptions<IsRequired>, 'required'>): PostalCodeSchema<IsRequired>;
|
|
2773
2825
|
|
|
2774
2826
|
/**
|
|
2775
2827
|
* @fileoverview Taiwan Landline Telephone Number validator for Zod Kit
|
|
@@ -2807,7 +2859,6 @@ type TelMessages = {
|
|
|
2807
2859
|
* @property {Record<Locale, TelMessages>} [i18n] - Custom error messages for different locales
|
|
2808
2860
|
*/
|
|
2809
2861
|
type TelOptions<IsRequired extends boolean = true> = {
|
|
2810
|
-
required?: IsRequired;
|
|
2811
2862
|
whitelist?: string[];
|
|
2812
2863
|
transform?: (value: string) => string;
|
|
2813
2864
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
@@ -2862,7 +2913,8 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2862
2913
|
* Creates a Zod schema for Taiwan landline telephone number validation
|
|
2863
2914
|
*
|
|
2864
2915
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
2865
|
-
* @param {
|
|
2916
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2917
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2866
2918
|
* @returns {TelSchema<IsRequired>} Zod schema for telephone number validation
|
|
2867
2919
|
*
|
|
2868
2920
|
* @description
|
|
@@ -2882,33 +2934,40 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2882
2934
|
* @example
|
|
2883
2935
|
* ```typescript
|
|
2884
2936
|
* // Basic telephone number validation
|
|
2885
|
-
* const basicSchema = tel()
|
|
2937
|
+
* const basicSchema = tel() // optional by default
|
|
2886
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
|
+
*
|
|
2887
2946
|
* basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
|
|
2888
2947
|
* basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
|
|
2889
2948
|
* basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
|
|
2890
2949
|
*
|
|
2891
2950
|
* // With whitelist (only specific numbers allowed)
|
|
2892
|
-
* const whitelistSchema = tel({
|
|
2951
|
+
* const whitelistSchema = tel(false, {
|
|
2893
2952
|
* whitelist: ["0223456789", "0312345678"]
|
|
2894
2953
|
* })
|
|
2895
2954
|
* whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
|
|
2896
2955
|
* whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
|
|
2897
2956
|
*
|
|
2898
2957
|
* // Optional telephone number
|
|
2899
|
-
* const optionalSchema = tel(
|
|
2958
|
+
* const optionalSchema = tel(false)
|
|
2900
2959
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2901
2960
|
* optionalSchema.parse("0223456789") // ✓ Valid
|
|
2902
2961
|
*
|
|
2903
2962
|
* // With custom transformation (remove separators)
|
|
2904
|
-
* const transformSchema = tel({
|
|
2963
|
+
* const transformSchema = tel(false, {
|
|
2905
2964
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
|
|
2906
2965
|
* })
|
|
2907
2966
|
* transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
|
|
2908
2967
|
* transformSchema.parse("02 2345 6789") // ✓ Valid (spaces removed)
|
|
2909
2968
|
*
|
|
2910
2969
|
* // With custom error messages
|
|
2911
|
-
* const customSchema = tel({
|
|
2970
|
+
* const customSchema = tel(false, {
|
|
2912
2971
|
* i18n: {
|
|
2913
2972
|
* en: { invalid: "Please enter a valid Taiwan landline number" },
|
|
2914
2973
|
* 'zh-TW': { invalid: "請輸入有效的台灣市話號碼" }
|
|
@@ -2920,7 +2979,7 @@ declare const validateTaiwanTel: (value: string) => boolean;
|
|
|
2920
2979
|
* @see {@link TelOptions} for all available configuration options
|
|
2921
2980
|
* @see {@link validateTaiwanTel} for validation logic details
|
|
2922
2981
|
*/
|
|
2923
|
-
declare function tel<IsRequired extends boolean =
|
|
2982
|
+
declare function tel<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TelOptions<IsRequired>, 'required'>): TelSchema<IsRequired>;
|
|
2924
2983
|
|
|
2925
2984
|
/**
|
|
2926
2985
|
* @fileoverview Taiwan Fax Number validator for Zod Kit
|
|
@@ -2958,7 +3017,6 @@ type FaxMessages = {
|
|
|
2958
3017
|
* @property {Record<Locale, FaxMessages>} [i18n] - Custom error messages for different locales
|
|
2959
3018
|
*/
|
|
2960
3019
|
type FaxOptions<IsRequired extends boolean = true> = {
|
|
2961
|
-
required?: IsRequired;
|
|
2962
3020
|
whitelist?: string[];
|
|
2963
3021
|
transform?: (value: string) => string;
|
|
2964
3022
|
defaultValue?: IsRequired extends true ? string : string | null;
|
|
@@ -3011,7 +3069,8 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3011
3069
|
* Creates a Zod schema for Taiwan fax number validation
|
|
3012
3070
|
*
|
|
3013
3071
|
* @template IsRequired - Whether the field is required (affects return type)
|
|
3014
|
-
* @param {
|
|
3072
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
3073
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
3015
3074
|
* @returns {FaxSchema<IsRequired>} Zod schema for fax number validation
|
|
3016
3075
|
*
|
|
3017
3076
|
* @description
|
|
@@ -3031,32 +3090,39 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3031
3090
|
* @example
|
|
3032
3091
|
* ```typescript
|
|
3033
3092
|
* // Basic fax number validation
|
|
3034
|
-
* const basicSchema = fax()
|
|
3093
|
+
* const basicSchema = fax() // optional by default
|
|
3035
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
|
+
*
|
|
3036
3102
|
* basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
|
|
3037
3103
|
* basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
|
|
3038
3104
|
* basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
|
|
3039
3105
|
*
|
|
3040
3106
|
* // With whitelist (only specific numbers allowed)
|
|
3041
|
-
* const whitelistSchema = fax({
|
|
3107
|
+
* const whitelistSchema = fax(false, {
|
|
3042
3108
|
* whitelist: ["0223456789", "0312345678"]
|
|
3043
3109
|
* })
|
|
3044
3110
|
* whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
|
|
3045
3111
|
* whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
|
|
3046
3112
|
*
|
|
3047
3113
|
* // Optional fax number
|
|
3048
|
-
* const optionalSchema = fax(
|
|
3114
|
+
* const optionalSchema = fax(false)
|
|
3049
3115
|
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
3050
3116
|
* optionalSchema.parse("0223456789") // ✓ Valid
|
|
3051
3117
|
*
|
|
3052
3118
|
* // With custom transformation
|
|
3053
|
-
* const transformSchema = fax({
|
|
3119
|
+
* const transformSchema = fax(false, {
|
|
3054
3120
|
* transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
|
|
3055
3121
|
* })
|
|
3056
3122
|
* transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
|
|
3057
3123
|
*
|
|
3058
3124
|
* // With custom error messages
|
|
3059
|
-
* const customSchema = fax({
|
|
3125
|
+
* const customSchema = fax(false, {
|
|
3060
3126
|
* i18n: {
|
|
3061
3127
|
* en: { invalid: "Please enter a valid Taiwan fax number" },
|
|
3062
3128
|
* 'zh-TW': { invalid: "請輸入有效的台灣傳真號碼" }
|
|
@@ -3068,6 +3134,6 @@ declare const validateTaiwanFax: (value: string) => boolean;
|
|
|
3068
3134
|
* @see {@link FaxOptions} for all available configuration options
|
|
3069
3135
|
* @see {@link validateTaiwanFax} for validation logic details
|
|
3070
3136
|
*/
|
|
3071
|
-
declare function fax<IsRequired extends boolean =
|
|
3137
|
+
declare function fax<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<FaxOptions<IsRequired>, 'required'>): FaxSchema<IsRequired>;
|
|
3072
3138
|
|
|
3073
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 };
|