@hy_ong/zod-kit 0.2.0 → 0.2.2
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/.github/workflows/ci.yml +24 -0
- package/CLAUDE.md +64 -22
- package/dist/chunk-2SWEVDFZ.js +134 -0
- package/dist/chunk-32JI34CV.cjs +146 -0
- package/dist/chunk-42C5OHRK.js +71 -0
- package/dist/chunk-46VAH2BJ.js +160 -0
- package/dist/chunk-5JGTDL3Y.js +87 -0
- package/dist/chunk-5LEXCVLX.js +257 -0
- package/dist/chunk-6AAP4LPF.js +2606 -0
- package/dist/chunk-B4EZYZOK.cjs +215 -0
- package/dist/chunk-COYKBWTI.js +161 -0
- package/dist/chunk-DFJZ3NS2.cjs +151 -0
- package/dist/chunk-EDHT4LPO.js +118 -0
- package/dist/chunk-EGHL277K.cjs +165 -0
- package/dist/chunk-ERH4NIMU.cjs +69 -0
- package/dist/chunk-FM3EZ72O.js +165 -0
- package/dist/chunk-GJIRDBZJ.cjs +90 -0
- package/dist/chunk-H2XTEM4M.js +696 -0
- package/dist/chunk-HMSM6FFA.cjs +181 -0
- package/dist/chunk-HTEHINI7.cjs +177 -0
- package/dist/chunk-JOLSGZGN.cjs +696 -0
- package/dist/chunk-JXY7APBU.js +69 -0
- package/dist/chunk-K2UOY6TB.js +136 -0
- package/dist/chunk-KFOHKTFD.js +61 -0
- package/dist/chunk-L4HSIKTU.cjs +135 -0
- package/dist/chunk-LH7ZB4BK.js +124 -0
- package/dist/chunk-LL4ZWLGO.js +90 -0
- package/dist/chunk-M6MTP3NY.cjs +99 -0
- package/dist/chunk-MHJFYYGV.js +215 -0
- package/dist/chunk-MINMXGW3.js +135 -0
- package/dist/chunk-MM7IL2RG.js +181 -0
- package/dist/chunk-OPQJWHXN.cjs +301 -0
- package/dist/chunk-ORFHDJII.cjs +136 -0
- package/dist/chunk-ORVV4MCF.cjs +87 -0
- package/dist/chunk-QICQ6YEY.js +75 -0
- package/dist/chunk-RKUQREMW.js +127 -0
- package/dist/chunk-RO47DKQG.js +146 -0
- package/dist/chunk-RRPXIRTQ.cjs +257 -0
- package/dist/chunk-RYFG2GKM.cjs +118 -0
- package/dist/chunk-STNHTRG7.cjs +124 -0
- package/dist/chunk-TFGS34VD.cjs +71 -0
- package/dist/chunk-TQXDUMML.cjs +61 -0
- package/dist/chunk-UBK3VCVH.cjs +134 -0
- package/dist/chunk-UCOXAZJF.cjs +2606 -0
- package/dist/chunk-UQZKFAFX.js +130 -0
- package/dist/chunk-VB2KV2ZM.cjs +130 -0
- package/dist/chunk-WABKPFPK.js +151 -0
- package/dist/chunk-WDI4QJMQ.js +177 -0
- package/dist/chunk-YDH3L27K.cjs +127 -0
- package/dist/chunk-YIM3D2AD.js +99 -0
- package/dist/chunk-YPSEIDUR.cjs +160 -0
- package/dist/chunk-ZNJLWJX3.cjs +75 -0
- package/dist/chunk-ZTFCJCPO.cjs +161 -0
- package/dist/chunk-ZXUMK2RR.js +301 -0
- package/dist/common/boolean.cjs +7 -0
- package/dist/common/boolean.d.cts +119 -0
- package/dist/common/boolean.d.ts +119 -0
- package/dist/common/boolean.js +7 -0
- package/dist/common/color.cjs +9 -0
- package/dist/common/color.d.cts +26 -0
- package/dist/common/color.d.ts +26 -0
- package/dist/common/color.js +9 -0
- package/dist/common/coordinate.cjs +11 -0
- package/dist/common/coordinate.d.cts +23 -0
- package/dist/common/coordinate.d.ts +23 -0
- package/dist/common/coordinate.js +11 -0
- package/dist/common/credit-card.cjs +11 -0
- package/dist/common/credit-card.d.cts +22 -0
- package/dist/common/credit-card.d.ts +22 -0
- package/dist/common/credit-card.js +11 -0
- package/dist/common/date.cjs +7 -0
- package/dist/common/date.d.cts +174 -0
- package/dist/common/date.d.ts +174 -0
- package/dist/common/date.js +7 -0
- package/dist/common/datetime.cjs +15 -0
- package/dist/common/datetime.d.cts +301 -0
- package/dist/common/datetime.d.ts +301 -0
- package/dist/common/datetime.js +15 -0
- package/dist/common/email.cjs +7 -0
- package/dist/common/email.d.cts +149 -0
- package/dist/common/email.d.ts +149 -0
- package/dist/common/email.js +7 -0
- package/dist/common/file.cjs +7 -0
- package/dist/common/file.d.cts +178 -0
- package/dist/common/file.d.ts +178 -0
- package/dist/common/file.js +7 -0
- package/dist/common/id.cjs +13 -0
- package/dist/common/id.d.cts +288 -0
- package/dist/common/id.d.ts +288 -0
- package/dist/common/id.js +13 -0
- package/dist/common/ip.cjs +11 -0
- package/dist/common/ip.d.cts +25 -0
- package/dist/common/ip.d.ts +25 -0
- package/dist/common/ip.js +11 -0
- package/dist/common/number.cjs +7 -0
- package/dist/common/number.d.cts +167 -0
- package/dist/common/number.d.ts +167 -0
- package/dist/common/number.js +7 -0
- package/dist/common/password.cjs +7 -0
- package/dist/common/password.d.cts +192 -0
- package/dist/common/password.d.ts +192 -0
- package/dist/common/password.js +7 -0
- package/dist/common/text.cjs +7 -0
- package/dist/common/text.d.cts +156 -0
- package/dist/common/text.d.ts +156 -0
- package/dist/common/text.js +7 -0
- package/dist/common/time.cjs +15 -0
- package/dist/common/time.d.cts +268 -0
- package/dist/common/time.d.ts +268 -0
- package/dist/common/time.js +15 -0
- package/dist/common/url.cjs +7 -0
- package/dist/common/url.d.cts +196 -0
- package/dist/common/url.d.ts +196 -0
- package/dist/common/url.js +7 -0
- package/dist/config-CABSSvAp.d.cts +5 -0
- package/dist/config-CABSSvAp.d.ts +5 -0
- package/dist/index.cjs +180 -5255
- package/dist/index.d.cts +28 -3150
- package/dist/index.d.ts +28 -3150
- package/dist/index.js +135 -5131
- package/dist/taiwan/bank-account.cjs +11 -0
- package/dist/taiwan/bank-account.d.cts +22 -0
- package/dist/taiwan/bank-account.d.ts +22 -0
- package/dist/taiwan/bank-account.js +11 -0
- package/dist/taiwan/business-id.cjs +9 -0
- package/dist/taiwan/business-id.d.cts +133 -0
- package/dist/taiwan/business-id.d.ts +133 -0
- package/dist/taiwan/business-id.js +9 -0
- package/dist/taiwan/fax.cjs +9 -0
- package/dist/taiwan/fax.d.cts +157 -0
- package/dist/taiwan/fax.d.ts +157 -0
- package/dist/taiwan/fax.js +9 -0
- package/dist/taiwan/invoice.cjs +9 -0
- package/dist/taiwan/invoice.d.cts +17 -0
- package/dist/taiwan/invoice.d.ts +17 -0
- package/dist/taiwan/invoice.js +9 -0
- package/dist/taiwan/license-plate.cjs +9 -0
- package/dist/taiwan/license-plate.d.cts +19 -0
- package/dist/taiwan/license-plate.d.ts +19 -0
- package/dist/taiwan/license-plate.js +9 -0
- package/dist/taiwan/mobile.cjs +9 -0
- package/dist/taiwan/mobile.d.cts +146 -0
- package/dist/taiwan/mobile.d.ts +146 -0
- package/dist/taiwan/mobile.js +9 -0
- package/dist/taiwan/national-id.cjs +15 -0
- package/dist/taiwan/national-id.d.cts +214 -0
- package/dist/taiwan/national-id.d.ts +214 -0
- package/dist/taiwan/national-id.js +15 -0
- package/dist/taiwan/passport.cjs +9 -0
- package/dist/taiwan/passport.d.cts +19 -0
- package/dist/taiwan/passport.d.ts +19 -0
- package/dist/taiwan/passport.js +9 -0
- package/dist/taiwan/postal-code.cjs +17 -0
- package/dist/taiwan/postal-code.d.cts +237 -0
- package/dist/taiwan/postal-code.d.ts +237 -0
- package/dist/taiwan/postal-code.js +17 -0
- package/dist/taiwan/tel.cjs +9 -0
- package/dist/taiwan/tel.d.cts +162 -0
- package/dist/taiwan/tel.d.ts +162 -0
- package/dist/taiwan/tel.js +9 -0
- package/package.json +132 -6
- package/src/i18n/locales/en-GB.json +51 -0
- package/src/i18n/locales/en-US.json +52 -1
- package/src/i18n/locales/id-ID.json +51 -0
- package/src/i18n/locales/ja-JP.json +51 -0
- package/src/i18n/locales/ko-KR.json +51 -0
- package/src/i18n/locales/ms-MY.json +51 -0
- package/src/i18n/locales/th-TH.json +51 -0
- package/src/i18n/locales/vi-VN.json +51 -0
- package/src/i18n/locales/zh-CN.json +51 -0
- package/src/i18n/locales/zh-TW.json +51 -0
- package/src/index.ts +10 -2
- package/src/validators/common/color.ts +192 -0
- package/src/validators/common/coordinate.ts +159 -0
- package/src/validators/common/credit-card.ts +134 -0
- package/src/validators/common/id.ts +45 -3
- package/src/validators/common/ip.ts +210 -0
- package/src/validators/taiwan/bank-account.ts +176 -0
- package/src/validators/taiwan/invoice.ts +84 -0
- package/src/validators/taiwan/license-plate.ts +110 -0
- package/src/validators/taiwan/passport.ts +103 -0
- package/tests/common/color.test.ts +587 -0
- package/tests/common/coordinate.test.ts +345 -0
- package/tests/common/credit-card.test.ts +378 -0
- package/tests/common/id.test.ts +68 -3
- package/tests/common/ip.test.ts +419 -0
- package/tests/taiwan/bank-account.test.ts +286 -0
- package/tests/taiwan/invoice.test.ts +227 -0
- package/tests/taiwan/license-plate.test.ts +280 -0
- package/tests/taiwan/passport.test.ts +277 -0
- package/tsup.config.ts +36 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3150 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
shouldBeTrue?: string;
|
|
30
|
-
shouldBeFalse?: string;
|
|
31
|
-
invalid?: string;
|
|
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
|
-
*/
|
|
47
|
-
type BooleanOptions<IsRequired extends boolean = true> = {
|
|
48
|
-
defaultValue?: IsRequired extends true ? boolean : boolean | null;
|
|
49
|
-
shouldBe?: boolean;
|
|
50
|
-
truthyValues?: unknown[];
|
|
51
|
-
falsyValues?: unknown[];
|
|
52
|
-
strict?: boolean;
|
|
53
|
-
transform?: (value: boolean) => boolean;
|
|
54
|
-
i18n?: Partial<Record<Locale, Partial<BooleanMessages>>>;
|
|
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
|
-
*/
|
|
63
|
-
type BooleanSchema<IsRequired extends boolean> = IsRequired extends true ? ZodBoolean : ZodNullable<ZodBoolean>;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
153
|
-
type DateMessages = {
|
|
154
|
-
required?: string;
|
|
155
|
-
invalid?: string;
|
|
156
|
-
format?: string;
|
|
157
|
-
min?: string;
|
|
158
|
-
max?: string;
|
|
159
|
-
includes?: string;
|
|
160
|
-
excludes?: string;
|
|
161
|
-
past?: string;
|
|
162
|
-
future?: string;
|
|
163
|
-
today?: string;
|
|
164
|
-
notToday?: string;
|
|
165
|
-
weekday?: string;
|
|
166
|
-
notWeekday?: string;
|
|
167
|
-
weekend?: string;
|
|
168
|
-
notWeekend?: string;
|
|
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
|
-
*/
|
|
192
|
-
type DateOptions<IsRequired extends boolean = true> = {
|
|
193
|
-
min?: string;
|
|
194
|
-
max?: string;
|
|
195
|
-
format?: string;
|
|
196
|
-
includes?: string;
|
|
197
|
-
excludes?: string | string[];
|
|
198
|
-
mustBePast?: boolean;
|
|
199
|
-
mustBeFuture?: boolean;
|
|
200
|
-
mustBeToday?: boolean;
|
|
201
|
-
mustNotBeToday?: boolean;
|
|
202
|
-
weekdaysOnly?: boolean;
|
|
203
|
-
weekendsOnly?: boolean;
|
|
204
|
-
transform?: (value: string) => string;
|
|
205
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
206
|
-
i18n?: Partial<Record<Locale, Partial<DateMessages>>>;
|
|
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
|
-
*/
|
|
215
|
-
type DateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
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?: Partial<Record<Locale, Partial<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>;
|
|
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
|
-
*/
|
|
613
|
-
type EmailMessages = {
|
|
614
|
-
required?: string;
|
|
615
|
-
invalid?: string;
|
|
616
|
-
minLength?: string;
|
|
617
|
-
maxLength?: string;
|
|
618
|
-
includes?: string;
|
|
619
|
-
domain?: string;
|
|
620
|
-
domainBlacklist?: string;
|
|
621
|
-
businessOnly?: string;
|
|
622
|
-
noDisposable?: string;
|
|
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
|
-
*/
|
|
644
|
-
type EmailOptions<IsRequired extends boolean = true> = {
|
|
645
|
-
domain?: string | string[];
|
|
646
|
-
domainBlacklist?: string[];
|
|
647
|
-
minLength?: number;
|
|
648
|
-
maxLength?: number;
|
|
649
|
-
includes?: string;
|
|
650
|
-
excludes?: string | string[];
|
|
651
|
-
allowSubdomains?: boolean;
|
|
652
|
-
businessOnly?: boolean;
|
|
653
|
-
noDisposable?: boolean;
|
|
654
|
-
lowercase?: boolean;
|
|
655
|
-
transform?: (value: string) => string;
|
|
656
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
657
|
-
i18n?: Partial<Record<Locale, Partial<EmailMessages>>>;
|
|
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
|
-
*/
|
|
666
|
-
type EmailSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
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?: Partial<Record<Locale, Partial<FileMessages>>>;
|
|
824
|
-
};
|
|
825
|
-
/**
|
|
826
|
-
* Type alias for file validation schema based on required flag
|
|
827
|
-
*
|
|
828
|
-
* @template IsRequired - Whether the field is required
|
|
829
|
-
* @description Returns ZodType with proper input/output types based on required flag
|
|
830
|
-
*/
|
|
831
|
-
type FileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodType<File, File | null> : ZodType<File | null, File | null>;
|
|
832
|
-
/**
|
|
833
|
-
* Creates a Zod schema for file validation with comprehensive filtering options
|
|
834
|
-
*
|
|
835
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
836
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
837
|
-
* @param {Omit<FileOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
838
|
-
* @returns {FileSchema<IsRequired>} Zod schema for file validation
|
|
839
|
-
*
|
|
840
|
-
* @description
|
|
841
|
-
* Creates a comprehensive file validator with MIME type filtering, size validation,
|
|
842
|
-
* extension validation, and extensive customization options.
|
|
843
|
-
*
|
|
844
|
-
* Features:
|
|
845
|
-
* - File size validation (min/max)
|
|
846
|
-
* - MIME type whitelist/blacklist support
|
|
847
|
-
* - File extension whitelist/blacklist support
|
|
848
|
-
* - File name pattern validation
|
|
849
|
-
* - Predefined file category filters (image, document, video, audio, archive)
|
|
850
|
-
* - Case-sensitive/insensitive extension matching
|
|
851
|
-
* - Custom transformation functions
|
|
852
|
-
* - Comprehensive internationalization
|
|
853
|
-
*
|
|
854
|
-
* @example
|
|
855
|
-
* ```typescript
|
|
856
|
-
* // Basic file validation
|
|
857
|
-
* const basicSchema = file() // optional by default
|
|
858
|
-
* basicSchema.parse(new File(["content"], "test.txt"))
|
|
859
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
860
|
-
*
|
|
861
|
-
* // Required validation
|
|
862
|
-
* const requiredSchema = parse(new File(["content"], "test.txt"))
|
|
863
|
-
(true)
|
|
864
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
* // Size restrictions
|
|
868
|
-
* const sizeSchema = file(false, {
|
|
869
|
-
* maxSize: 1024 * 1024, // 1MB
|
|
870
|
-
* minSize: 1024 // 1KB
|
|
871
|
-
* })
|
|
872
|
-
*
|
|
873
|
-
* // Extension restrictions
|
|
874
|
-
* const imageSchema = file(false, {
|
|
875
|
-
* extension: [".jpg", ".png", ".gif"],
|
|
876
|
-
* maxSize: 5 * 1024 * 1024 // 5MB
|
|
877
|
-
* })
|
|
878
|
-
*
|
|
879
|
-
* // MIME type restrictions
|
|
880
|
-
* const documentSchema = file(false, {
|
|
881
|
-
* type: ["application/pdf", "application/msword"],
|
|
882
|
-
* maxSize: 10 * 1024 * 1024 // 10MB
|
|
883
|
-
* })
|
|
884
|
-
*
|
|
885
|
-
* // Image files only
|
|
886
|
-
* const imageOnlySchema = file(false, { imageOnly: true })
|
|
887
|
-
*
|
|
888
|
-
* // Document files only
|
|
889
|
-
* const docOnlySchema = file(false, { documentOnly: true })
|
|
890
|
-
*
|
|
891
|
-
* // Name pattern validation
|
|
892
|
-
* const patternSchema = file(false, {
|
|
893
|
-
* namePattern: /^[a-zA-Z0-9_-]+\.(pdf|doc|docx)$/,
|
|
894
|
-
* maxSize: 5 * 1024 * 1024
|
|
895
|
-
* })
|
|
896
|
-
*
|
|
897
|
-
* // Optional with default
|
|
898
|
-
* const optionalSchema = file(false, {
|
|
899
|
-
* defaultValue: null
|
|
900
|
-
* })
|
|
901
|
-
* ```
|
|
902
|
-
*
|
|
903
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
904
|
-
* @see {@link FileOptions} for all available configuration options
|
|
905
|
-
*/
|
|
906
|
-
declare function file<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<FileOptions<IsRequired>, "required">): FileSchema<IsRequired>;
|
|
907
|
-
|
|
908
|
-
/**
|
|
909
|
-
* @fileoverview ID validator for Zod Kit
|
|
910
|
-
*
|
|
911
|
-
* Provides comprehensive ID validation with support for multiple ID formats,
|
|
912
|
-
* auto-detection, custom patterns, and flexible validation options.
|
|
913
|
-
*
|
|
914
|
-
* @author Ong Hoe Yuan
|
|
915
|
-
* @version 0.0.5
|
|
916
|
-
*/
|
|
917
|
-
|
|
918
|
-
/**
|
|
919
|
-
* Type definition for ID validation error messages
|
|
920
|
-
*
|
|
921
|
-
* @interface IdMessages
|
|
922
|
-
* @property {string} [required] - Message when field is required but empty
|
|
923
|
-
* @property {string} [invalid] - Message when ID format is invalid
|
|
924
|
-
* @property {string} [minLength] - Message when ID is too short
|
|
925
|
-
* @property {string} [maxLength] - Message when ID is too long
|
|
926
|
-
* @property {string} [numeric] - Message when numeric ID format is invalid
|
|
927
|
-
* @property {string} [uuid] - Message when UUID format is invalid
|
|
928
|
-
* @property {string} [objectId] - Message when MongoDB ObjectId format is invalid
|
|
929
|
-
* @property {string} [nanoid] - Message when Nano ID format is invalid
|
|
930
|
-
* @property {string} [snowflake] - Message when Snowflake ID format is invalid
|
|
931
|
-
* @property {string} [cuid] - Message when CUID format is invalid
|
|
932
|
-
* @property {string} [ulid] - Message when ULID format is invalid
|
|
933
|
-
* @property {string} [shortid] - Message when ShortId format is invalid
|
|
934
|
-
* @property {string} [customFormat] - Message when custom regex format is invalid
|
|
935
|
-
* @property {string} [includes] - Message when ID doesn't contain required string
|
|
936
|
-
* @property {string} [excludes] - Message when ID contains forbidden string
|
|
937
|
-
* @property {string} [startsWith] - Message when ID doesn't start with required string
|
|
938
|
-
* @property {string} [endsWith] - Message when ID doesn't end with required string
|
|
939
|
-
*/
|
|
940
|
-
type IdMessages = {
|
|
941
|
-
required?: string;
|
|
942
|
-
invalid?: string;
|
|
943
|
-
minLength?: string;
|
|
944
|
-
maxLength?: string;
|
|
945
|
-
numeric?: string;
|
|
946
|
-
uuid?: string;
|
|
947
|
-
objectId?: string;
|
|
948
|
-
nanoid?: string;
|
|
949
|
-
snowflake?: string;
|
|
950
|
-
cuid?: string;
|
|
951
|
-
ulid?: string;
|
|
952
|
-
shortid?: string;
|
|
953
|
-
customFormat?: string;
|
|
954
|
-
includes?: string;
|
|
955
|
-
excludes?: string;
|
|
956
|
-
startsWith?: string;
|
|
957
|
-
endsWith?: string;
|
|
958
|
-
};
|
|
959
|
-
/**
|
|
960
|
-
* Supported ID types for validation
|
|
961
|
-
*
|
|
962
|
-
* @typedef {string} IdType
|
|
963
|
-
*
|
|
964
|
-
* Available types:
|
|
965
|
-
* - numeric: Pure numeric IDs (1, 123, 999999)
|
|
966
|
-
* - uuid: UUID v4 format (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx)
|
|
967
|
-
* - objectId: MongoDB ObjectId (24-character hexadecimal)
|
|
968
|
-
* - nanoid: Nano ID format (21-character URL-safe)
|
|
969
|
-
* - snowflake: Twitter Snowflake (19-digit number)
|
|
970
|
-
* - cuid: CUID format (25-character starting with 'c')
|
|
971
|
-
* - ulid: ULID format (26-character case-insensitive)
|
|
972
|
-
* - shortid: ShortId format (7-14 character URL-safe)
|
|
973
|
-
* - auto: Auto-detect format from the value
|
|
974
|
-
*/
|
|
975
|
-
type IdType = "numeric" | "uuid" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
|
|
976
|
-
/**
|
|
977
|
-
* Configuration options for ID validation
|
|
978
|
-
*
|
|
979
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
980
|
-
* @template Type - The ID type being validated
|
|
981
|
-
*
|
|
982
|
-
* @interface IdOptions
|
|
983
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
984
|
-
* @property {Type} [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 {any} [defaultValue] - Default value when input is empty (string for string types, number for numeric)
|
|
996
|
-
* @property {Record<Locale, IdMessages>} [i18n] - Custom error messages for different locales
|
|
997
|
-
*/
|
|
998
|
-
type IdOptions<Type extends IdType | undefined = undefined> = {
|
|
999
|
-
type?: Type;
|
|
1000
|
-
minLength?: number;
|
|
1001
|
-
maxLength?: number;
|
|
1002
|
-
allowedTypes?: IdType[];
|
|
1003
|
-
customRegex?: RegExp;
|
|
1004
|
-
includes?: string;
|
|
1005
|
-
excludes?: string | string[];
|
|
1006
|
-
startsWith?: string;
|
|
1007
|
-
endsWith?: string;
|
|
1008
|
-
caseSensitive?: boolean;
|
|
1009
|
-
transform?: (value: string) => string;
|
|
1010
|
-
defaultValue?: any;
|
|
1011
|
-
i18n?: Partial<Record<Locale, Partial<IdMessages>>>;
|
|
1012
|
-
};
|
|
1013
|
-
/**
|
|
1014
|
-
* Type alias for ID validation schema based on required flag and ID type
|
|
1015
|
-
*
|
|
1016
|
-
* @template IsRequired - Whether the field is required
|
|
1017
|
-
* @template IdType - The ID type being validated
|
|
1018
|
-
* @typedef IdSchema
|
|
1019
|
-
* @description Returns appropriate Zod type based on required flag and ID type:
|
|
1020
|
-
* - numeric type: ZodNumber or ZodNullable<ZodNumber>
|
|
1021
|
-
* - other types: ZodString or ZodNullable<ZodString>
|
|
1022
|
-
*/
|
|
1023
|
-
type IdSchema<IsRequired extends boolean, Type extends IdType | undefined = undefined> = Type extends "numeric" ? IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber> : IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
1024
|
-
/**
|
|
1025
|
-
* Regular expression patterns for different ID formats
|
|
1026
|
-
*
|
|
1027
|
-
* @constant {Record<string, RegExp>} ID_PATTERNS
|
|
1028
|
-
* @description Maps each ID type to its corresponding regex pattern
|
|
1029
|
-
*/
|
|
1030
|
-
declare const ID_PATTERNS: {
|
|
1031
|
-
readonly numeric: RegExp;
|
|
1032
|
-
readonly uuid: RegExp;
|
|
1033
|
-
readonly objectId: RegExp;
|
|
1034
|
-
readonly nanoid: RegExp;
|
|
1035
|
-
readonly snowflake: RegExp;
|
|
1036
|
-
readonly cuid: RegExp;
|
|
1037
|
-
readonly ulid: RegExp;
|
|
1038
|
-
readonly shortid: RegExp;
|
|
1039
|
-
};
|
|
1040
|
-
/**
|
|
1041
|
-
* Detects the ID type of a given value using pattern matching
|
|
1042
|
-
*
|
|
1043
|
-
* @param {string} value - The ID value to analyze
|
|
1044
|
-
* @returns {IdType | null} The detected ID type or null if no pattern matches
|
|
1045
|
-
*
|
|
1046
|
-
* @description
|
|
1047
|
-
* Attempts to identify the ID type by testing against known patterns.
|
|
1048
|
-
* Patterns are ordered by specificity to avoid false positives.
|
|
1049
|
-
* More specific patterns (UUID, ObjectId) are tested before generic ones (numeric, shortid).
|
|
1050
|
-
*
|
|
1051
|
-
* @example
|
|
1052
|
-
* ```typescript
|
|
1053
|
-
* detectIdType("550e8400-e29b-41d4-a716-446655440000") // "uuid"
|
|
1054
|
-
* detectIdType("507f1f77bcf86cd799439011") // "objectId"
|
|
1055
|
-
* detectIdType("V1StGXR8_Z5jdHi6B-myT") // "nanoid"
|
|
1056
|
-
* detectIdType("123456789") // "numeric"
|
|
1057
|
-
* detectIdType("invalid-id") // null
|
|
1058
|
-
* ```
|
|
1059
|
-
*/
|
|
1060
|
-
declare const detectIdType: (value: string) => IdType | null;
|
|
1061
|
-
/**
|
|
1062
|
-
* Validates if a value matches the specified ID type
|
|
1063
|
-
*
|
|
1064
|
-
* @param {string} value - The ID value to validate
|
|
1065
|
-
* @param {IdType} type - The expected ID type
|
|
1066
|
-
* @returns {boolean} True if the value matches the specified type
|
|
1067
|
-
*
|
|
1068
|
-
* @description
|
|
1069
|
-
* Validates a specific ID type using regex patterns or auto-detection.
|
|
1070
|
-
* For "auto" type, uses detectIdType to check if any known pattern matches.
|
|
1071
|
-
*
|
|
1072
|
-
* @example
|
|
1073
|
-
* ```typescript
|
|
1074
|
-
* validateIdType("123456", "numeric") // true
|
|
1075
|
-
* validateIdType("abc123", "numeric") // false
|
|
1076
|
-
* validateIdType("550e8400-e29b-41d4-a716-446655440000", "uuid") // true
|
|
1077
|
-
* validateIdType("invalid-uuid", "uuid") // false
|
|
1078
|
-
* ```
|
|
1079
|
-
*/
|
|
1080
|
-
declare const validateIdType: (value: string, type: IdType) => boolean;
|
|
1081
|
-
/**
|
|
1082
|
-
* Creates a Zod schema for ID validation with comprehensive format support
|
|
1083
|
-
*
|
|
1084
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1085
|
-
* @template Type - The ID type being validated (affects return type for numeric)
|
|
1086
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
1087
|
-
* @returns {IdSchema<IsRequired, Type>} Zod schema for ID validation
|
|
1088
|
-
*
|
|
1089
|
-
* @description
|
|
1090
|
-
* Creates a comprehensive ID validator with support for multiple ID formats,
|
|
1091
|
-
* auto-detection, custom patterns, and flexible validation options.
|
|
1092
|
-
*
|
|
1093
|
-
* Features:
|
|
1094
|
-
* - Multiple ID format support (UUID, ObjectId, Snowflake, etc.)
|
|
1095
|
-
* - Auto-detection of ID types
|
|
1096
|
-
* - Custom regex pattern support
|
|
1097
|
-
* - Length validation
|
|
1098
|
-
* - Content validation (includes, excludes, startsWith, endsWith)
|
|
1099
|
-
* - Case sensitivity control
|
|
1100
|
-
* - Multiple allowed types
|
|
1101
|
-
* - Custom transformation functions
|
|
1102
|
-
* - Comprehensive internationalization
|
|
1103
|
-
*
|
|
1104
|
-
* @example
|
|
1105
|
-
* ```typescript
|
|
1106
|
-
* // Auto-detect ID format
|
|
1107
|
-
* const autoSchema = id()
|
|
1108
|
-
* autoSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
|
|
1109
|
-
* autoSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
|
|
1110
|
-
* autoSchema.parse("123456") // ✓ Valid (numeric)
|
|
1111
|
-
*
|
|
1112
|
-
* // Specific ID type
|
|
1113
|
-
* const uuidSchema = id(false, { type: "uuid" })
|
|
1114
|
-
* uuidSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid
|
|
1115
|
-
* uuidSchema.parse("invalid-uuid") // ✗ Invalid
|
|
1116
|
-
*
|
|
1117
|
-
* // Multiple allowed types
|
|
1118
|
-
* const multiSchema = id(false, { allowedTypes: ["uuid", "objectId"] })
|
|
1119
|
-
* multiSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
|
|
1120
|
-
* multiSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
|
|
1121
|
-
* multiSchema.parse("123456") // ✗ Invalid (numeric not allowed)
|
|
1122
|
-
*
|
|
1123
|
-
* // Custom regex pattern
|
|
1124
|
-
* const customSchema = id(false, { customRegex: /^CUST_\d{6}$/ })
|
|
1125
|
-
* customSchema.parse("CUST_123456") // ✓ Valid
|
|
1126
|
-
* customSchema.parse("invalid") // ✗ Invalid
|
|
1127
|
-
*
|
|
1128
|
-
* // Content validation
|
|
1129
|
-
* const prefixSchema = id(false, {
|
|
1130
|
-
* type: "auto",
|
|
1131
|
-
* startsWith: "user_",
|
|
1132
|
-
* minLength: 10
|
|
1133
|
-
* })
|
|
1134
|
-
* prefixSchema.parse("user_123456") // ✓ Valid
|
|
1135
|
-
*
|
|
1136
|
-
* // Case insensitive
|
|
1137
|
-
* const caseInsensitiveSchema = id(false, {
|
|
1138
|
-
* type: "uuid",
|
|
1139
|
-
* caseSensitive: false
|
|
1140
|
-
* })
|
|
1141
|
-
* caseInsensitiveSchema.parse("550E8400-E29B-41D4-A716-446655440000") // ✓ Valid
|
|
1142
|
-
*
|
|
1143
|
-
* // Optional with default
|
|
1144
|
-
* const optionalSchema = id(false, {
|
|
1145
|
-
* defaultValue: null
|
|
1146
|
-
* })
|
|
1147
|
-
* ```
|
|
1148
|
-
*
|
|
1149
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1150
|
-
* @see {@link IdOptions} for all available configuration options
|
|
1151
|
-
* @see {@link IdType} for supported ID types
|
|
1152
|
-
* @see {@link detectIdType} for auto-detection logic
|
|
1153
|
-
* @see {@link validateIdType} for type-specific validation
|
|
1154
|
-
*/
|
|
1155
|
-
declare function id<IsRequired extends boolean = false>(required?: IsRequired): IdSchema<IsRequired, undefined>;
|
|
1156
|
-
declare function id<IsRequired extends boolean = false>(required: IsRequired, options: Omit<IdOptions<"numeric">, "required"> & {
|
|
1157
|
-
type: "numeric";
|
|
1158
|
-
}): IdSchema<IsRequired, "numeric">;
|
|
1159
|
-
declare function id<IsRequired extends boolean = false, Type extends Exclude<IdType, "numeric"> = Exclude<IdType, "numeric">>(required: IsRequired, options: Omit<IdOptions<Type>, "required"> & {
|
|
1160
|
-
type: Type;
|
|
1161
|
-
}): IdSchema<IsRequired, Type>;
|
|
1162
|
-
declare function id<IsRequired extends boolean = false>(required: IsRequired, options: Omit<IdOptions, "required"> & {
|
|
1163
|
-
type?: never;
|
|
1164
|
-
}): IdSchema<IsRequired, undefined>;
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* @fileoverview Number validator for Zod Kit
|
|
1168
|
-
*
|
|
1169
|
-
* Provides comprehensive number validation with type constraints, range validation,
|
|
1170
|
-
* precision control, and advanced parsing features including comma-separated numbers.
|
|
1171
|
-
*
|
|
1172
|
-
* @author Ong Hoe Yuan
|
|
1173
|
-
* @version 0.0.5
|
|
1174
|
-
*/
|
|
1175
|
-
|
|
1176
|
-
/**
|
|
1177
|
-
* Type definition for number validation error messages
|
|
1178
|
-
*
|
|
1179
|
-
* @interface NumberMessages
|
|
1180
|
-
* @property {string} [required] - Message when field is required but empty
|
|
1181
|
-
* @property {string} [invalid] - Message when value is not a valid number
|
|
1182
|
-
* @property {string} [integer] - Message when integer is required but float provided
|
|
1183
|
-
* @property {string} [float] - Message when float is required but integer provided
|
|
1184
|
-
* @property {string} [min] - Message when number is below minimum value
|
|
1185
|
-
* @property {string} [max] - Message when number exceeds maximum value
|
|
1186
|
-
* @property {string} [positive] - Message when positive number is required
|
|
1187
|
-
* @property {string} [negative] - Message when negative number is required
|
|
1188
|
-
* @property {string} [nonNegative] - Message when non-negative number is required
|
|
1189
|
-
* @property {string} [nonPositive] - Message when non-positive number is required
|
|
1190
|
-
* @property {string} [multipleOf] - Message when number is not a multiple of specified value
|
|
1191
|
-
* @property {string} [finite] - Message when finite number is required
|
|
1192
|
-
* @property {string} [precision] - Message when number has too many decimal places
|
|
1193
|
-
*/
|
|
1194
|
-
type NumberMessages = {
|
|
1195
|
-
required?: string;
|
|
1196
|
-
invalid?: string;
|
|
1197
|
-
integer?: string;
|
|
1198
|
-
float?: string;
|
|
1199
|
-
min?: string;
|
|
1200
|
-
max?: string;
|
|
1201
|
-
positive?: string;
|
|
1202
|
-
negative?: string;
|
|
1203
|
-
nonNegative?: string;
|
|
1204
|
-
nonPositive?: string;
|
|
1205
|
-
multipleOf?: string;
|
|
1206
|
-
finite?: string;
|
|
1207
|
-
precision?: string;
|
|
1208
|
-
};
|
|
1209
|
-
/**
|
|
1210
|
-
* Configuration options for number validation
|
|
1211
|
-
*
|
|
1212
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1213
|
-
*
|
|
1214
|
-
* @interface NumberOptions
|
|
1215
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
1216
|
-
* @property {number} [min] - Minimum allowed value
|
|
1217
|
-
* @property {number} [max] - Maximum allowed value
|
|
1218
|
-
* @property {number | null} [defaultValue] - Default value when input is empty
|
|
1219
|
-
* @property {"integer" | "float" | "both"} [type="both"] - Type constraint for the number
|
|
1220
|
-
* @property {boolean} [positive] - Whether number must be positive (> 0)
|
|
1221
|
-
* @property {boolean} [negative] - Whether number must be negative (< 0)
|
|
1222
|
-
* @property {boolean} [nonNegative] - Whether number must be non-negative (>= 0)
|
|
1223
|
-
* @property {boolean} [nonPositive] - Whether number must be non-positive (<= 0)
|
|
1224
|
-
* @property {number} [multipleOf] - Number must be a multiple of this value
|
|
1225
|
-
* @property {number} [precision] - Maximum number of decimal places allowed
|
|
1226
|
-
* @property {boolean} [finite=true] - Whether to reject Infinity and -Infinity
|
|
1227
|
-
* @property {Function} [transform] - Custom transformation function for number values
|
|
1228
|
-
* @property {boolean} [parseCommas=false] - Whether to parse comma-separated numbers (e.g., "1,234")
|
|
1229
|
-
* @property {Record<Locale, NumberMessages>} [i18n] - Custom error messages for different locales
|
|
1230
|
-
*/
|
|
1231
|
-
type NumberOptions<IsRequired extends boolean = true> = {
|
|
1232
|
-
min?: number;
|
|
1233
|
-
max?: number;
|
|
1234
|
-
defaultValue?: IsRequired extends true ? number : number | null;
|
|
1235
|
-
type?: "integer" | "float" | "both";
|
|
1236
|
-
positive?: boolean;
|
|
1237
|
-
negative?: boolean;
|
|
1238
|
-
nonNegative?: boolean;
|
|
1239
|
-
nonPositive?: boolean;
|
|
1240
|
-
multipleOf?: number;
|
|
1241
|
-
precision?: number;
|
|
1242
|
-
finite?: boolean;
|
|
1243
|
-
transform?: (value: number) => number;
|
|
1244
|
-
parseCommas?: boolean;
|
|
1245
|
-
i18n?: Partial<Record<Locale, Partial<NumberMessages>>>;
|
|
1246
|
-
};
|
|
1247
|
-
/**
|
|
1248
|
-
* Type alias for number validation schema based on required flag
|
|
1249
|
-
*
|
|
1250
|
-
* @template IsRequired - Whether the field is required
|
|
1251
|
-
* @typedef NumberSchema
|
|
1252
|
-
* @description Returns ZodNumber if required, ZodNullable<ZodNumber> if optional
|
|
1253
|
-
*/
|
|
1254
|
-
type NumberSchema<IsRequired extends boolean> = IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber>;
|
|
1255
|
-
/**
|
|
1256
|
-
* Creates a Zod schema for number validation with comprehensive constraints
|
|
1257
|
-
*
|
|
1258
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1259
|
-
* @param required
|
|
1260
|
-
* @param {NumberOptions<IsRequired>} [options] - Configuration options for number validation
|
|
1261
|
-
* @returns {NumberSchema<IsRequired>} Zod schema for number validation
|
|
1262
|
-
*
|
|
1263
|
-
* @description
|
|
1264
|
-
* Creates a comprehensive number validator with type constraints, range validation,
|
|
1265
|
-
* precision control, and advanced parsing features including comma-separated numbers.
|
|
1266
|
-
*
|
|
1267
|
-
* Features:
|
|
1268
|
-
* - Type constraints (integer, float, or both)
|
|
1269
|
-
* - Range validation (min/max)
|
|
1270
|
-
* - Sign constraints (positive, negative, non-negative, non-positive)
|
|
1271
|
-
* - Multiple-of validation
|
|
1272
|
-
* - Precision control (decimal places)
|
|
1273
|
-
* - Finite number validation
|
|
1274
|
-
* - Comma-separated number parsing
|
|
1275
|
-
* - Custom transformation functions
|
|
1276
|
-
* - Comprehensive internationalization
|
|
1277
|
-
*
|
|
1278
|
-
* @example
|
|
1279
|
-
* ```typescript
|
|
1280
|
-
* // Basic number validation (optional by default)
|
|
1281
|
-
* const basicSchema = number()
|
|
1282
|
-
* basicSchema.parse(42) // ✓ Valid
|
|
1283
|
-
* basicSchema.parse("42") // ✓ Valid (converted to number)
|
|
1284
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
1285
|
-
*
|
|
1286
|
-
* // Required number
|
|
1287
|
-
* const requiredSchema = number(true)
|
|
1288
|
-
* requiredSchema.parse(42) // ✓ Valid
|
|
1289
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
1290
|
-
*
|
|
1291
|
-
* // Integer only
|
|
1292
|
-
* const integerSchema = number(false, { type: "integer" })
|
|
1293
|
-
* integerSchema.parse(42) // ✓ Valid
|
|
1294
|
-
* integerSchema.parse(42.5) // ✗ Invalid
|
|
1295
|
-
*
|
|
1296
|
-
* // Range validation
|
|
1297
|
-
* const rangeSchema = number(true, { min: 0, max: 100 })
|
|
1298
|
-
* rangeSchema.parse(50) // ✓ Valid
|
|
1299
|
-
* rangeSchema.parse(150) // ✗ Invalid
|
|
1300
|
-
*
|
|
1301
|
-
* // Positive numbers only
|
|
1302
|
-
* const positiveSchema = number(true, { positive: true })
|
|
1303
|
-
* positiveSchema.parse(5) // ✓ Valid
|
|
1304
|
-
* positiveSchema.parse(-5) // ✗ Invalid
|
|
1305
|
-
*
|
|
1306
|
-
* // Multiple of constraint
|
|
1307
|
-
* const multipleSchema = number(true, { multipleOf: 5 })
|
|
1308
|
-
* multipleSchema.parse(10) // ✓ Valid
|
|
1309
|
-
* multipleSchema.parse(7) // ✗ Invalid
|
|
1310
|
-
*
|
|
1311
|
-
* // Precision control
|
|
1312
|
-
* const precisionSchema = number(true, { precision: 2 })
|
|
1313
|
-
* precisionSchema.parse(3.14) // ✓ Valid
|
|
1314
|
-
* precisionSchema.parse(3.14159) // ✗ Invalid
|
|
1315
|
-
*
|
|
1316
|
-
* // Comma-separated parsing
|
|
1317
|
-
* const commaSchema = number(false, { parseCommas: true })
|
|
1318
|
-
* commaSchema.parse("1,234.56") // ✓ Valid (parsed as 1234.56)
|
|
1319
|
-
*
|
|
1320
|
-
* // Optional with default
|
|
1321
|
-
* const optionalSchema = number(false, { defaultValue: 0 })
|
|
1322
|
-
* ```
|
|
1323
|
-
*
|
|
1324
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1325
|
-
* @see {@link NumberOptions} for all available configuration options
|
|
1326
|
-
*/
|
|
1327
|
-
declare function number<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<NumberOptions<IsRequired>, "required">): NumberSchema<IsRequired>;
|
|
1328
|
-
|
|
1329
|
-
/**
|
|
1330
|
-
* @fileoverview Password validator for Zod Kit
|
|
1331
|
-
*
|
|
1332
|
-
* Provides comprehensive password validation with strength analysis, character requirements,
|
|
1333
|
-
* security checks, and protection against common weak passwords.
|
|
1334
|
-
*
|
|
1335
|
-
* @author Ong Hoe Yuan
|
|
1336
|
-
* @version 0.0.5
|
|
1337
|
-
*/
|
|
1338
|
-
|
|
1339
|
-
/**
|
|
1340
|
-
* Type definition for password validation error messages
|
|
1341
|
-
*
|
|
1342
|
-
* @interface PasswordMessages
|
|
1343
|
-
* @property {string} [required] - Message when field is required but empty
|
|
1344
|
-
* @property {string} [min] - Message when password is too short
|
|
1345
|
-
* @property {string} [max] - Message when password is too long
|
|
1346
|
-
* @property {string} [uppercase] - Message when uppercase letters are required
|
|
1347
|
-
* @property {string} [lowercase] - Message when lowercase letters are required
|
|
1348
|
-
* @property {string} [digits] - Message when digits are required
|
|
1349
|
-
* @property {string} [special] - Message when special characters are required
|
|
1350
|
-
* @property {string} [noRepeating] - Message when repeating characters are forbidden
|
|
1351
|
-
* @property {string} [noSequential] - Message when sequential characters are forbidden
|
|
1352
|
-
* @property {string} [noCommonWords] - Message when common passwords are forbidden
|
|
1353
|
-
* @property {string} [minStrength] - Message when password strength is insufficient
|
|
1354
|
-
* @property {string} [excludes] - Message when password contains forbidden strings
|
|
1355
|
-
* @property {string} [includes] - Message when password doesn't contain required string
|
|
1356
|
-
* @property {string} [invalid] - Message when password doesn't match custom regex
|
|
1357
|
-
*/
|
|
1358
|
-
type PasswordMessages = {
|
|
1359
|
-
required?: string;
|
|
1360
|
-
min?: string;
|
|
1361
|
-
max?: string;
|
|
1362
|
-
uppercase?: string;
|
|
1363
|
-
lowercase?: string;
|
|
1364
|
-
digits?: string;
|
|
1365
|
-
special?: string;
|
|
1366
|
-
noRepeating?: string;
|
|
1367
|
-
noSequential?: string;
|
|
1368
|
-
noCommonWords?: string;
|
|
1369
|
-
minStrength?: string;
|
|
1370
|
-
excludes?: string;
|
|
1371
|
-
includes?: string;
|
|
1372
|
-
invalid?: string;
|
|
1373
|
-
};
|
|
1374
|
-
/**
|
|
1375
|
-
* Password strength levels used for validation
|
|
1376
|
-
*
|
|
1377
|
-
* @typedef {"weak" | "medium" | "strong" | "very-strong"} PasswordStrength
|
|
1378
|
-
* @description
|
|
1379
|
-
* - weak: Basic passwords with minimal requirements
|
|
1380
|
-
* - medium: Passwords with some character variety
|
|
1381
|
-
* - strong: Passwords with good character variety and length
|
|
1382
|
-
* - very-strong: Passwords with excellent character variety, length, and complexity
|
|
1383
|
-
*/
|
|
1384
|
-
type PasswordStrength = "weak" | "medium" | "strong" | "very-strong";
|
|
1385
|
-
/**
|
|
1386
|
-
* Configuration options for password validation
|
|
1387
|
-
*
|
|
1388
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1389
|
-
*
|
|
1390
|
-
* @interface PasswordOptions
|
|
1391
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
1392
|
-
* @property {number} [min] - Minimum length of password
|
|
1393
|
-
* @property {number} [max] - Maximum length of password
|
|
1394
|
-
* @property {boolean} [uppercase] - Whether uppercase letters are required
|
|
1395
|
-
* @property {boolean} [lowercase] - Whether lowercase letters are required
|
|
1396
|
-
* @property {boolean} [digits] - Whether digits are required
|
|
1397
|
-
* @property {boolean} [special] - Whether special characters are required
|
|
1398
|
-
* @property {boolean} [noRepeating] - Whether to forbid repeating characters (3+ in a row)
|
|
1399
|
-
* @property {boolean} [noSequential] - Whether to forbid sequential characters (abc, 123)
|
|
1400
|
-
* @property {boolean} [noCommonWords] - Whether to forbid common weak passwords
|
|
1401
|
-
* @property {PasswordStrength} [minStrength] - Minimum required password strength
|
|
1402
|
-
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
1403
|
-
* @property {string} [includes] - String that must be included in password
|
|
1404
|
-
* @property {RegExp} [regex] - Custom regex pattern for validation
|
|
1405
|
-
* @property {Function} [transform] - Custom transformation function for password
|
|
1406
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
1407
|
-
* @property {Record<Locale, PasswordMessages>} [i18n] - Custom error messages for different locales
|
|
1408
|
-
*/
|
|
1409
|
-
type PasswordOptions<IsRequired extends boolean = true> = {
|
|
1410
|
-
min?: number;
|
|
1411
|
-
max?: number;
|
|
1412
|
-
uppercase?: boolean;
|
|
1413
|
-
lowercase?: boolean;
|
|
1414
|
-
digits?: boolean;
|
|
1415
|
-
special?: boolean;
|
|
1416
|
-
noRepeating?: boolean;
|
|
1417
|
-
noSequential?: boolean;
|
|
1418
|
-
noCommonWords?: boolean;
|
|
1419
|
-
minStrength?: PasswordStrength;
|
|
1420
|
-
excludes?: string | string[];
|
|
1421
|
-
includes?: string;
|
|
1422
|
-
regex?: RegExp;
|
|
1423
|
-
transform?: (value: string) => string;
|
|
1424
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
1425
|
-
i18n?: Partial<Record<Locale, Partial<PasswordMessages>>>;
|
|
1426
|
-
};
|
|
1427
|
-
/**
|
|
1428
|
-
* Type alias for password validation schema based on required flag
|
|
1429
|
-
*
|
|
1430
|
-
* @template IsRequired - Whether the field is required
|
|
1431
|
-
* @typedef PasswordSchema
|
|
1432
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
1433
|
-
*/
|
|
1434
|
-
type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
1435
|
-
/**
|
|
1436
|
-
* Creates a Zod schema for password validation with comprehensive security checks
|
|
1437
|
-
*
|
|
1438
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1439
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
1440
|
-
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
1441
|
-
* @returns {PasswordSchema<IsRequired>} Zod schema for password validation
|
|
1442
|
-
*
|
|
1443
|
-
* @description
|
|
1444
|
-
* Creates a comprehensive password validator with strength analysis, character requirements,
|
|
1445
|
-
* security checks, and protection against common weak passwords.
|
|
1446
|
-
*
|
|
1447
|
-
* Features:
|
|
1448
|
-
* - Length validation (min/max)
|
|
1449
|
-
* - Character requirements (uppercase, lowercase, digits, special)
|
|
1450
|
-
* - Security checks (no repeating, no sequential patterns)
|
|
1451
|
-
* - Common password detection
|
|
1452
|
-
* - Strength analysis with configurable minimum levels
|
|
1453
|
-
* - Content inclusion/exclusion
|
|
1454
|
-
* - Custom regex patterns
|
|
1455
|
-
* - Custom transformation functions
|
|
1456
|
-
* - Comprehensive internationalization
|
|
1457
|
-
*
|
|
1458
|
-
* @example
|
|
1459
|
-
* ```typescript
|
|
1460
|
-
* // Basic password validation
|
|
1461
|
-
* const basicSchema = password() // optional by default
|
|
1462
|
-
* basicSchema.parse("MyPassword123!") // ✓ Valid
|
|
1463
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
1464
|
-
*
|
|
1465
|
-
* // Required validation
|
|
1466
|
-
* const requiredSchema = parse("MyPassword123!") // ✓ Valid
|
|
1467
|
-
(true)
|
|
1468
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
1469
|
-
*
|
|
1470
|
-
*
|
|
1471
|
-
* // Strong password requirements
|
|
1472
|
-
* const strongSchema = password(false, {
|
|
1473
|
-
* min: 12,
|
|
1474
|
-
* uppercase: true,
|
|
1475
|
-
* lowercase: true,
|
|
1476
|
-
* digits: true,
|
|
1477
|
-
* special: true,
|
|
1478
|
-
* minStrength: "strong"
|
|
1479
|
-
* })
|
|
1480
|
-
*
|
|
1481
|
-
* // No common passwords
|
|
1482
|
-
* const secureSchema = password(false, {
|
|
1483
|
-
* noCommonWords: true,
|
|
1484
|
-
* noRepeating: true,
|
|
1485
|
-
* noSequential: true
|
|
1486
|
-
* })
|
|
1487
|
-
* secureSchema.parse("password123") // ✗ Invalid (common password)
|
|
1488
|
-
* secureSchema.parse("aaa123") // ✗ Invalid (repeating characters)
|
|
1489
|
-
* secureSchema.parse("abc123") // ✗ Invalid (sequential characters)
|
|
1490
|
-
*
|
|
1491
|
-
* // Custom requirements
|
|
1492
|
-
* const customSchema = password(false, {
|
|
1493
|
-
* min: 8,
|
|
1494
|
-
* includes: "@", // Must contain @
|
|
1495
|
-
* excludes: ["admin", "user"], // Cannot contain these words
|
|
1496
|
-
* regex: /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)/ // Custom pattern
|
|
1497
|
-
* })
|
|
1498
|
-
*
|
|
1499
|
-
* // Minimum strength requirement
|
|
1500
|
-
* const strengthSchema = password(false, { minStrength: "very-strong" })
|
|
1501
|
-
* strengthSchema.parse("weak") // ✗ Invalid (insufficient strength)
|
|
1502
|
-
* strengthSchema.parse("MyVeryStr0ng!P@ssw0rd2024") // ✓ Valid
|
|
1503
|
-
*
|
|
1504
|
-
* // Optional with default
|
|
1505
|
-
* const optionalSchema = password(false, {
|
|
1506
|
-
* defaultValue: null
|
|
1507
|
-
* })
|
|
1508
|
-
* ```
|
|
1509
|
-
*
|
|
1510
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1511
|
-
* @see {@link PasswordOptions} for all available configuration options
|
|
1512
|
-
* @see {@link PasswordStrength} for strength level definitions
|
|
1513
|
-
* @see {@link calculatePasswordStrength} for strength calculation logic
|
|
1514
|
-
*/
|
|
1515
|
-
declare function password<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<PasswordOptions<IsRequired>, 'required'>): PasswordSchema<IsRequired>;
|
|
1516
|
-
|
|
1517
|
-
/**
|
|
1518
|
-
* @fileoverview Text validator for Zod Kit
|
|
1519
|
-
*
|
|
1520
|
-
* Provides comprehensive text validation with length constraints, content validation,
|
|
1521
|
-
* flexible trimming and casing options, and advanced transformation features.
|
|
1522
|
-
*
|
|
1523
|
-
* @author Ong Hoe Yuan
|
|
1524
|
-
* @version 0.0.5
|
|
1525
|
-
*/
|
|
1526
|
-
|
|
1527
|
-
/**
|
|
1528
|
-
* Type definition for text validation error messages
|
|
1529
|
-
*
|
|
1530
|
-
* @interface TextMessages
|
|
1531
|
-
* @property {string} [required] - Message when field is required but empty
|
|
1532
|
-
* @property {string} [notEmpty] - Message when field must not be empty (whitespace-only)
|
|
1533
|
-
* @property {string} [minLength] - Message when text is shorter than minimum length
|
|
1534
|
-
* @property {string} [maxLength] - Message when text exceeds maximum length
|
|
1535
|
-
* @property {string} [startsWith] - Message when text doesn't start with required string
|
|
1536
|
-
* @property {string} [endsWith] - Message when text doesn't end with required string
|
|
1537
|
-
* @property {string} [includes] - Message when text doesn't contain required string
|
|
1538
|
-
* @property {string} [excludes] - Message when text contains forbidden string
|
|
1539
|
-
* @property {string} [invalid] - Message when text doesn't match regex pattern
|
|
1540
|
-
*/
|
|
1541
|
-
type TextMessages = {
|
|
1542
|
-
required?: string;
|
|
1543
|
-
notEmpty?: string;
|
|
1544
|
-
minLength?: string;
|
|
1545
|
-
maxLength?: string;
|
|
1546
|
-
startsWith?: string;
|
|
1547
|
-
endsWith?: string;
|
|
1548
|
-
includes?: string;
|
|
1549
|
-
excludes?: string;
|
|
1550
|
-
invalid?: string;
|
|
1551
|
-
};
|
|
1552
|
-
/**
|
|
1553
|
-
* Configuration options for text validation
|
|
1554
|
-
*
|
|
1555
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1556
|
-
*
|
|
1557
|
-
* @interface TextOptions
|
|
1558
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
1559
|
-
* @property {number} [minLength] - Minimum length of text
|
|
1560
|
-
* @property {number} [maxLength] - Maximum length of text
|
|
1561
|
-
* @property {string} [startsWith] - String that text must start with
|
|
1562
|
-
* @property {string} [endsWith] - String that text must end with
|
|
1563
|
-
* @property {string} [includes] - String that must be included in text
|
|
1564
|
-
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
1565
|
-
* @property {RegExp} [regex] - Regular expression pattern for validation
|
|
1566
|
-
* @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
|
|
1567
|
-
* @property {"upper" | "lower" | "title" | "none"} [casing="none"] - Case transformation
|
|
1568
|
-
* @property {Function} [transform] - Custom transformation function for text
|
|
1569
|
-
* @property {boolean} [notEmpty] - Whether to reject whitespace-only strings
|
|
1570
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
1571
|
-
* @property {Record<Locale, TextMessages>} [i18n] - Custom error messages for different locales
|
|
1572
|
-
*/
|
|
1573
|
-
type TextOptions<IsRequired extends boolean = true> = {
|
|
1574
|
-
minLength?: number;
|
|
1575
|
-
maxLength?: number;
|
|
1576
|
-
startsWith?: string;
|
|
1577
|
-
endsWith?: string;
|
|
1578
|
-
includes?: string;
|
|
1579
|
-
excludes?: string | string[];
|
|
1580
|
-
regex?: RegExp;
|
|
1581
|
-
trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
|
|
1582
|
-
casing?: "upper" | "lower" | "title" | "none";
|
|
1583
|
-
transform?: (value: string) => string;
|
|
1584
|
-
notEmpty?: boolean;
|
|
1585
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
1586
|
-
i18n?: Partial<Record<Locale, Partial<TextMessages>>>;
|
|
1587
|
-
};
|
|
1588
|
-
/**
|
|
1589
|
-
* Type alias for text validation schema based on required flag
|
|
1590
|
-
*
|
|
1591
|
-
* @template IsRequired - Whether the field is required
|
|
1592
|
-
* @typedef TextSchema
|
|
1593
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
1594
|
-
*/
|
|
1595
|
-
type TextSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
1596
|
-
/**
|
|
1597
|
-
* Creates a Zod schema for text validation with comprehensive string processing
|
|
1598
|
-
*
|
|
1599
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1600
|
-
* @param {TextOptions<IsRequired>} [options] - Configuration options for text validation
|
|
1601
|
-
* @returns {TextSchema<IsRequired>} Zod schema for text validation
|
|
1602
|
-
*
|
|
1603
|
-
* @description
|
|
1604
|
-
* Creates a comprehensive text validator with length constraints, content validation,
|
|
1605
|
-
* flexible trimming and casing options, and advanced transformation features.
|
|
1606
|
-
*
|
|
1607
|
-
* Features:
|
|
1608
|
-
* - Length validation (min/max)
|
|
1609
|
-
* - Content validation (startsWith, endsWith, includes, excludes)
|
|
1610
|
-
* - Regular expression pattern matching
|
|
1611
|
-
* - Flexible trimming options (trim, trimStart, trimEnd, none)
|
|
1612
|
-
* - Case transformation (upper, lower, title, none)
|
|
1613
|
-
* - Empty string vs whitespace-only validation
|
|
1614
|
-
* - Custom transformation functions
|
|
1615
|
-
* - Comprehensive internationalization
|
|
1616
|
-
*
|
|
1617
|
-
* @example
|
|
1618
|
-
* ```typescript
|
|
1619
|
-
* // Basic text validation (optional by default)
|
|
1620
|
-
* const basicSchema = text()
|
|
1621
|
-
* basicSchema.parse("Hello World") // ✓ Valid
|
|
1622
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
1623
|
-
*
|
|
1624
|
-
* // Required text
|
|
1625
|
-
* const requiredSchema = text(true)
|
|
1626
|
-
* requiredSchema.parse("Hello") // ✓ Valid
|
|
1627
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
1628
|
-
*
|
|
1629
|
-
* // Length constraints
|
|
1630
|
-
* const lengthSchema = text(true, { minLength: 3, maxLength: 50 })
|
|
1631
|
-
* lengthSchema.parse("Hello") // ✓ Valid
|
|
1632
|
-
* lengthSchema.parse("Hi") // ✗ Invalid (too short)
|
|
1633
|
-
*
|
|
1634
|
-
* // Content validation
|
|
1635
|
-
* const contentSchema = text(true, {
|
|
1636
|
-
* startsWith: "Hello",
|
|
1637
|
-
* endsWith: "!",
|
|
1638
|
-
* includes: "World"
|
|
1639
|
-
* })
|
|
1640
|
-
* contentSchema.parse("Hello World!") // ✓ Valid
|
|
1641
|
-
*
|
|
1642
|
-
* // Case transformation
|
|
1643
|
-
* const upperSchema = text(false, { casing: "upper" })
|
|
1644
|
-
* upperSchema.parse("hello") // ✓ Valid (converted to "HELLO")
|
|
1645
|
-
*
|
|
1646
|
-
* // Trim modes
|
|
1647
|
-
* const trimStartSchema = text(false, { trimMode: "trimStart" })
|
|
1648
|
-
* trimStartSchema.parse(" hello ") // ✓ Valid (result: "hello ")
|
|
1649
|
-
*
|
|
1650
|
-
* // Regex validation
|
|
1651
|
-
* const regexSchema = text(true, { regex: /^[a-zA-Z]+$/ })
|
|
1652
|
-
* regexSchema.parse("hello") // ✓ Valid
|
|
1653
|
-
* regexSchema.parse("hello123") // ✗ Invalid
|
|
1654
|
-
*
|
|
1655
|
-
* // Not empty (rejects whitespace-only)
|
|
1656
|
-
* const notEmptySchema = text(true, { notEmpty: true })
|
|
1657
|
-
* notEmptySchema.parse("hello") // ✓ Valid
|
|
1658
|
-
* notEmptySchema.parse(" ") // ✗ Invalid
|
|
1659
|
-
*
|
|
1660
|
-
* // Optional with default
|
|
1661
|
-
* const optionalSchema = text(false, { defaultValue: "default text" })
|
|
1662
|
-
* ```
|
|
1663
|
-
*
|
|
1664
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1665
|
-
* @see {@link TextOptions} for all available configuration options
|
|
1666
|
-
*/
|
|
1667
|
-
declare function text<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TextOptions<IsRequired>, 'required'>): TextSchema<IsRequired>;
|
|
1668
|
-
|
|
1669
|
-
/**
|
|
1670
|
-
* @fileoverview Time validator for Zod Kit
|
|
1671
|
-
*
|
|
1672
|
-
* Provides comprehensive time validation with support for multiple time formats,
|
|
1673
|
-
* hour/minute constraints, and advanced time-based validation options.
|
|
1674
|
-
*
|
|
1675
|
-
* @author Ong Hoe Yuan
|
|
1676
|
-
* @version 0.0.5
|
|
1677
|
-
*/
|
|
1678
|
-
|
|
1679
|
-
/**
|
|
1680
|
-
* Type definition for time validation error messages
|
|
1681
|
-
*
|
|
1682
|
-
* @interface TimeMessages
|
|
1683
|
-
* @property {string} [required] - Message when field is required but empty
|
|
1684
|
-
* @property {string} [invalid] - Message when time format is invalid
|
|
1685
|
-
* @property {string} [format] - Message when time doesn't match expected format
|
|
1686
|
-
* @property {string} [min] - Message when time is before minimum allowed
|
|
1687
|
-
* @property {string} [max] - Message when time is after maximum allowed
|
|
1688
|
-
* @property {string} [hour] - Message when hour is outside allowed range
|
|
1689
|
-
* @property {string} [minute] - Message when minute doesn't match step requirement
|
|
1690
|
-
* @property {string} [second] - Message when second doesn't match step requirement
|
|
1691
|
-
* @property {string} [includes] - Message when time doesn't contain required string
|
|
1692
|
-
* @property {string} [excludes] - Message when time contains forbidden string
|
|
1693
|
-
* @property {string} [customRegex] - Message when custom regex validation fails
|
|
1694
|
-
* @property {string} [notInWhitelist] - Message when value is not in whitelist
|
|
1695
|
-
*/
|
|
1696
|
-
type TimeMessages = {
|
|
1697
|
-
required?: string;
|
|
1698
|
-
invalid?: string;
|
|
1699
|
-
format?: string;
|
|
1700
|
-
min?: string;
|
|
1701
|
-
max?: string;
|
|
1702
|
-
hour?: string;
|
|
1703
|
-
minute?: string;
|
|
1704
|
-
second?: string;
|
|
1705
|
-
includes?: string;
|
|
1706
|
-
excludes?: string;
|
|
1707
|
-
customRegex?: string;
|
|
1708
|
-
notInWhitelist?: string;
|
|
1709
|
-
};
|
|
1710
|
-
/**
|
|
1711
|
-
* Supported time formats for validation
|
|
1712
|
-
*
|
|
1713
|
-
* @typedef {string} TimeFormat
|
|
1714
|
-
*
|
|
1715
|
-
* Available formats:
|
|
1716
|
-
* - HH:mm: 24-hour format with leading zeros (14:30, 09:30)
|
|
1717
|
-
* - HH:mm:ss: 24-hour format with seconds (14:30:45, 09:30:15)
|
|
1718
|
-
* - hh:mm A: 12-hour format with AM/PM (02:30 PM, 09:30 AM)
|
|
1719
|
-
* - hh:mm:ss A: 12-hour format with seconds and AM/PM (02:30:45 PM)
|
|
1720
|
-
* - H:mm: 24-hour format without leading zeros (14:30, 9:30)
|
|
1721
|
-
* - h:mm A: 12-hour format without leading zeros (2:30 PM, 9:30 AM)
|
|
1722
|
-
*/
|
|
1723
|
-
type TimeFormat = "HH:mm" | "HH:mm:ss" | "hh:mm A" | "hh:mm:ss A" | "H:mm" | "h:mm A";
|
|
1724
|
-
/**
|
|
1725
|
-
* Configuration options for time validation
|
|
1726
|
-
*
|
|
1727
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1728
|
-
*
|
|
1729
|
-
* @interface TimeOptions
|
|
1730
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
1731
|
-
* @property {TimeFormat} [format="HH:mm"] - Expected time format
|
|
1732
|
-
* @property {string} [min] - Minimum allowed time (e.g., "09:00")
|
|
1733
|
-
* @property {string} [max] - Maximum allowed time (e.g., "17:00")
|
|
1734
|
-
* @property {number} [minHour] - Minimum allowed hour (0-23)
|
|
1735
|
-
* @property {number} [maxHour] - Maximum allowed hour (0-23)
|
|
1736
|
-
* @property {number[]} [allowedHours] - Specific hours that are allowed
|
|
1737
|
-
* @property {number} [minuteStep] - Required minute intervals (e.g., 15 for :00, :15, :30, :45)
|
|
1738
|
-
* @property {number} [secondStep] - Required second intervals
|
|
1739
|
-
* @property {string} [includes] - String that must be included in the time
|
|
1740
|
-
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
1741
|
-
* @property {RegExp} [regex] - Custom regex for validation (overrides format validation)
|
|
1742
|
-
* @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
|
|
1743
|
-
* @property {"upper" | "lower" | "none"} [casing="none"] - Case transformation
|
|
1744
|
-
* @property {string[]} [whitelist] - Specific time strings that are always allowed
|
|
1745
|
-
* @property {boolean} [whitelistOnly=false] - If true, only values in whitelist are allowed
|
|
1746
|
-
* @property {Function} [transform] - Custom transformation function applied before validation
|
|
1747
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
1748
|
-
* @property {Record<Locale, TimeMessages>} [i18n] - Custom error messages for different locales
|
|
1749
|
-
*/
|
|
1750
|
-
type TimeOptions<IsRequired extends boolean = true> = {
|
|
1751
|
-
format?: TimeFormat;
|
|
1752
|
-
min?: string;
|
|
1753
|
-
max?: string;
|
|
1754
|
-
minHour?: number;
|
|
1755
|
-
maxHour?: number;
|
|
1756
|
-
allowedHours?: number[];
|
|
1757
|
-
minuteStep?: number;
|
|
1758
|
-
secondStep?: number;
|
|
1759
|
-
includes?: string;
|
|
1760
|
-
excludes?: string | string[];
|
|
1761
|
-
regex?: RegExp;
|
|
1762
|
-
trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
|
|
1763
|
-
casing?: "upper" | "lower" | "none";
|
|
1764
|
-
whitelist?: string[];
|
|
1765
|
-
whitelistOnly?: boolean;
|
|
1766
|
-
transform?: (value: string) => string;
|
|
1767
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
1768
|
-
i18n?: Partial<Record<Locale, Partial<TimeMessages>>>;
|
|
1769
|
-
};
|
|
1770
|
-
/**
|
|
1771
|
-
* Type alias for time validation schema based on required flag
|
|
1772
|
-
*
|
|
1773
|
-
* @template IsRequired - Whether the field is required
|
|
1774
|
-
* @typedef TimeSchema
|
|
1775
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
1776
|
-
*/
|
|
1777
|
-
type TimeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
1778
|
-
/**
|
|
1779
|
-
* Regular expression patterns for time format validation
|
|
1780
|
-
*
|
|
1781
|
-
* @constant {Record<TimeFormat, RegExp>} TIME_PATTERNS
|
|
1782
|
-
* @description Maps each supported time format to its corresponding regex pattern
|
|
1783
|
-
*/
|
|
1784
|
-
declare const TIME_PATTERNS: Record<TimeFormat, RegExp>;
|
|
1785
|
-
/**
|
|
1786
|
-
* Parses a time string to minutes since midnight for comparison
|
|
1787
|
-
*
|
|
1788
|
-
* @param {string} timeStr - The time string to parse
|
|
1789
|
-
* @param {TimeFormat} format - The expected time format
|
|
1790
|
-
* @returns {number | null} Minutes since midnight (0-1439) or null if parsing fails
|
|
1791
|
-
*
|
|
1792
|
-
* @description
|
|
1793
|
-
* Converts time strings to minutes since midnight for easy comparison and validation.
|
|
1794
|
-
* Handles both 12-hour and 24-hour formats with proper AM/PM conversion.
|
|
1795
|
-
*
|
|
1796
|
-
* @example
|
|
1797
|
-
* ```typescript
|
|
1798
|
-
* parseTimeToMinutes("14:30", "HH:mm") // 870 (14*60 + 30)
|
|
1799
|
-
* parseTimeToMinutes("2:30 PM", "h:mm A") // 870 (14*60 + 30)
|
|
1800
|
-
* parseTimeToMinutes("12:00 AM", "hh:mm A") // 0 (midnight)
|
|
1801
|
-
* parseTimeToMinutes("12:00 PM", "hh:mm A") // 720 (noon)
|
|
1802
|
-
* ```
|
|
1803
|
-
*/
|
|
1804
|
-
declare const parseTimeToMinutes: (timeStr: string, format: TimeFormat) => number | null;
|
|
1805
|
-
/**
|
|
1806
|
-
* Validates if a time string matches the specified format pattern
|
|
1807
|
-
*
|
|
1808
|
-
* @param {string} value - The time string to validate
|
|
1809
|
-
* @param {TimeFormat} format - The expected time format
|
|
1810
|
-
* @returns {boolean} True if the time matches the format pattern
|
|
1811
|
-
*
|
|
1812
|
-
* @description
|
|
1813
|
-
* Performs regex pattern matching to validate time format.
|
|
1814
|
-
* Does not validate actual time values (e.g., 25:00 would pass pattern but fail logic).
|
|
1815
|
-
*
|
|
1816
|
-
* @example
|
|
1817
|
-
* ```typescript
|
|
1818
|
-
* validateTimeFormat("14:30", "HH:mm") // true
|
|
1819
|
-
* validateTimeFormat("2:30 PM", "h:mm A") // true
|
|
1820
|
-
* validateTimeFormat("25:00", "HH:mm") // true (pattern matches)
|
|
1821
|
-
* validateTimeFormat("14:30", "h:mm A") // false (wrong format)
|
|
1822
|
-
* ```
|
|
1823
|
-
*/
|
|
1824
|
-
declare const validateTimeFormat: (value: string, format: TimeFormat) => boolean;
|
|
1825
|
-
/**
|
|
1826
|
-
* Normalizes time to 24-hour format for internal processing
|
|
1827
|
-
*
|
|
1828
|
-
* @param {string} timeStr - The time string to normalize
|
|
1829
|
-
* @param {TimeFormat} format - The current time format
|
|
1830
|
-
* @returns {string | null} Normalized time string or null if parsing fails
|
|
1831
|
-
*
|
|
1832
|
-
* @description
|
|
1833
|
-
* Converts time strings to a standardized 24-hour format for consistent processing.
|
|
1834
|
-
* Handles AM/PM conversion and leading zero normalization.
|
|
1835
|
-
*
|
|
1836
|
-
* @example
|
|
1837
|
-
* ```typescript
|
|
1838
|
-
* normalizeTime("2:30 PM", "h:mm A") // "14:30"
|
|
1839
|
-
* normalizeTime("12:00 AM", "hh:mm A") // "00:00"
|
|
1840
|
-
* normalizeTime("9:30", "H:mm") // "09:30"
|
|
1841
|
-
* normalizeTime("14:30:45", "HH:mm:ss") // "14:30:45"
|
|
1842
|
-
* ```
|
|
1843
|
-
*/
|
|
1844
|
-
declare const normalizeTime: (timeStr: string, format: TimeFormat) => string | null;
|
|
1845
|
-
/**
|
|
1846
|
-
* Creates a Zod schema for time validation with comprehensive options
|
|
1847
|
-
*
|
|
1848
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1849
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
1850
|
-
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
1851
|
-
* @returns {TimeSchema<IsRequired>} Zod schema for time validation
|
|
1852
|
-
*
|
|
1853
|
-
* @description
|
|
1854
|
-
* Creates a comprehensive time validator that supports multiple time formats,
|
|
1855
|
-
* hour/minute constraints, step validation, and extensive customization options.
|
|
1856
|
-
*
|
|
1857
|
-
* Features:
|
|
1858
|
-
* - Multiple time formats (24-hour, 12-hour, with/without seconds)
|
|
1859
|
-
* - Time range validation (min/max)
|
|
1860
|
-
* - Hour and minute constraints
|
|
1861
|
-
* - Step validation (e.g., 15-minute intervals)
|
|
1862
|
-
* - Whitelist/blacklist support
|
|
1863
|
-
* - Custom regex patterns
|
|
1864
|
-
* - String transformation and case handling
|
|
1865
|
-
* - Comprehensive internationalization
|
|
1866
|
-
*
|
|
1867
|
-
* @example
|
|
1868
|
-
* ```typescript
|
|
1869
|
-
* // Basic time validation (24-hour format)
|
|
1870
|
-
* const basicSchema = time()
|
|
1871
|
-
* basicSchema.parse("14:30") // ✓ Valid
|
|
1872
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
1873
|
-
*
|
|
1874
|
-
* // Required validation
|
|
1875
|
-
* const requiredSchema = parse("14:30") // ✓ Valid
|
|
1876
|
-
(true)
|
|
1877
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
1878
|
-
*
|
|
1879
|
-
* basicSchema.parse("2:30 PM") // ✗ Invalid (wrong format)
|
|
1880
|
-
*
|
|
1881
|
-
* // 12-hour format with AM/PM
|
|
1882
|
-
* const ampmSchema = time(false, { format: "hh:mm A" })
|
|
1883
|
-
* ampmSchema.parse("02:30 PM") // ✓ Valid
|
|
1884
|
-
* ampmSchema.parse("14:30") // ✗ Invalid (wrong format)
|
|
1885
|
-
*
|
|
1886
|
-
* // Business hours validation
|
|
1887
|
-
* const businessHours = time({
|
|
1888
|
-
* format: "HH:mm",
|
|
1889
|
-
* minHour: 9,
|
|
1890
|
-
* maxHour: 17,
|
|
1891
|
-
* minuteStep: 15 // Only :00, :15, :30, :45
|
|
1892
|
-
* })
|
|
1893
|
-
* businessHours.parse("09:15") // ✓ Valid
|
|
1894
|
-
* businessHours.parse("18:00") // ✗ Invalid (after maxHour)
|
|
1895
|
-
* businessHours.parse("09:05") // ✗ Invalid (not 15-minute step)
|
|
1896
|
-
*
|
|
1897
|
-
* // Time range validation
|
|
1898
|
-
* const timeRangeSchema = time(false, {
|
|
1899
|
-
* min: "09:00",
|
|
1900
|
-
* max: "17:00"
|
|
1901
|
-
* })
|
|
1902
|
-
* timeRangeSchema.parse("12:30") // ✓ Valid
|
|
1903
|
-
* timeRangeSchema.parse("08:00") // ✗ Invalid (before min)
|
|
1904
|
-
*
|
|
1905
|
-
* // Allowed hours only
|
|
1906
|
-
* const specificHours = time({
|
|
1907
|
-
* allowedHours: [9, 12, 15, 18]
|
|
1908
|
-
* })
|
|
1909
|
-
* specificHours.parse("12:30") // ✓ Valid
|
|
1910
|
-
* specificHours.parse("11:30") // ✗ Invalid (hour not allowed)
|
|
1911
|
-
*
|
|
1912
|
-
* // Whitelist specific times
|
|
1913
|
-
* const whitelistSchema = time(false, {
|
|
1914
|
-
* whitelist: ["09:00", "12:00", "17:00"],
|
|
1915
|
-
* whitelistOnly: true
|
|
1916
|
-
* })
|
|
1917
|
-
* whitelistSchema.parse("12:00") // ✓ Valid (in whitelist)
|
|
1918
|
-
* whitelistSchema.parse("13:00") // ✗ Invalid (not in whitelist)
|
|
1919
|
-
*
|
|
1920
|
-
* // Optional with default
|
|
1921
|
-
* const optionalSchema = time(false, {
|
|
1922
|
-
* defaultValue: "09:00"
|
|
1923
|
-
* })
|
|
1924
|
-
* optionalSchema.parse("") // ✓ Valid (returns "09:00")
|
|
1925
|
-
* ```
|
|
1926
|
-
*
|
|
1927
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
1928
|
-
* @see {@link TimeOptions} for all available configuration options
|
|
1929
|
-
* @see {@link TimeFormat} for supported time formats
|
|
1930
|
-
*/
|
|
1931
|
-
declare function time<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TimeOptions<IsRequired>, 'required'>): TimeSchema<IsRequired>;
|
|
1932
|
-
|
|
1933
|
-
/**
|
|
1934
|
-
* @fileoverview URL validator for Zod Kit
|
|
1935
|
-
*
|
|
1936
|
-
* Provides comprehensive URL validation with protocol filtering, domain control,
|
|
1937
|
-
* port validation, path constraints, and localhost handling.
|
|
1938
|
-
*
|
|
1939
|
-
* @author Ong Hoe Yuan
|
|
1940
|
-
* @version 0.0.5
|
|
1941
|
-
*/
|
|
1942
|
-
|
|
1943
|
-
/**
|
|
1944
|
-
* Type definition for URL validation error messages
|
|
1945
|
-
*
|
|
1946
|
-
* @interface UrlMessages
|
|
1947
|
-
* @property {string} [required] - Message when field is required but empty
|
|
1948
|
-
* @property {string} [invalid] - Message when URL format is invalid
|
|
1949
|
-
* @property {string} [min] - Message when URL is too short
|
|
1950
|
-
* @property {string} [max] - Message when URL is too long
|
|
1951
|
-
* @property {string} [includes] - Message when URL doesn't contain required string
|
|
1952
|
-
* @property {string} [excludes] - Message when URL contains forbidden string
|
|
1953
|
-
* @property {string} [protocol] - Message when protocol is not allowed
|
|
1954
|
-
* @property {string} [domain] - Message when domain is not allowed
|
|
1955
|
-
* @property {string} [domainBlacklist] - Message when domain is blacklisted
|
|
1956
|
-
* @property {string} [port] - Message when port is not allowed
|
|
1957
|
-
* @property {string} [pathStartsWith] - Message when path doesn't start with required string
|
|
1958
|
-
* @property {string} [pathEndsWith] - Message when path doesn't end with required string
|
|
1959
|
-
* @property {string} [hasQuery] - Message when query parameters are required
|
|
1960
|
-
* @property {string} [noQuery] - Message when query parameters are forbidden
|
|
1961
|
-
* @property {string} [hasFragment] - Message when fragment is required
|
|
1962
|
-
* @property {string} [noFragment] - Message when fragment is forbidden
|
|
1963
|
-
* @property {string} [localhost] - Message when localhost is forbidden
|
|
1964
|
-
* @property {string} [noLocalhost] - Message when localhost is required
|
|
1965
|
-
*/
|
|
1966
|
-
type UrlMessages = {
|
|
1967
|
-
required?: string;
|
|
1968
|
-
invalid?: string;
|
|
1969
|
-
min?: string;
|
|
1970
|
-
max?: string;
|
|
1971
|
-
includes?: string;
|
|
1972
|
-
excludes?: string;
|
|
1973
|
-
protocol?: string;
|
|
1974
|
-
domain?: string;
|
|
1975
|
-
domainBlacklist?: string;
|
|
1976
|
-
port?: string;
|
|
1977
|
-
pathStartsWith?: string;
|
|
1978
|
-
pathEndsWith?: string;
|
|
1979
|
-
hasQuery?: string;
|
|
1980
|
-
noQuery?: string;
|
|
1981
|
-
hasFragment?: string;
|
|
1982
|
-
noFragment?: string;
|
|
1983
|
-
localhost?: string;
|
|
1984
|
-
noLocalhost?: string;
|
|
1985
|
-
};
|
|
1986
|
-
/**
|
|
1987
|
-
* Configuration options for URL validation
|
|
1988
|
-
*
|
|
1989
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
1990
|
-
*
|
|
1991
|
-
* @interface UrlOptions
|
|
1992
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
1993
|
-
* @property {number} [min] - Minimum length of URL
|
|
1994
|
-
* @property {number} [max] - Maximum length of URL
|
|
1995
|
-
* @property {string} [includes] - String that must be included in URL
|
|
1996
|
-
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
1997
|
-
* @property {string[]} [protocols] - Allowed protocols (e.g., ["https", "http"])
|
|
1998
|
-
* @property {string[]} [allowedDomains] - Domains that are allowed
|
|
1999
|
-
* @property {string[]} [blockedDomains] - Domains that are blocked
|
|
2000
|
-
* @property {number[]} [allowedPorts] - Ports that are allowed
|
|
2001
|
-
* @property {number[]} [blockedPorts] - Ports that are blocked
|
|
2002
|
-
* @property {string} [pathStartsWith] - Path must start with this string
|
|
2003
|
-
* @property {string} [pathEndsWith] - Path must end with this string
|
|
2004
|
-
* @property {boolean} [mustHaveQuery] - Whether URL must have query parameters
|
|
2005
|
-
* @property {boolean} [mustNotHaveQuery] - Whether URL must not have query parameters
|
|
2006
|
-
* @property {boolean} [mustHaveFragment] - Whether URL must have fragment
|
|
2007
|
-
* @property {boolean} [mustNotHaveFragment] - Whether URL must not have fragment
|
|
2008
|
-
* @property {boolean} [allowLocalhost=true] - Whether to allow localhost URLs
|
|
2009
|
-
* @property {boolean} [blockLocalhost] - Whether to explicitly block localhost URLs
|
|
2010
|
-
* @property {Function} [transform] - Custom transformation function for URL strings
|
|
2011
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2012
|
-
* @property {Record<Locale, UrlMessages>} [i18n] - Custom error messages for different locales
|
|
2013
|
-
*/
|
|
2014
|
-
type UrlOptions<IsRequired extends boolean = true> = {
|
|
2015
|
-
min?: number;
|
|
2016
|
-
max?: number;
|
|
2017
|
-
includes?: string;
|
|
2018
|
-
excludes?: string | string[];
|
|
2019
|
-
protocols?: string[];
|
|
2020
|
-
allowedDomains?: string[];
|
|
2021
|
-
blockedDomains?: string[];
|
|
2022
|
-
allowedPorts?: number[];
|
|
2023
|
-
blockedPorts?: number[];
|
|
2024
|
-
pathStartsWith?: string;
|
|
2025
|
-
pathEndsWith?: string;
|
|
2026
|
-
mustHaveQuery?: boolean;
|
|
2027
|
-
mustNotHaveQuery?: boolean;
|
|
2028
|
-
mustHaveFragment?: boolean;
|
|
2029
|
-
mustNotHaveFragment?: boolean;
|
|
2030
|
-
allowLocalhost?: boolean;
|
|
2031
|
-
blockLocalhost?: boolean;
|
|
2032
|
-
transform?: (value: string) => string;
|
|
2033
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2034
|
-
i18n?: Partial<Record<Locale, Partial<UrlMessages>>>;
|
|
2035
|
-
};
|
|
2036
|
-
/**
|
|
2037
|
-
* Type alias for URL validation schema based on required flag
|
|
2038
|
-
*
|
|
2039
|
-
* @template IsRequired - Whether the field is required
|
|
2040
|
-
* @typedef UrlSchema
|
|
2041
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2042
|
-
*/
|
|
2043
|
-
type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2044
|
-
/**
|
|
2045
|
-
* Creates a Zod schema for URL validation with comprehensive constraints
|
|
2046
|
-
*
|
|
2047
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2048
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2049
|
-
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2050
|
-
* @returns {UrlSchema<IsRequired>} Zod schema for URL validation
|
|
2051
|
-
*
|
|
2052
|
-
* @description
|
|
2053
|
-
* Creates a comprehensive URL validator with protocol filtering, domain control,
|
|
2054
|
-
* port validation, path constraints, and localhost handling.
|
|
2055
|
-
*
|
|
2056
|
-
* Features:
|
|
2057
|
-
* - RFC-compliant URL format validation
|
|
2058
|
-
* - Protocol whitelist/blacklist (http, https, ftp, etc.)
|
|
2059
|
-
* - Domain whitelist/blacklist with subdomain support
|
|
2060
|
-
* - Port validation and filtering
|
|
2061
|
-
* - Path prefix/suffix validation
|
|
2062
|
-
* - Query parameter requirements
|
|
2063
|
-
* - Fragment requirements
|
|
2064
|
-
* - Localhost detection and control
|
|
2065
|
-
* - Length validation
|
|
2066
|
-
* - Content inclusion/exclusion
|
|
2067
|
-
* - Custom transformation functions
|
|
2068
|
-
* - Comprehensive internationalization
|
|
2069
|
-
*
|
|
2070
|
-
* @example
|
|
2071
|
-
* ```typescript
|
|
2072
|
-
* // Basic URL validation
|
|
2073
|
-
* const basicSchema = url() // optional by default
|
|
2074
|
-
* basicSchema.parse("https://example.com") // ✓ Valid
|
|
2075
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
2076
|
-
*
|
|
2077
|
-
* // Required validation
|
|
2078
|
-
* const requiredSchema = parse("https://example.com") // ✓ Valid
|
|
2079
|
-
(true)
|
|
2080
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
2081
|
-
*
|
|
2082
|
-
*
|
|
2083
|
-
* // HTTPS only
|
|
2084
|
-
* const httpsSchema = url(false, { protocols: ["https"] })
|
|
2085
|
-
* httpsSchema.parse("https://example.com") // ✓ Valid
|
|
2086
|
-
* httpsSchema.parse("http://example.com") // ✗ Invalid
|
|
2087
|
-
*
|
|
2088
|
-
* // Domain restriction
|
|
2089
|
-
* const domainSchema = url(false, {
|
|
2090
|
-
* allowedDomains: ["company.com", "trusted.org"]
|
|
2091
|
-
* })
|
|
2092
|
-
* domainSchema.parse("https://app.company.com") // ✓ Valid (subdomain)
|
|
2093
|
-
* domainSchema.parse("https://example.com") // ✗ Invalid
|
|
2094
|
-
*
|
|
2095
|
-
* // Block localhost
|
|
2096
|
-
* const noLocalhostSchema = url(false, { blockLocalhost: true })
|
|
2097
|
-
* noLocalhostSchema.parse("https://example.com") // ✓ Valid
|
|
2098
|
-
* noLocalhostSchema.parse("http://localhost:3000") // ✗ Invalid
|
|
2099
|
-
*
|
|
2100
|
-
* // API endpoints with path requirements
|
|
2101
|
-
* const apiSchema = url(false, {
|
|
2102
|
-
* pathStartsWith: "/api/",
|
|
2103
|
-
* mustHaveQuery: true
|
|
2104
|
-
* })
|
|
2105
|
-
* apiSchema.parse("https://api.com/api/users?page=1") // ✓ Valid
|
|
2106
|
-
*
|
|
2107
|
-
* // Port restrictions
|
|
2108
|
-
* const portSchema = url(false, {
|
|
2109
|
-
* allowedPorts: [80, 443, 8080]
|
|
2110
|
-
* })
|
|
2111
|
-
* portSchema.parse("https://example.com:443") // ✓ Valid
|
|
2112
|
-
* portSchema.parse("https://example.com:3000") // ✗ Invalid
|
|
2113
|
-
*
|
|
2114
|
-
* // Optional with default
|
|
2115
|
-
* const optionalSchema = url(false, {
|
|
2116
|
-
* defaultValue: null
|
|
2117
|
-
* })
|
|
2118
|
-
* ```
|
|
2119
|
-
*
|
|
2120
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2121
|
-
* @see {@link UrlOptions} for all available configuration options
|
|
2122
|
-
*/
|
|
2123
|
-
declare function url<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<UrlOptions<IsRequired>, 'required'>): UrlSchema<IsRequired>;
|
|
2124
|
-
|
|
2125
|
-
/**
|
|
2126
|
-
* @fileoverview Taiwan Business ID (統一編號) validator for Zod Kit
|
|
2127
|
-
*
|
|
2128
|
-
* Provides validation for Taiwan Business Identification Numbers (統一編號) with
|
|
2129
|
-
* support for both new (2023+) and legacy validation rules.
|
|
2130
|
-
*
|
|
2131
|
-
* @author Ong Hoe Yuan
|
|
2132
|
-
* @version 0.0.5
|
|
2133
|
-
*/
|
|
2134
|
-
|
|
2135
|
-
/**
|
|
2136
|
-
* Type definition for business ID validation error messages
|
|
2137
|
-
*
|
|
2138
|
-
* @interface TwBusinessIdMessages
|
|
2139
|
-
* @property {string} [required] - Message when field is required but empty
|
|
2140
|
-
* @property {string} [invalid] - Message when business ID format or checksum is invalid
|
|
2141
|
-
*/
|
|
2142
|
-
type TwBusinessIdMessages = {
|
|
2143
|
-
required?: string;
|
|
2144
|
-
invalid?: string;
|
|
2145
|
-
};
|
|
2146
|
-
/**
|
|
2147
|
-
* Configuration options for Taiwan business ID validation
|
|
2148
|
-
*
|
|
2149
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2150
|
-
*
|
|
2151
|
-
* @interface TwBusinessIdOptions
|
|
2152
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2153
|
-
* @property {Function} [transform] - Custom transformation function for business ID
|
|
2154
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2155
|
-
* @property {Record<Locale, TwBusinessIdMessages>} [i18n] - Custom error messages for different locales
|
|
2156
|
-
*/
|
|
2157
|
-
type TwBusinessIdOptions<IsRequired extends boolean = true> = {
|
|
2158
|
-
transform?: (value: string) => string;
|
|
2159
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2160
|
-
i18n?: Partial<Record<Locale, Partial<TwBusinessIdMessages>>>;
|
|
2161
|
-
};
|
|
2162
|
-
/**
|
|
2163
|
-
* Type alias for business ID validation schema based on required flag
|
|
2164
|
-
*
|
|
2165
|
-
* @template IsRequired - Whether the field is required
|
|
2166
|
-
* @typedef TwBusinessIdSchema
|
|
2167
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2168
|
-
*/
|
|
2169
|
-
type TwBusinessIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2170
|
-
/**
|
|
2171
|
-
* Validates Taiwan Business Identification Number (統一編號)
|
|
2172
|
-
*
|
|
2173
|
-
* @param {string} value - The business ID to validate
|
|
2174
|
-
* @returns {boolean} True if the business ID is valid
|
|
2175
|
-
*
|
|
2176
|
-
* @description
|
|
2177
|
-
* Validates Taiwan Business ID using both new (2023+) and legacy validation rules.
|
|
2178
|
-
* The validation includes format checking (8 digits) and checksum verification.
|
|
2179
|
-
*
|
|
2180
|
-
* Validation rules:
|
|
2181
|
-
* 1. Must be exactly 8 digits
|
|
2182
|
-
* 2. Weighted sum calculation using coefficients [1,2,1,2,1,2,4] for first 7 digits
|
|
2183
|
-
* 3. New rules (2023+): Sum + 8th digit must be divisible by 5
|
|
2184
|
-
* 4. Legacy rules: Sum + 8th digit must be divisible by 10
|
|
2185
|
-
* 5. Special case: If 7th digit is 7, try alternative calculation with +1
|
|
2186
|
-
*
|
|
2187
|
-
* @example
|
|
2188
|
-
* ```typescript
|
|
2189
|
-
* validateTaiwanBusinessId("12345675") // true (if valid checksum)
|
|
2190
|
-
* validateTaiwanBusinessId("1234567") // false (not 8 digits)
|
|
2191
|
-
* validateTaiwanBusinessId("abcd1234") // false (not all digits)
|
|
2192
|
-
* ```
|
|
2193
|
-
*/
|
|
2194
|
-
declare const validateTaiwanBusinessId: (value: string) => boolean;
|
|
2195
|
-
/**
|
|
2196
|
-
* Creates a Zod schema for Taiwan Business ID validation
|
|
2197
|
-
*
|
|
2198
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2199
|
-
* @param {BusinessIdOptions<IsRequired>} [options] - Configuration options for business ID validation
|
|
2200
|
-
* @returns {BusinessIdSchema<IsRequired>} Zod schema for business ID validation
|
|
2201
|
-
*
|
|
2202
|
-
* @description
|
|
2203
|
-
* Creates a comprehensive Taiwan Business ID validator that validates the format
|
|
2204
|
-
* and checksum according to Taiwan government specifications.
|
|
2205
|
-
*
|
|
2206
|
-
* Features:
|
|
2207
|
-
* - 8-digit format validation
|
|
2208
|
-
* - Checksum verification (supports both new 2023+ and legacy rules)
|
|
2209
|
-
* - Automatic trimming and preprocessing
|
|
2210
|
-
* - Custom transformation functions
|
|
2211
|
-
* - Comprehensive internationalization
|
|
2212
|
-
* - Optional field support
|
|
2213
|
-
*
|
|
2214
|
-
* @example
|
|
2215
|
-
* ```typescript
|
|
2216
|
-
* // Basic business ID validation
|
|
2217
|
-
* const basicSchema = businessId() // optional by default
|
|
2218
|
-
* basicSchema.parse("12345675") // ✓ Valid (if checksum correct)
|
|
2219
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
2220
|
-
*
|
|
2221
|
-
* // Required validation
|
|
2222
|
-
* const requiredSchema = parse("12345675") // ✓ Valid (if checksum correct)
|
|
2223
|
-
(true)
|
|
2224
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
2225
|
-
*
|
|
2226
|
-
* basicSchema.parse("1234567") // ✗ Invalid (not 8 digits)
|
|
2227
|
-
*
|
|
2228
|
-
* // Optional business ID
|
|
2229
|
-
* const optionalSchema = businessId(false)
|
|
2230
|
-
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2231
|
-
* optionalSchema.parse("12345675") // ✓ Valid (if checksum correct)
|
|
2232
|
-
*
|
|
2233
|
-
* // With custom transformation
|
|
2234
|
-
* const transformSchema = businessId(false, {
|
|
2235
|
-
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
2236
|
-
* })
|
|
2237
|
-
* transformSchema.parse("1234-5675") // ✓ Valid (if checksum correct after cleaning)
|
|
2238
|
-
*
|
|
2239
|
-
* // With custom error messages
|
|
2240
|
-
* const customSchema = businessId(false, {
|
|
2241
|
-
* i18n: {
|
|
2242
|
-
* en: { invalid: "Please enter a valid Taiwan Business ID" },
|
|
2243
|
-
* 'zh-TW': { invalid: "請輸入有效的統一編號" }
|
|
2244
|
-
* }
|
|
2245
|
-
* })
|
|
2246
|
-
* ```
|
|
2247
|
-
*
|
|
2248
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2249
|
-
* @see {@link TwBusinessIdOptions} for all available configuration options
|
|
2250
|
-
* @see {@link validateTaiwanBusinessId} for validation logic details
|
|
2251
|
-
*/
|
|
2252
|
-
declare function twBusinessId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwBusinessIdOptions<IsRequired>, "required">): TwBusinessIdSchema<IsRequired>;
|
|
2253
|
-
|
|
2254
|
-
/**
|
|
2255
|
-
* @fileoverview Taiwan National ID (身分證/居留證) validator for Zod Kit
|
|
2256
|
-
*
|
|
2257
|
-
* Provides validation for Taiwan National ID cards (身分證) and
|
|
2258
|
-
* Resident Certificates (居留證) with support for both old and new formats.
|
|
2259
|
-
*
|
|
2260
|
-
* @author Ong Hoe Yuan
|
|
2261
|
-
* @version 0.0.5
|
|
2262
|
-
*/
|
|
2263
|
-
|
|
2264
|
-
/**
|
|
2265
|
-
* Type definition for national ID validation error messages
|
|
2266
|
-
*
|
|
2267
|
-
* @interface TwNationalIdMessages
|
|
2268
|
-
* @property {string} [required] - Message when field is required but empty
|
|
2269
|
-
* @property {string} [invalid] - Message when national ID format or checksum is invalid
|
|
2270
|
-
*/
|
|
2271
|
-
type TwNationalIdMessages = {
|
|
2272
|
-
required?: string;
|
|
2273
|
-
invalid?: string;
|
|
2274
|
-
};
|
|
2275
|
-
/**
|
|
2276
|
-
* Types of Taiwan national identification documents
|
|
2277
|
-
*
|
|
2278
|
-
* @typedef {"citizen" | "resident" | "both"} NationalIdType
|
|
2279
|
-
*
|
|
2280
|
-
* Available types:
|
|
2281
|
-
* - citizen: National ID card (身分證字號) for Taiwan citizens
|
|
2282
|
-
* - resident: Resident certificate (居留證號) for foreign residents
|
|
2283
|
-
* - both: Accept both citizen and resident IDs
|
|
2284
|
-
*/
|
|
2285
|
-
type NationalIdType = "citizen" | "resident" | "both";
|
|
2286
|
-
/**
|
|
2287
|
-
* Configuration options for Taiwan national ID validation
|
|
2288
|
-
*
|
|
2289
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2290
|
-
*
|
|
2291
|
-
* @interface TwNationalIdOptions
|
|
2292
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2293
|
-
* @property {NationalIdType} [type="both"] - Type of ID to accept
|
|
2294
|
-
* @property {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
2295
|
-
* @property {Function} [transform] - Custom transformation function for ID
|
|
2296
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2297
|
-
* @property {Record<Locale, TwNationalIdMessages>} [i18n] - Custom error messages for different locales
|
|
2298
|
-
*/
|
|
2299
|
-
type TwNationalIdOptions<IsRequired extends boolean = true> = {
|
|
2300
|
-
type?: NationalIdType;
|
|
2301
|
-
allowOldResident?: boolean;
|
|
2302
|
-
transform?: (value: string) => string;
|
|
2303
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2304
|
-
i18n?: Partial<Record<Locale, Partial<TwNationalIdMessages>>>;
|
|
2305
|
-
};
|
|
2306
|
-
/**
|
|
2307
|
-
* Type alias for national ID validation schema based on required flag
|
|
2308
|
-
*
|
|
2309
|
-
* @template IsRequired - Whether the field is required
|
|
2310
|
-
* @typedef TwNationalIdSchema
|
|
2311
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2312
|
-
*/
|
|
2313
|
-
type TwNationalIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2314
|
-
/**
|
|
2315
|
-
* Validates Taiwan citizen national ID card (身分證字號)
|
|
2316
|
-
*
|
|
2317
|
-
* @param {string} value - The citizen ID to validate
|
|
2318
|
-
* @returns {boolean} True if the citizen ID is valid
|
|
2319
|
-
*
|
|
2320
|
-
* @description
|
|
2321
|
-
* Validates Taiwan citizen ID format: 1 letter + 1 gender digit (1-2) + 8 digits
|
|
2322
|
-
* Uses checksum algorithm with city code conversion and weighted sum.
|
|
2323
|
-
*
|
|
2324
|
-
* Format: [A-Z][1-2]XXXXXXXX
|
|
2325
|
-
* - First letter: City/county code
|
|
2326
|
-
* - Second digit: Gender (1=male, 2=female)
|
|
2327
|
-
* - Last 8 digits: Serial number + checksum
|
|
2328
|
-
*
|
|
2329
|
-
* @example
|
|
2330
|
-
* ```typescript
|
|
2331
|
-
* validateCitizenId("A123456789") // true/false based on checksum
|
|
2332
|
-
* validateCitizenId("A323456789") // false (invalid gender digit)
|
|
2333
|
-
* ```
|
|
2334
|
-
*/
|
|
2335
|
-
declare const validateCitizenId: (value: string) => boolean;
|
|
2336
|
-
/**
|
|
2337
|
-
* Validates old-style Taiwan resident certificate (舊式居留證號)
|
|
2338
|
-
*
|
|
2339
|
-
* @param {string} value - The old-style resident ID to validate
|
|
2340
|
-
* @returns {boolean} True if the old-style resident ID is valid
|
|
2341
|
-
*
|
|
2342
|
-
* @description
|
|
2343
|
-
* Validates old-style resident ID format: 1 letter + 1 gender letter + 8 digits
|
|
2344
|
-
* Uses checksum algorithm with city code and gender code conversion.
|
|
2345
|
-
*
|
|
2346
|
-
* Format: [A-Z][ABCD]XXXXXXXX
|
|
2347
|
-
* - First letter: City/county code
|
|
2348
|
-
* - Second letter: Gender code (A/C=male, B/D=female)
|
|
2349
|
-
* - Last 8 digits: Serial number + checksum
|
|
2350
|
-
*
|
|
2351
|
-
* @example
|
|
2352
|
-
* ```typescript
|
|
2353
|
-
* validateOldResidentId("AA12345678") // true/false based on checksum
|
|
2354
|
-
* validateOldResidentId("AE12345678") // false (invalid gender letter)
|
|
2355
|
-
* ```
|
|
2356
|
-
*/
|
|
2357
|
-
declare const validateOldResidentId: (value: string) => boolean;
|
|
2358
|
-
/**
|
|
2359
|
-
* Validates new-style Taiwan resident certificate (新式居留證號)
|
|
2360
|
-
*
|
|
2361
|
-
* @param {string} value - The new-style resident ID to validate
|
|
2362
|
-
* @returns {boolean} True if the new-style resident ID is valid
|
|
2363
|
-
*
|
|
2364
|
-
* @description
|
|
2365
|
-
* Validates new-style resident ID format: 1 letter + 1 type digit + 8 digits
|
|
2366
|
-
* Uses the same checksum algorithm as citizen IDs.
|
|
2367
|
-
*
|
|
2368
|
-
* Format: [A-Z][89]XXXXXXXX
|
|
2369
|
-
* - First letter: City/county code
|
|
2370
|
-
* - Second digit: Type indicator (8 or 9)
|
|
2371
|
-
* - Last 8 digits: Serial number + checksum
|
|
2372
|
-
*
|
|
2373
|
-
* @example
|
|
2374
|
-
* ```typescript
|
|
2375
|
-
* validateNewResidentId("A812345678") // true/false based on checksum
|
|
2376
|
-
* validateNewResidentId("A712345678") // false (invalid type digit)
|
|
2377
|
-
* ```
|
|
2378
|
-
*/
|
|
2379
|
-
declare const validateNewResidentId: (value: string) => boolean;
|
|
2380
|
-
/**
|
|
2381
|
-
* Main validation function for Taiwan national IDs
|
|
2382
|
-
*
|
|
2383
|
-
* @param {string} value - The national ID to validate
|
|
2384
|
-
* @param {NationalIdType} [type="both"] - Type of ID to accept
|
|
2385
|
-
* @param {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
2386
|
-
* @returns {boolean} True if the national ID is valid
|
|
2387
|
-
*
|
|
2388
|
-
* @description
|
|
2389
|
-
* Validates Taiwan national IDs based on the specified type and options.
|
|
2390
|
-
* Supports citizen IDs, resident certificates (both old and new styles).
|
|
2391
|
-
*
|
|
2392
|
-
* @example
|
|
2393
|
-
* ```typescript
|
|
2394
|
-
* validateTaiwanNationalId("A123456789", "citizen") // Citizen ID only
|
|
2395
|
-
* validateTaiwanNationalId("A812345678", "resident") // Resident ID only
|
|
2396
|
-
* validateTaiwanNationalId("A123456789", "both") // Accept any valid format
|
|
2397
|
-
* validateTaiwanNationalId("AA12345678", "both", false) // Reject old resident format
|
|
2398
|
-
* ```
|
|
2399
|
-
*/
|
|
2400
|
-
declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, allowOldResident?: boolean) => boolean;
|
|
2401
|
-
/**
|
|
2402
|
-
* Creates a Zod schema for Taiwan National ID validation
|
|
2403
|
-
*
|
|
2404
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2405
|
-
* @param {TwNationalIdOptions<IsRequired>} [options] - Configuration options for national ID validation
|
|
2406
|
-
* @returns {TwNationalIdSchema<IsRequired>} Zod schema for national ID validation
|
|
2407
|
-
*
|
|
2408
|
-
* @description
|
|
2409
|
-
* Creates a comprehensive Taiwan National ID validator that supports both
|
|
2410
|
-
* citizen IDs and resident certificates with configurable validation rules.
|
|
2411
|
-
*
|
|
2412
|
-
* Features:
|
|
2413
|
-
* - Citizen ID validation (身分證字號)
|
|
2414
|
-
* - Resident certificate validation (居留證號, old and new formats)
|
|
2415
|
-
* - Configurable ID type acceptance
|
|
2416
|
-
* - Automatic case conversion to uppercase
|
|
2417
|
-
* - Checksum verification
|
|
2418
|
-
* - Custom transformation functions
|
|
2419
|
-
* - Comprehensive internationalization
|
|
2420
|
-
* - Optional field support
|
|
2421
|
-
*
|
|
2422
|
-
* @example
|
|
2423
|
-
* ```typescript
|
|
2424
|
-
* // Accept any valid Taiwan ID
|
|
2425
|
-
* const anyIdSchema = twNationalId()
|
|
2426
|
-
* anyIdSchema.parse("A123456789") // ✓ Valid citizen ID
|
|
2427
|
-
* anyIdSchema.parse("A812345678") // ✓ Valid new resident ID
|
|
2428
|
-
* anyIdSchema.parse("AA12345678") // ✓ Valid old resident ID
|
|
2429
|
-
*
|
|
2430
|
-
* // Citizen IDs only
|
|
2431
|
-
* const citizenSchema = twNationalId(false, { type: "citizen" })
|
|
2432
|
-
* citizenSchema.parse("A123456789") // ✓ Valid
|
|
2433
|
-
* citizenSchema.parse("A812345678") // ✗ Invalid (resident ID)
|
|
2434
|
-
*
|
|
2435
|
-
* // Resident IDs only (new format only)
|
|
2436
|
-
* const residentSchema = twNationalId(false, {
|
|
2437
|
-
* type: "resident",
|
|
2438
|
-
* allowOldResident: false
|
|
2439
|
-
* })
|
|
2440
|
-
* residentSchema.parse("A812345678") // ✓ Valid
|
|
2441
|
-
* residentSchema.parse("AA12345678") // ✗ Invalid (old format)
|
|
2442
|
-
*
|
|
2443
|
-
* // Optional with custom transformation
|
|
2444
|
-
* const optionalSchema = twNationalId(false, {
|
|
2445
|
-
* transform: (value) => value.replace(/[^A-Z0-9]/g, '') // Remove special chars
|
|
2446
|
-
* })
|
|
2447
|
-
*
|
|
2448
|
-
* // With custom error messages
|
|
2449
|
-
* const customSchema = twNationalId(false, {
|
|
2450
|
-
* i18n: {
|
|
2451
|
-
* en: { invalid: "Please enter a valid Taiwan National ID" },
|
|
2452
|
-
* 'zh-TW': { invalid: "請輸入有效的身分證或居留證號碼" }
|
|
2453
|
-
* }
|
|
2454
|
-
* })
|
|
2455
|
-
* ```
|
|
2456
|
-
*
|
|
2457
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2458
|
-
* @see {@link TwNationalIdOptions} for all available configuration options
|
|
2459
|
-
* @see {@link NationalIdType} for supported ID types
|
|
2460
|
-
* @see {@link validateTaiwanNationalId} for validation logic details
|
|
2461
|
-
*/
|
|
2462
|
-
declare function twNationalId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwNationalIdOptions<IsRequired>, 'required'>): TwNationalIdSchema<IsRequired>;
|
|
2463
|
-
|
|
2464
|
-
/**
|
|
2465
|
-
* @fileoverview Taiwan Mobile Phone Number validator for Zod Kit
|
|
2466
|
-
*
|
|
2467
|
-
* Provides validation for Taiwan mobile phone numbers with support for
|
|
2468
|
-
* all Taiwan mobile network operators and whitelist functionality.
|
|
2469
|
-
*
|
|
2470
|
-
* @author Ong Hoe Yuan
|
|
2471
|
-
* @version 0.0.5
|
|
2472
|
-
*/
|
|
2473
|
-
|
|
2474
|
-
/**
|
|
2475
|
-
* Type definition for mobile phone validation error messages
|
|
2476
|
-
*
|
|
2477
|
-
* @interface TwMobileMessages
|
|
2478
|
-
* @property {string} [required] - Message when field is required but empty
|
|
2479
|
-
* @property {string} [invalid] - Message when mobile number format is invalid
|
|
2480
|
-
* @property {string} [notInWhitelist] - Message when mobile number is not in whitelist
|
|
2481
|
-
*/
|
|
2482
|
-
type TwMobileMessages = {
|
|
2483
|
-
required?: string;
|
|
2484
|
-
invalid?: string;
|
|
2485
|
-
notInWhitelist?: string;
|
|
2486
|
-
};
|
|
2487
|
-
/**
|
|
2488
|
-
* Configuration options for Taiwan mobile phone validation
|
|
2489
|
-
*
|
|
2490
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2491
|
-
*
|
|
2492
|
-
* @interface TwMobileOptions
|
|
2493
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2494
|
-
* @property {string[]} [whitelist] - Array of specific mobile numbers that are always allowed
|
|
2495
|
-
* @property {Function} [transform] - Custom transformation function for mobile number
|
|
2496
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2497
|
-
* @property {Record<Locale, TwMobileMessages>} [i18n] - Custom error messages for different locales
|
|
2498
|
-
*/
|
|
2499
|
-
type TwMobileOptions<IsRequired extends boolean = true> = {
|
|
2500
|
-
whitelist?: string[];
|
|
2501
|
-
transform?: (value: string) => string;
|
|
2502
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2503
|
-
i18n?: Partial<Record<Locale, Partial<TwMobileMessages>>>;
|
|
2504
|
-
};
|
|
2505
|
-
/**
|
|
2506
|
-
* Type alias for mobile phone validation schema based on required flag
|
|
2507
|
-
*
|
|
2508
|
-
* @template IsRequired - Whether the field is required
|
|
2509
|
-
* @typedef TwMobileSchema
|
|
2510
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2511
|
-
*/
|
|
2512
|
-
type TwMobileSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2513
|
-
/**
|
|
2514
|
-
* Validates Taiwan mobile phone number format
|
|
2515
|
-
*
|
|
2516
|
-
* @param {string} value - The mobile phone number to validate
|
|
2517
|
-
* @returns {boolean} True if the mobile number is valid
|
|
2518
|
-
*
|
|
2519
|
-
* @description
|
|
2520
|
-
* Validates Taiwan mobile phone numbers according to the official numbering plan.
|
|
2521
|
-
* Taiwan mobile numbers use the format: 09X-XXXX-XXXX (10 digits total).
|
|
2522
|
-
*
|
|
2523
|
-
* Valid prefixes: 090, 091, 092, 093, 094, 095, 096, 097, 098, 099
|
|
2524
|
-
* - All major Taiwan mobile operators are covered
|
|
2525
|
-
* - Format: 09[0-9] followed by 7 additional digits
|
|
2526
|
-
*
|
|
2527
|
-
* @example
|
|
2528
|
-
* ```typescript
|
|
2529
|
-
* validateTaiwanMobile("0912345678") // true
|
|
2530
|
-
* validateTaiwanMobile("0987654321") // true
|
|
2531
|
-
* validateTaiwanMobile("0812345678") // false (invalid prefix)
|
|
2532
|
-
* validateTaiwanMobile("091234567") // false (too short)
|
|
2533
|
-
* ```
|
|
2534
|
-
*/
|
|
2535
|
-
declare const validateTaiwanMobile: (value: string) => boolean;
|
|
2536
|
-
/**
|
|
2537
|
-
* Creates a Zod schema for Taiwan mobile phone number validation
|
|
2538
|
-
*
|
|
2539
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2540
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2541
|
-
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2542
|
-
* @returns {TwMobileSchema<IsRequired>} Zod schema for mobile phone validation
|
|
2543
|
-
*
|
|
2544
|
-
* @description
|
|
2545
|
-
* Creates a comprehensive Taiwan mobile phone number validator with support for
|
|
2546
|
-
* all Taiwan mobile network operators and optional whitelist functionality.
|
|
2547
|
-
*
|
|
2548
|
-
* Features:
|
|
2549
|
-
* - Taiwan mobile number format validation (09X-XXXX-XXXX)
|
|
2550
|
-
* - Support for all Taiwan mobile operators (090-099 prefixes)
|
|
2551
|
-
* - Whitelist functionality for specific allowed numbers
|
|
2552
|
-
* - Automatic trimming and preprocessing
|
|
2553
|
-
* - Custom transformation functions
|
|
2554
|
-
* - Comprehensive internationalization
|
|
2555
|
-
* - Optional field support
|
|
2556
|
-
*
|
|
2557
|
-
* @example
|
|
2558
|
-
* ```typescript
|
|
2559
|
-
* // Basic mobile number validation
|
|
2560
|
-
* const basicSchema = twMobile() // optional by default
|
|
2561
|
-
* basicSchema.parse("0912345678") // ✓ Valid
|
|
2562
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
2563
|
-
*
|
|
2564
|
-
* // Required validation
|
|
2565
|
-
* const requiredSchema = parse("0912345678") // ✓ Valid
|
|
2566
|
-
(true)
|
|
2567
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
2568
|
-
*
|
|
2569
|
-
* basicSchema.parse("0987654321") // ✓ Valid
|
|
2570
|
-
* basicSchema.parse("0812345678") // ✗ Invalid (wrong prefix)
|
|
2571
|
-
*
|
|
2572
|
-
* // With whitelist (only specific numbers allowed)
|
|
2573
|
-
* const whitelistSchema = twMobile(false, {
|
|
2574
|
-
* whitelist: ["0912345678", "0987654321"]
|
|
2575
|
-
* })
|
|
2576
|
-
* whitelistSchema.parse("0912345678") // ✓ Valid (in whitelist)
|
|
2577
|
-
* whitelistSchema.parse("0911111111") // ✗ Invalid (not in whitelist)
|
|
2578
|
-
*
|
|
2579
|
-
* // Optional mobile number
|
|
2580
|
-
* const optionalSchema = twMobile(false)
|
|
2581
|
-
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2582
|
-
* optionalSchema.parse("0912345678") // ✓ Valid
|
|
2583
|
-
*
|
|
2584
|
-
* // With custom transformation
|
|
2585
|
-
* const transformSchema = twMobile(false, {
|
|
2586
|
-
* transform: (value) => value.replace(/[^0-9]/g, '') // Remove non-digits
|
|
2587
|
-
* })
|
|
2588
|
-
* transformSchema.parse("091-234-5678") // ✓ Valid (formatted input)
|
|
2589
|
-
* transformSchema.parse("091 234 5678") // ✓ Valid (spaced input)
|
|
2590
|
-
*
|
|
2591
|
-
* // With custom error messages
|
|
2592
|
-
* const customSchema = twMobile(false, {
|
|
2593
|
-
* i18n: {
|
|
2594
|
-
* en: { invalid: "Please enter a valid Taiwan mobile number" },
|
|
2595
|
-
* 'zh-TW': { invalid: "請輸入有效的台灣手機號碼" }
|
|
2596
|
-
* }
|
|
2597
|
-
* })
|
|
2598
|
-
* ```
|
|
2599
|
-
*
|
|
2600
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2601
|
-
* @see {@link TwMobileOptions} for all available configuration options
|
|
2602
|
-
* @see {@link validateTaiwanMobile} for validation logic details
|
|
2603
|
-
*/
|
|
2604
|
-
declare function twMobile<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwMobileOptions<IsRequired>, 'required'>): TwMobileSchema<IsRequired>;
|
|
2605
|
-
|
|
2606
|
-
/**
|
|
2607
|
-
* @fileoverview Taiwan Postal Code validator for Zod Kit
|
|
2608
|
-
*
|
|
2609
|
-
* Provides comprehensive validation for Taiwan postal codes with support for
|
|
2610
|
-
* 3-digit, 5-digit (legacy), and 6-digit (current) formats based on official
|
|
2611
|
-
* Chunghwa Post specifications.
|
|
2612
|
-
*
|
|
2613
|
-
* @author Ong Hoe Yuan
|
|
2614
|
-
* @version 0.0.5
|
|
2615
|
-
*/
|
|
2616
|
-
|
|
2617
|
-
/**
|
|
2618
|
-
* Type definition for postal code validation error messages
|
|
2619
|
-
*
|
|
2620
|
-
* @interface TwPostalCodeMessages
|
|
2621
|
-
* @property {string} [required] - Message when field is required but empty
|
|
2622
|
-
* @property {string} [invalid] - Message when postal code format is invalid
|
|
2623
|
-
* @property {string} [invalidFormat] - Message when format doesn't match expected pattern
|
|
2624
|
-
* @property {string} [invalidRange] - Message when postal code is outside valid range
|
|
2625
|
-
* @property {string} [legacy5DigitWarning] - Warning message for 5-digit legacy format
|
|
2626
|
-
* @property {string} [format3Only] - Message when only 3-digit format is allowed
|
|
2627
|
-
* @property {string} [format5Only] - Message when only 5-digit format is allowed
|
|
2628
|
-
* @property {string} [format6Only] - Message when only 6-digit format is allowed
|
|
2629
|
-
*/
|
|
2630
|
-
type TwPostalCodeMessages = {
|
|
2631
|
-
required?: string;
|
|
2632
|
-
invalid?: string;
|
|
2633
|
-
invalidFormat?: string;
|
|
2634
|
-
invalidRange?: string;
|
|
2635
|
-
legacy5DigitWarning?: string;
|
|
2636
|
-
format3Only?: string;
|
|
2637
|
-
format5Only?: string;
|
|
2638
|
-
format6Only?: string;
|
|
2639
|
-
invalidSuffix?: string;
|
|
2640
|
-
deprecated5Digit?: string;
|
|
2641
|
-
};
|
|
2642
|
-
/**
|
|
2643
|
-
* Postal code format types supported in Taiwan
|
|
2644
|
-
*
|
|
2645
|
-
* @typedef {"3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all"} TwPostalCodeFormatType
|
|
2646
|
-
*
|
|
2647
|
-
* Available formats:
|
|
2648
|
-
* - "3": 3-digit basic postal codes (100-982)
|
|
2649
|
-
* - "5": 5-digit postal codes (3+2 format, legacy)
|
|
2650
|
-
* - "6": 6-digit postal codes (3+3 format, current standard)
|
|
2651
|
-
* - "3+5": Accept both 3-digit and 5-digit formats
|
|
2652
|
-
* - "3+6": Accept both 3-digit and 6-digit formats (recommended)
|
|
2653
|
-
* - "5+6": Accept both 5-digit and 6-digit formats
|
|
2654
|
-
* - "all": Accept all formats (3, 5, and 6 digits)
|
|
2655
|
-
*/
|
|
2656
|
-
type TwPostalCodeFormatType = "3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all";
|
|
2657
|
-
/**
|
|
2658
|
-
* Configuration options for Taiwan postal code validation
|
|
2659
|
-
*
|
|
2660
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2661
|
-
*
|
|
2662
|
-
* @interface TwPostalCodeOptions
|
|
2663
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2664
|
-
* @property {TwPostalCodeFormatType} [format="3+6"] - Which postal code formats to accept
|
|
2665
|
-
* @property {boolean} [strictValidation=true] - Enable strict validation against known postal code ranges
|
|
2666
|
-
* @property {boolean} [allowDashes=true] - Whether to allow dashes in postal codes (e.g., "100-01" or "100-001")
|
|
2667
|
-
* @property {boolean} [warn5Digit=true] - Whether to show warning for 5-digit legacy format
|
|
2668
|
-
* @property {string[]} [allowedPrefixes] - Specific 3-digit prefixes to allow (if strictValidation is true)
|
|
2669
|
-
* @property {string[]} [blockedPrefixes] - Specific 3-digit prefixes to block
|
|
2670
|
-
* @property {Function} [transform] - Custom transformation function for postal codes
|
|
2671
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2672
|
-
* @property {Record<Locale, TwPostalCodeMessages>} [i18n] - Custom error messages for different locales
|
|
2673
|
-
*/
|
|
2674
|
-
type TwPostalCodeOptions<IsRequired extends boolean = true> = {
|
|
2675
|
-
format?: TwPostalCodeFormatType;
|
|
2676
|
-
strictValidation?: boolean;
|
|
2677
|
-
allowDashes?: boolean;
|
|
2678
|
-
warn5Digit?: boolean;
|
|
2679
|
-
allowedPrefixes?: string[];
|
|
2680
|
-
blockedPrefixes?: string[];
|
|
2681
|
-
transform?: (value: string) => string;
|
|
2682
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2683
|
-
i18n?: Partial<Record<Locale, Partial<TwPostalCodeMessages>>>;
|
|
2684
|
-
strictSuffixValidation?: boolean;
|
|
2685
|
-
deprecate5Digit?: boolean;
|
|
2686
|
-
};
|
|
2687
|
-
/**
|
|
2688
|
-
* Type alias for postal code validation schema based on required flag
|
|
2689
|
-
*
|
|
2690
|
-
* @template IsRequired - Whether the field is required
|
|
2691
|
-
* @typedef TwPostalCodeSchema
|
|
2692
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2693
|
-
*/
|
|
2694
|
-
type TwPostalCodeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2695
|
-
/**
|
|
2696
|
-
* Valid 3-digit postal code prefixes for Taiwan
|
|
2697
|
-
* Based on official Chunghwa Post data (2024)
|
|
2698
|
-
*/
|
|
2699
|
-
declare const VALID_3_DIGIT_PREFIXES: string[];
|
|
2700
|
-
/**
|
|
2701
|
-
* Validates 3-digit Taiwan postal code
|
|
2702
|
-
*
|
|
2703
|
-
* @param {string} value - The 3-digit postal code to validate
|
|
2704
|
-
* @param {boolean} strictValidation - Whether to validate against known postal code list
|
|
2705
|
-
* @param {string[]} allowedPrefixes - Specific prefixes to allow (overrides strictValidation)
|
|
2706
|
-
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
2707
|
-
* @returns {boolean} True if the postal code is valid
|
|
2708
|
-
*/
|
|
2709
|
-
declare const validate3DigitPostalCode: (value: string, strictValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
2710
|
-
/**
|
|
2711
|
-
* Validates 5-digit Taiwan postal code (legacy format)
|
|
2712
|
-
*
|
|
2713
|
-
* @param {string} value - The 5-digit postal code to validate
|
|
2714
|
-
* @param {boolean} strictValidation - Whether to validate the 3-digit prefix
|
|
2715
|
-
* @param {boolean} strictSuffixValidation - Whether to validate the 2-digit suffix
|
|
2716
|
-
* @param {string[]} allowedPrefixes - Specific prefixes to allow
|
|
2717
|
-
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
2718
|
-
* @returns {boolean} True if the postal code is valid
|
|
2719
|
-
*/
|
|
2720
|
-
declare const validate5DigitPostalCode: (value: string, strictValidation?: boolean, strictSuffixValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
2721
|
-
/**
|
|
2722
|
-
* Validates 6-digit Taiwan postal code (current format)
|
|
2723
|
-
*
|
|
2724
|
-
* @param {string} value - The 6-digit postal code to validate
|
|
2725
|
-
* @param {boolean} strictValidation - Whether to validate the 3-digit prefix
|
|
2726
|
-
* @param {boolean} strictSuffixValidation - Whether to validate the 3-digit suffix
|
|
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 validate6DigitPostalCode: (value: string, strictValidation?: boolean, strictSuffixValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
2732
|
-
/**
|
|
2733
|
-
* Main validation function for Taiwan postal codes
|
|
2734
|
-
*
|
|
2735
|
-
* @param {string} value - The postal code to validate
|
|
2736
|
-
* @param {TwPostalCodeFormatType} format - Which formats to accept
|
|
2737
|
-
* @param {boolean} strictValidation - Whether to validate against known postal codes
|
|
2738
|
-
* @param {boolean} strictSuffixValidation - Whether to validate suffix ranges
|
|
2739
|
-
* @param {boolean} allowDashes - Whether dashes/spaces are allowed and should be removed
|
|
2740
|
-
* @param {string[]} allowedPrefixes - Specific prefixes to allow
|
|
2741
|
-
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
2742
|
-
* @returns {boolean} True if the postal code is valid
|
|
2743
|
-
*/
|
|
2744
|
-
declare const validateTaiwanPostalCode: (value: string, format?: TwPostalCodeFormatType, strictValidation?: boolean, strictSuffixValidation?: boolean, allowDashes?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
2745
|
-
/**
|
|
2746
|
-
* Creates a Zod schema for Taiwan postal code validation
|
|
2747
|
-
*
|
|
2748
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2749
|
-
* @param {TwPostalCodeOptions<IsRequired>} [options] - Configuration options for postal code validation
|
|
2750
|
-
* @returns {TwPostalCodeSchema<IsRequired>} Zod schema for postal code validation
|
|
2751
|
-
*
|
|
2752
|
-
* @description
|
|
2753
|
-
* Creates a comprehensive Taiwan postal code validator that supports multiple formats
|
|
2754
|
-
* and provides extensive configuration options for different validation scenarios.
|
|
2755
|
-
*
|
|
2756
|
-
* Features:
|
|
2757
|
-
* - 3-digit, 5-digit, and 6-digit postal code format support
|
|
2758
|
-
* - Strict validation against official postal code ranges
|
|
2759
|
-
* - Legacy 5-digit format with optional warnings
|
|
2760
|
-
* - Custom prefix allowlist/blocklist support
|
|
2761
|
-
* - Dash and space handling in postal codes
|
|
2762
|
-
* - Automatic normalization and formatting
|
|
2763
|
-
* - Custom transformation functions
|
|
2764
|
-
* - Comprehensive internationalization
|
|
2765
|
-
* - Optional field support
|
|
2766
|
-
*
|
|
2767
|
-
* @example
|
|
2768
|
-
* ```typescript
|
|
2769
|
-
* // Accept 3-digit or 6-digit formats (recommended)
|
|
2770
|
-
* const modernSchema = twPostalCode()
|
|
2771
|
-
* modernSchema.parse("100") // ✓ Valid 3-digit
|
|
2772
|
-
* modernSchema.parse("100001") // ✓ Valid 6-digit
|
|
2773
|
-
* modernSchema.parse("10001") // ✗ Invalid (5-digit not allowed)
|
|
2774
|
-
*
|
|
2775
|
-
* // Accept all formats
|
|
2776
|
-
* const flexibleSchema = twPostalCode(false, { format: "all" })
|
|
2777
|
-
* flexibleSchema.parse("100") // ✓ Valid
|
|
2778
|
-
* flexibleSchema.parse("10001") // ✓ Valid
|
|
2779
|
-
* flexibleSchema.parse("100001") // ✓ Valid
|
|
2780
|
-
*
|
|
2781
|
-
* // Only 6-digit format (current standard)
|
|
2782
|
-
* const modernOnlySchema = twPostalCode(false, { format: "6" })
|
|
2783
|
-
* modernOnlySchema.parse("100001") // ✓ Valid
|
|
2784
|
-
* modernOnlySchema.parse("100") // ✗ Invalid
|
|
2785
|
-
*
|
|
2786
|
-
* // With dashes allowed
|
|
2787
|
-
* const dashSchema = twPostalCode(false, { allowDashes: true })
|
|
2788
|
-
* dashSchema.parse("100-001") // ✓ Valid (normalized to "100001")
|
|
2789
|
-
* dashSchema.parse("100-01") // ✓ Valid if 5-digit format allowed
|
|
2790
|
-
*
|
|
2791
|
-
* // Specific areas only
|
|
2792
|
-
* const taipeiSchema = twPostalCode(false, {
|
|
2793
|
-
* allowedPrefixes: ["100", "103", "104", "105", "106"]
|
|
2794
|
-
* })
|
|
2795
|
-
* taipeiSchema.parse("100001") // ✓ Valid (Taipei area)
|
|
2796
|
-
* taipeiSchema.parse("200001") // ✗ Invalid (not in allowlist)
|
|
2797
|
-
*
|
|
2798
|
-
* // Block specific areas
|
|
2799
|
-
* const blockedSchema = twPostalCode(false, {
|
|
2800
|
-
* blockedPrefixes: ["999"] // Block test codes
|
|
2801
|
-
* })
|
|
2802
|
-
*
|
|
2803
|
-
* // With warning for legacy format
|
|
2804
|
-
* const warnSchema = twPostalCode(false, {
|
|
2805
|
-
* format: "all",
|
|
2806
|
-
* warn5Digit: true
|
|
2807
|
-
* })
|
|
2808
|
-
* // Will validate but may show warning for 5-digit codes
|
|
2809
|
-
*
|
|
2810
|
-
* // Optional with custom transformation
|
|
2811
|
-
* const optionalSchema = twPostalCode(false, {
|
|
2812
|
-
* transform: (value) => value.replace(/\D/g, '') // Remove non-digits
|
|
2813
|
-
* })
|
|
2814
|
-
*
|
|
2815
|
-
* // Strict suffix validation for real postal codes
|
|
2816
|
-
* const strictSchema = twPostalCode(false, {
|
|
2817
|
-
* format: "6",
|
|
2818
|
-
* strictSuffixValidation: true // Validates suffix range 001-999
|
|
2819
|
-
* })
|
|
2820
|
-
* strictSchema.parse("100001") // ✓ Valid
|
|
2821
|
-
* strictSchema.parse("100000") // ✗ Invalid (suffix 000 not allowed)
|
|
2822
|
-
*
|
|
2823
|
-
* // Deprecate 5-digit codes entirely
|
|
2824
|
-
* const modern2024Schema = twPostalCode(false, {
|
|
2825
|
-
* format: "all",
|
|
2826
|
-
* deprecate5Digit: true // Throws error for any 5-digit code
|
|
2827
|
-
* })
|
|
2828
|
-
* modern2024Schema.parse("100001") // ✓ Valid 6-digit
|
|
2829
|
-
* modern2024Schema.parse("10001") // ✗ Error: deprecated format
|
|
2830
|
-
* ```
|
|
2831
|
-
*
|
|
2832
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2833
|
-
* @see {@link TwPostalCodeOptions} for all available configuration options
|
|
2834
|
-
* @see {@link TwPostalCodeFormatType} for supported formats
|
|
2835
|
-
* @see {@link validateTaiwanPostalCode} for validation logic details
|
|
2836
|
-
*/
|
|
2837
|
-
declare function twPostalCode<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwPostalCodeOptions<IsRequired>, 'required'>): TwPostalCodeSchema<IsRequired>;
|
|
2838
|
-
|
|
2839
|
-
/**
|
|
2840
|
-
* @fileoverview Taiwan Landline Telephone Number validator for Zod Kit
|
|
2841
|
-
*
|
|
2842
|
-
* Provides validation for Taiwan landline telephone numbers according to the
|
|
2843
|
-
* official 2024 telecom numbering plan with comprehensive area code support.
|
|
2844
|
-
*
|
|
2845
|
-
* @author Ong Hoe Yuan
|
|
2846
|
-
* @version 0.0.5
|
|
2847
|
-
*/
|
|
2848
|
-
|
|
2849
|
-
/**
|
|
2850
|
-
* Type definition for telephone validation error messages
|
|
2851
|
-
*
|
|
2852
|
-
* @interface TwTelMessages
|
|
2853
|
-
* @property {string} [required] - Message when field is required but empty
|
|
2854
|
-
* @property {string} [invalid] - Message when telephone number format is invalid
|
|
2855
|
-
* @property {string} [notInWhitelist] - Message when telephone number is not in whitelist
|
|
2856
|
-
*/
|
|
2857
|
-
type TwTelMessages = {
|
|
2858
|
-
required?: string;
|
|
2859
|
-
invalid?: string;
|
|
2860
|
-
notInWhitelist?: string;
|
|
2861
|
-
};
|
|
2862
|
-
/**
|
|
2863
|
-
* Configuration options for Taiwan landline telephone validation
|
|
2864
|
-
*
|
|
2865
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2866
|
-
*
|
|
2867
|
-
* @interface TwTelOptions
|
|
2868
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
2869
|
-
* @property {string[]} [whitelist] - Array of specific telephone numbers that are always allowed
|
|
2870
|
-
* @property {Function} [transform] - Custom transformation function for telephone number
|
|
2871
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
2872
|
-
* @property {Record<Locale, TwTelMessages>} [i18n] - Custom error messages for different locales
|
|
2873
|
-
*/
|
|
2874
|
-
type TwTelOptions<IsRequired extends boolean = true> = {
|
|
2875
|
-
whitelist?: string[];
|
|
2876
|
-
transform?: (value: string) => string;
|
|
2877
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
2878
|
-
i18n?: Partial<Record<Locale, Partial<TwTelMessages>>>;
|
|
2879
|
-
};
|
|
2880
|
-
/**
|
|
2881
|
-
* Type alias for telephone validation schema based on required flag
|
|
2882
|
-
*
|
|
2883
|
-
* @template IsRequired - Whether the field is required
|
|
2884
|
-
* @typedef TwTelSchema
|
|
2885
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
2886
|
-
*/
|
|
2887
|
-
type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
2888
|
-
/**
|
|
2889
|
-
* Validates Taiwan landline telephone number format (Official 2024 rules)
|
|
2890
|
-
*
|
|
2891
|
-
* @param {string} value - The telephone number to validate
|
|
2892
|
-
* @returns {boolean} True if the telephone number is valid
|
|
2893
|
-
*
|
|
2894
|
-
* @description
|
|
2895
|
-
* Validates Taiwan landline telephone numbers according to the official 2024
|
|
2896
|
-
* telecom numbering plan. Supports all Taiwan area codes and their specific
|
|
2897
|
-
* number patterns.
|
|
2898
|
-
*
|
|
2899
|
-
* Supported area codes and formats:
|
|
2900
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
2901
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
2902
|
-
* - 037: Miaoli - 6-7 digits
|
|
2903
|
-
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
2904
|
-
* - 049: Nantou - 6-7 digits
|
|
2905
|
-
* - 05: Yunlin, Chiayi - 7 digits
|
|
2906
|
-
* - 06: Tainan - 7 digits
|
|
2907
|
-
* - 07: Kaohsiung - 7-8 digits
|
|
2908
|
-
* - 08: Pingtung - 7 digits
|
|
2909
|
-
* - 0800: Toll-free - 6 digits
|
|
2910
|
-
* - 0809: Toll-free - 6 digits
|
|
2911
|
-
* - 082: Kinmen - 6 digits
|
|
2912
|
-
* - 0836: Matsu - 5-6 digits
|
|
2913
|
-
* - 089: Taitung - 6 digits
|
|
2914
|
-
*
|
|
2915
|
-
* @example
|
|
2916
|
-
* ```typescript
|
|
2917
|
-
* validateTaiwanTel("0223456789") // true (Taipei area)
|
|
2918
|
-
* validateTaiwanTel("0423288882") // true (Taichung area, 8 digits)
|
|
2919
|
-
* validateTaiwanTel("037234567") // true (Miaoli area)
|
|
2920
|
-
* validateTaiwanTel("082234567") // true (Kinmen area)
|
|
2921
|
-
* validateTaiwanTel("02-2345-6789") // true (with separators)
|
|
2922
|
-
* ```
|
|
2923
|
-
*/
|
|
2924
|
-
declare const validateTaiwanTel: (value: string) => boolean;
|
|
2925
|
-
/**
|
|
2926
|
-
* Creates a Zod schema for Taiwan landline telephone number validation
|
|
2927
|
-
*
|
|
2928
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
2929
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
2930
|
-
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
2931
|
-
* @returns {TwTelSchema<IsRequired>} Zod schema for telephone number validation
|
|
2932
|
-
*
|
|
2933
|
-
* @description
|
|
2934
|
-
* Creates a comprehensive Taiwan landline telephone number validator with support for
|
|
2935
|
-
* all Taiwan area codes according to the official 2024 telecom numbering plan.
|
|
2936
|
-
*
|
|
2937
|
-
* Features:
|
|
2938
|
-
* - Complete Taiwan area code support (02, 03, 037, 04, 049, 05, 06, 07, 08, 082, 0826, 0836, 089)
|
|
2939
|
-
* - Automatic separator handling (hyphens and spaces)
|
|
2940
|
-
* - Area-specific number length and pattern validation
|
|
2941
|
-
* - Whitelist functionality for specific allowed numbers
|
|
2942
|
-
* - Automatic trimming and preprocessing
|
|
2943
|
-
* - Custom transformation functions
|
|
2944
|
-
* - Comprehensive internationalization
|
|
2945
|
-
* - Optional field support
|
|
2946
|
-
*
|
|
2947
|
-
* @example
|
|
2948
|
-
* ```typescript
|
|
2949
|
-
* // Basic telephone number validation
|
|
2950
|
-
* const basicSchema = twTel() // optional by default
|
|
2951
|
-
* basicSchema.parse("0223456789") // ✓ Valid (Taipei)
|
|
2952
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
2953
|
-
*
|
|
2954
|
-
* // Required validation
|
|
2955
|
-
* const requiredSchema = parse("0223456789") // ✓ Valid (Taipei)
|
|
2956
|
-
(true)
|
|
2957
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
2958
|
-
*
|
|
2959
|
-
* basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
|
|
2960
|
-
* basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
|
|
2961
|
-
* basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
|
|
2962
|
-
*
|
|
2963
|
-
* // With whitelist (only specific numbers allowed)
|
|
2964
|
-
* const whitelistSchema = twTel(false, {
|
|
2965
|
-
* whitelist: ["0223456789", "0312345678"]
|
|
2966
|
-
* })
|
|
2967
|
-
* whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
|
|
2968
|
-
* whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
|
|
2969
|
-
*
|
|
2970
|
-
* // Optional telephone number
|
|
2971
|
-
* const optionalSchema = twTel(false)
|
|
2972
|
-
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
2973
|
-
* optionalSchema.parse("0223456789") // ✓ Valid
|
|
2974
|
-
*
|
|
2975
|
-
* // With custom transformation (remove separators)
|
|
2976
|
-
* const transformSchema = twTel(false, {
|
|
2977
|
-
* transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
|
|
2978
|
-
* })
|
|
2979
|
-
* transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
|
|
2980
|
-
* transformSchema.parse("02 2345 6789") // ✓ Valid (spaces removed)
|
|
2981
|
-
*
|
|
2982
|
-
* // With custom error messages
|
|
2983
|
-
* const customSchema = twTel(false, {
|
|
2984
|
-
* i18n: {
|
|
2985
|
-
* en: { invalid: "Please enter a valid Taiwan landline number" },
|
|
2986
|
-
* 'zh-TW': { invalid: "請輸入有效的台灣市話號碼" }
|
|
2987
|
-
* }
|
|
2988
|
-
* })
|
|
2989
|
-
* ```
|
|
2990
|
-
*
|
|
2991
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
2992
|
-
* @see {@link TwTelOptions} for all available configuration options
|
|
2993
|
-
* @see {@link validateTaiwanTel} for validation logic details
|
|
2994
|
-
*/
|
|
2995
|
-
declare function twTel<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwTelOptions<IsRequired>, 'required'>): TwTelSchema<IsRequired>;
|
|
2996
|
-
|
|
2997
|
-
/**
|
|
2998
|
-
* @fileoverview Taiwan Fax Number validator for Zod Kit
|
|
2999
|
-
*
|
|
3000
|
-
* Provides validation for Taiwan fax numbers according to the official 2024
|
|
3001
|
-
* telecom numbering plan. Uses the same format as landline telephone numbers.
|
|
3002
|
-
*
|
|
3003
|
-
* @author Ong Hoe Yuan
|
|
3004
|
-
* @version 0.0.5
|
|
3005
|
-
*/
|
|
3006
|
-
|
|
3007
|
-
/**
|
|
3008
|
-
* Type definition for fax number validation error messages
|
|
3009
|
-
*
|
|
3010
|
-
* @interface TwFaxMessages
|
|
3011
|
-
* @property {string} [required] - Message when field is required but empty
|
|
3012
|
-
* @property {string} [invalid] - Message when fax number format is invalid
|
|
3013
|
-
* @property {string} [notInWhitelist] - Message when fax number is not in whitelist
|
|
3014
|
-
*/
|
|
3015
|
-
type TwFaxMessages = {
|
|
3016
|
-
required?: string;
|
|
3017
|
-
invalid?: string;
|
|
3018
|
-
notInWhitelist?: string;
|
|
3019
|
-
};
|
|
3020
|
-
/**
|
|
3021
|
-
* Configuration options for Taiwan fax number validation
|
|
3022
|
-
*
|
|
3023
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
3024
|
-
*
|
|
3025
|
-
* @interface TwFaxOptions
|
|
3026
|
-
* @property {IsRequired} [required=true] - Whether the field is required
|
|
3027
|
-
* @property {string[]} [whitelist] - Array of specific fax numbers that are always allowed
|
|
3028
|
-
* @property {Function} [transform] - Custom transformation function for fax number
|
|
3029
|
-
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
3030
|
-
* @property {Record<Locale, TwFaxMessages>} [i18n] - Custom error messages for different locales
|
|
3031
|
-
*/
|
|
3032
|
-
type TwFaxOptions<IsRequired extends boolean = true> = {
|
|
3033
|
-
whitelist?: string[];
|
|
3034
|
-
transform?: (value: string) => string;
|
|
3035
|
-
defaultValue?: IsRequired extends true ? string : string | null;
|
|
3036
|
-
i18n?: Partial<Record<Locale, Partial<TwFaxMessages>>>;
|
|
3037
|
-
};
|
|
3038
|
-
/**
|
|
3039
|
-
* Type alias for fax number validation schema based on required flag
|
|
3040
|
-
*
|
|
3041
|
-
* @template IsRequired - Whether the field is required
|
|
3042
|
-
* @typedef TwFaxSchema
|
|
3043
|
-
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
3044
|
-
*/
|
|
3045
|
-
type TwFaxSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
3046
|
-
/**
|
|
3047
|
-
* Validates Taiwan fax number format (Official 2024 rules - same as landline)
|
|
3048
|
-
*
|
|
3049
|
-
* @param {string} value - The fax number to validate
|
|
3050
|
-
* @returns {boolean} True if the fax number is valid
|
|
3051
|
-
*
|
|
3052
|
-
* @description
|
|
3053
|
-
* Validates Taiwan fax numbers according to the official 2024 telecom numbering plan.
|
|
3054
|
-
* Fax numbers follow the same format as landline telephone numbers in Taiwan.
|
|
3055
|
-
*
|
|
3056
|
-
* Supported area codes and formats (same as landline):
|
|
3057
|
-
* - 02: Taipei, New Taipei, Keelung - 8 digits
|
|
3058
|
-
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
3059
|
-
* - 037: Miaoli - 6-7 digits
|
|
3060
|
-
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
3061
|
-
* - 049: Nantou - 7 digits
|
|
3062
|
-
* - 05: Yunlin, Chiayi - 7 digits
|
|
3063
|
-
* - 06: Tainan - 7 digits
|
|
3064
|
-
* - 07: Kaohsiung - 7 digits
|
|
3065
|
-
* - 08: Pingtung - 7 digits
|
|
3066
|
-
* - 082: Kinmen - 6 digits
|
|
3067
|
-
* - 0836: Matsu - 5 digits
|
|
3068
|
-
* - 089: Taitung - 6 digits
|
|
3069
|
-
*
|
|
3070
|
-
* @example
|
|
3071
|
-
* ```typescript
|
|
3072
|
-
* validateTaiwanFax("0223456789") // true (Taipei area)
|
|
3073
|
-
* validateTaiwanFax("0423288882") // true (Taichung area, 8 digits)
|
|
3074
|
-
* validateTaiwanFax("037234567") // true (Miaoli area)
|
|
3075
|
-
* validateTaiwanFax("02-2345-6789") // true (with separators)
|
|
3076
|
-
* ```
|
|
3077
|
-
*/
|
|
3078
|
-
declare const validateTaiwanFax: (value: string) => boolean;
|
|
3079
|
-
/**
|
|
3080
|
-
* Creates a Zod schema for Taiwan fax number validation
|
|
3081
|
-
*
|
|
3082
|
-
* @template IsRequired - Whether the field is required (affects return type)
|
|
3083
|
-
* @param {IsRequired} [required=false] - Whether the field is required
|
|
3084
|
-
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
3085
|
-
* @returns {TwFaxSchema<IsRequired>} Zod schema for fax number validation
|
|
3086
|
-
*
|
|
3087
|
-
* @description
|
|
3088
|
-
* Creates a comprehensive Taiwan fax number validator with support for all Taiwan
|
|
3089
|
-
* area codes. Fax numbers follow the same format as landline telephone numbers.
|
|
3090
|
-
*
|
|
3091
|
-
* Features:
|
|
3092
|
-
* - Complete Taiwan area code support (same as landline)
|
|
3093
|
-
* - Automatic separator handling (hyphens and spaces)
|
|
3094
|
-
* - Area-specific number length and pattern validation
|
|
3095
|
-
* - Whitelist functionality for specific allowed numbers
|
|
3096
|
-
* - Automatic trimming and preprocessing
|
|
3097
|
-
* - Custom transformation functions
|
|
3098
|
-
* - Comprehensive internationalization
|
|
3099
|
-
* - Optional field support
|
|
3100
|
-
*
|
|
3101
|
-
* @example
|
|
3102
|
-
* ```typescript
|
|
3103
|
-
* // Basic fax number validation
|
|
3104
|
-
* const basicSchema = twFax() // optional by default
|
|
3105
|
-
* basicSchema.parse("0223456789") // ✓ Valid (Taipei)
|
|
3106
|
-
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
3107
|
-
*
|
|
3108
|
-
* // Required validation
|
|
3109
|
-
* const requiredSchema = parse("0223456789") // ✓ Valid (Taipei)
|
|
3110
|
-
(true)
|
|
3111
|
-
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
3112
|
-
*
|
|
3113
|
-
* basicSchema.parse("0312345678") // ✓ Valid (Taoyuan)
|
|
3114
|
-
* basicSchema.parse("02-2345-6789") // ✓ Valid (with separators)
|
|
3115
|
-
* basicSchema.parse("0812345678") // ✗ Invalid (wrong format for 08)
|
|
3116
|
-
*
|
|
3117
|
-
* // With whitelist (only specific numbers allowed)
|
|
3118
|
-
* const whitelistSchema = twFax(false, {
|
|
3119
|
-
* whitelist: ["0223456789", "0312345678"]
|
|
3120
|
-
* })
|
|
3121
|
-
* whitelistSchema.parse("0223456789") // ✓ Valid (in whitelist)
|
|
3122
|
-
* whitelistSchema.parse("0287654321") // ✗ Invalid (not in whitelist)
|
|
3123
|
-
*
|
|
3124
|
-
* // Optional fax number
|
|
3125
|
-
* const optionalSchema = twFax(false)
|
|
3126
|
-
* optionalSchema.parse("") // ✓ Valid (returns null)
|
|
3127
|
-
* optionalSchema.parse("0223456789") // ✓ Valid
|
|
3128
|
-
*
|
|
3129
|
-
* // With custom transformation
|
|
3130
|
-
* const transformSchema = twFax(false, {
|
|
3131
|
-
* transform: (value) => value.replace(/[^0-9]/g, '') // Keep only digits
|
|
3132
|
-
* })
|
|
3133
|
-
* transformSchema.parse("02-2345-6789") // ✓ Valid (separators removed)
|
|
3134
|
-
*
|
|
3135
|
-
* // With custom error messages
|
|
3136
|
-
* const customSchema = twFax(false, {
|
|
3137
|
-
* i18n: {
|
|
3138
|
-
* en: { invalid: "Please enter a valid Taiwan fax number" },
|
|
3139
|
-
* 'zh-TW': { invalid: "請輸入有效的台灣傳真號碼" }
|
|
3140
|
-
* }
|
|
3141
|
-
* })
|
|
3142
|
-
* ```
|
|
3143
|
-
*
|
|
3144
|
-
* @throws {z.ZodError} When validation fails with specific error messages
|
|
3145
|
-
* @see {@link TwFaxOptions} for all available configuration options
|
|
3146
|
-
* @see {@link validateTaiwanFax} for validation logic details
|
|
3147
|
-
*/
|
|
3148
|
-
declare function twFax<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwFaxOptions<IsRequired>, 'required'>): TwFaxSchema<IsRequired>;
|
|
3149
|
-
|
|
3150
|
-
export { type BooleanMessages, type BooleanOptions, type BooleanSchema, DATETIME_PATTERNS, type DateMessages, type DateOptions, type DateSchema, type DateTimeFormat, type DateTimeMessages, type DateTimeOptions, type DateTimeSchema, type EmailMessages, type EmailOptions, type EmailSchema, type FileMessages, type FileOptions, type FileSchema, ID_PATTERNS, type IdMessages, type IdOptions, type IdSchema, type IdType, type Locale, type NationalIdType, type NumberMessages, type NumberOptions, type NumberSchema, type PasswordMessages, type PasswordOptions, type PasswordSchema, type PasswordStrength, TIME_PATTERNS, type TextMessages, type TextOptions, type TextSchema, type TimeFormat, type TimeMessages, type TimeOptions, type TimeSchema, type TwBusinessIdMessages, type TwBusinessIdOptions, type TwBusinessIdSchema, type TwFaxMessages, type TwFaxOptions, type TwFaxSchema, type TwMobileMessages, type TwMobileOptions, type TwMobileSchema, type TwNationalIdMessages, type TwNationalIdOptions, type TwNationalIdSchema, type TwPostalCodeFormatType, type TwPostalCodeMessages, type TwPostalCodeOptions, type TwPostalCodeSchema, type TwTelMessages, type TwTelOptions, type TwTelSchema, type UrlMessages, type UrlOptions, type UrlSchema, VALID_3_DIGIT_PREFIXES, boolean, date, datetime, detectIdType, email, file, getLocale, id, normalizeDateTimeValue, normalizeTime, number, parseDateTimeValue, parseTimeToMinutes, password, setLocale, text, time, twBusinessId, twFax, twMobile, twNationalId, twPostalCode, twTel, url, validate3DigitPostalCode, validate5DigitPostalCode, validate6DigitPostalCode, validateCitizenId, validateDateTimeFormat, validateIdType, validateNewResidentId, validateOldResidentId, validateTaiwanBusinessId, validateTaiwanFax, validateTaiwanMobile, validateTaiwanNationalId, validateTaiwanPostalCode, validateTaiwanTel, validateTimeFormat };
|
|
1
|
+
export { BooleanMessages, BooleanOptions, BooleanSchema, boolean } from './common/boolean.js';
|
|
2
|
+
export { ColorFormat, ColorMessages, ColorOptions, ColorSchema, color, validateColor } from './common/color.js';
|
|
3
|
+
export { CoordinateMessages, CoordinateOptions, CoordinateSchema, CoordinateType, coordinate, validateLatitude, validateLongitude } from './common/coordinate.js';
|
|
4
|
+
export { CreditCardMessages, CreditCardOptions, CreditCardSchema, CreditCardType, creditCard, detectCardType, validateCreditCard } from './common/credit-card.js';
|
|
5
|
+
export { DateMessages, DateOptions, DateSchema, date } from './common/date.js';
|
|
6
|
+
export { DATETIME_PATTERNS, DateTimeFormat, DateTimeMessages, DateTimeOptions, DateTimeSchema, datetime, normalizeDateTimeValue, parseDateTimeValue, validateDateTimeFormat } from './common/datetime.js';
|
|
7
|
+
export { EmailMessages, EmailOptions, EmailSchema, email } from './common/email.js';
|
|
8
|
+
export { FileMessages, FileOptions, FileSchema, file } from './common/file.js';
|
|
9
|
+
export { ID_PATTERNS, IdMessages, IdOptions, IdSchema, IdType, detectIdType, id, validateIdType } from './common/id.js';
|
|
10
|
+
export { IpMessages, IpOptions, IpSchema, IpVersion, ip, validateIPv4, validateIPv6 } from './common/ip.js';
|
|
11
|
+
export { NumberMessages, NumberOptions, NumberSchema, number } from './common/number.js';
|
|
12
|
+
export { PasswordMessages, PasswordOptions, PasswordSchema, PasswordStrength, password } from './common/password.js';
|
|
13
|
+
export { TextMessages, TextOptions, TextSchema, text } from './common/text.js';
|
|
14
|
+
export { TIME_PATTERNS, TimeFormat, TimeMessages, TimeOptions, TimeSchema, normalizeTime, parseTimeToMinutes, time, validateTimeFormat } from './common/time.js';
|
|
15
|
+
export { UrlMessages, UrlOptions, UrlSchema, url } from './common/url.js';
|
|
16
|
+
export { TAIWAN_BANK_CODES, TwBankAccountMessages, TwBankAccountOptions, TwBankAccountSchema, twBankAccount, validateTaiwanBankAccount } from './taiwan/bank-account.js';
|
|
17
|
+
export { TwBusinessIdMessages, TwBusinessIdOptions, TwBusinessIdSchema, twBusinessId, validateTaiwanBusinessId } from './taiwan/business-id.js';
|
|
18
|
+
export { TwFaxMessages, TwFaxOptions, TwFaxSchema, twFax, validateTaiwanFax } from './taiwan/fax.js';
|
|
19
|
+
export { TwInvoiceMessages, TwInvoiceOptions, TwInvoiceSchema, twInvoice, validateTaiwanInvoice } from './taiwan/invoice.js';
|
|
20
|
+
export { PlateType, TwLicensePlateMessages, TwLicensePlateOptions, TwLicensePlateSchema, twLicensePlate, validateTaiwanLicensePlate } from './taiwan/license-plate.js';
|
|
21
|
+
export { TwMobileMessages, TwMobileOptions, TwMobileSchema, twMobile, validateTaiwanMobile } from './taiwan/mobile.js';
|
|
22
|
+
export { NationalIdType, TwNationalIdMessages, TwNationalIdOptions, TwNationalIdSchema, twNationalId, validateCitizenId, validateNewResidentId, validateOldResidentId, validateTaiwanNationalId } from './taiwan/national-id.js';
|
|
23
|
+
export { PassportType, TwPassportMessages, TwPassportOptions, TwPassportSchema, twPassport, validateTaiwanPassport } from './taiwan/passport.js';
|
|
24
|
+
export { TwPostalCodeFormatType, TwPostalCodeMessages, TwPostalCodeOptions, TwPostalCodeSchema, VALID_3_DIGIT_PREFIXES, twPostalCode, validate3DigitPostalCode, validate5DigitPostalCode, validate6DigitPostalCode, validateTaiwanPostalCode } from './taiwan/postal-code.js';
|
|
25
|
+
export { TwTelMessages, TwTelOptions, TwTelSchema, twTel, validateTaiwanTel } from './taiwan/tel.js';
|
|
26
|
+
export { L as Locale, g as getLocale, s as setLocale } from './config-CABSSvAp.js';
|
|
27
|
+
import 'zod';
|
|
28
|
+
import 'dayjs';
|