@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
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Taiwan National ID (身分證/居留證) validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides validation for Taiwan National ID cards (身分證) and
|
|
8
|
+
* Resident Certificates (居留證) with support for both old and new formats.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for national ID validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface TwNationalIdMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [invalid] - Message when national ID format or checksum is invalid
|
|
20
|
+
*/
|
|
21
|
+
type TwNationalIdMessages = {
|
|
22
|
+
required?: string;
|
|
23
|
+
invalid?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Types of Taiwan national identification documents
|
|
27
|
+
*
|
|
28
|
+
* @typedef {"citizen" | "resident" | "both"} NationalIdType
|
|
29
|
+
*
|
|
30
|
+
* Available types:
|
|
31
|
+
* - citizen: National ID card (身分證字號) for Taiwan citizens
|
|
32
|
+
* - resident: Resident certificate (居留證號) for foreign residents
|
|
33
|
+
* - both: Accept both citizen and resident IDs
|
|
34
|
+
*/
|
|
35
|
+
type NationalIdType = "citizen" | "resident" | "both";
|
|
36
|
+
/**
|
|
37
|
+
* Configuration options for Taiwan national ID validation
|
|
38
|
+
*
|
|
39
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
40
|
+
*
|
|
41
|
+
* @interface TwNationalIdOptions
|
|
42
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
43
|
+
* @property {NationalIdType} [type="both"] - Type of ID to accept
|
|
44
|
+
* @property {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
45
|
+
* @property {Function} [transform] - Custom transformation function for ID
|
|
46
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
47
|
+
* @property {Record<Locale, TwNationalIdMessages>} [i18n] - Custom error messages for different locales
|
|
48
|
+
*/
|
|
49
|
+
type TwNationalIdOptions<IsRequired extends boolean = true> = {
|
|
50
|
+
type?: NationalIdType;
|
|
51
|
+
allowOldResident?: boolean;
|
|
52
|
+
transform?: (value: string) => string;
|
|
53
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
54
|
+
i18n?: Partial<Record<Locale, Partial<TwNationalIdMessages>>>;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Type alias for national ID validation schema based on required flag
|
|
58
|
+
*
|
|
59
|
+
* @template IsRequired - Whether the field is required
|
|
60
|
+
* @typedef TwNationalIdSchema
|
|
61
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
62
|
+
*/
|
|
63
|
+
type TwNationalIdSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
64
|
+
/**
|
|
65
|
+
* Validates Taiwan citizen national ID card (身分證字號)
|
|
66
|
+
*
|
|
67
|
+
* @param {string} value - The citizen ID to validate
|
|
68
|
+
* @returns {boolean} True if the citizen ID is valid
|
|
69
|
+
*
|
|
70
|
+
* @description
|
|
71
|
+
* Validates Taiwan citizen ID format: 1 letter + 1 gender digit (1-2) + 8 digits
|
|
72
|
+
* Uses checksum algorithm with city code conversion and weighted sum.
|
|
73
|
+
*
|
|
74
|
+
* Format: [A-Z][1-2]XXXXXXXX
|
|
75
|
+
* - First letter: City/county code
|
|
76
|
+
* - Second digit: Gender (1=male, 2=female)
|
|
77
|
+
* - Last 8 digits: Serial number + checksum
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* validateCitizenId("A123456789") // true/false based on checksum
|
|
82
|
+
* validateCitizenId("A323456789") // false (invalid gender digit)
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare const validateCitizenId: (value: string) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Validates old-style Taiwan resident certificate (舊式居留證號)
|
|
88
|
+
*
|
|
89
|
+
* @param {string} value - The old-style resident ID to validate
|
|
90
|
+
* @returns {boolean} True if the old-style resident ID is valid
|
|
91
|
+
*
|
|
92
|
+
* @description
|
|
93
|
+
* Validates old-style resident ID format: 1 letter + 1 gender letter + 8 digits
|
|
94
|
+
* Uses checksum algorithm with city code and gender code conversion.
|
|
95
|
+
*
|
|
96
|
+
* Format: [A-Z][ABCD]XXXXXXXX
|
|
97
|
+
* - First letter: City/county code
|
|
98
|
+
* - Second letter: Gender code (A/C=male, B/D=female)
|
|
99
|
+
* - Last 8 digits: Serial number + checksum
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* validateOldResidentId("AA12345678") // true/false based on checksum
|
|
104
|
+
* validateOldResidentId("AE12345678") // false (invalid gender letter)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare const validateOldResidentId: (value: string) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Validates new-style Taiwan resident certificate (新式居留證號)
|
|
110
|
+
*
|
|
111
|
+
* @param {string} value - The new-style resident ID to validate
|
|
112
|
+
* @returns {boolean} True if the new-style resident ID is valid
|
|
113
|
+
*
|
|
114
|
+
* @description
|
|
115
|
+
* Validates new-style resident ID format: 1 letter + 1 type digit + 8 digits
|
|
116
|
+
* Uses the same checksum algorithm as citizen IDs.
|
|
117
|
+
*
|
|
118
|
+
* Format: [A-Z][89]XXXXXXXX
|
|
119
|
+
* - First letter: City/county code
|
|
120
|
+
* - Second digit: Type indicator (8 or 9)
|
|
121
|
+
* - Last 8 digits: Serial number + checksum
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* validateNewResidentId("A812345678") // true/false based on checksum
|
|
126
|
+
* validateNewResidentId("A712345678") // false (invalid type digit)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare const validateNewResidentId: (value: string) => boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Main validation function for Taiwan national IDs
|
|
132
|
+
*
|
|
133
|
+
* @param {string} value - The national ID to validate
|
|
134
|
+
* @param {NationalIdType} [type="both"] - Type of ID to accept
|
|
135
|
+
* @param {boolean} [allowOldResident=true] - Whether to accept old-style resident certificates
|
|
136
|
+
* @returns {boolean} True if the national ID is valid
|
|
137
|
+
*
|
|
138
|
+
* @description
|
|
139
|
+
* Validates Taiwan national IDs based on the specified type and options.
|
|
140
|
+
* Supports citizen IDs, resident certificates (both old and new styles).
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* validateTaiwanNationalId("A123456789", "citizen") // Citizen ID only
|
|
145
|
+
* validateTaiwanNationalId("A812345678", "resident") // Resident ID only
|
|
146
|
+
* validateTaiwanNationalId("A123456789", "both") // Accept any valid format
|
|
147
|
+
* validateTaiwanNationalId("AA12345678", "both", false) // Reject old resident format
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare const validateTaiwanNationalId: (value: string, type?: NationalIdType, allowOldResident?: boolean) => boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a Zod schema for Taiwan National ID validation
|
|
153
|
+
*
|
|
154
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
155
|
+
* @param {TwNationalIdOptions<IsRequired>} [options] - Configuration options for national ID validation
|
|
156
|
+
* @returns {TwNationalIdSchema<IsRequired>} Zod schema for national ID validation
|
|
157
|
+
*
|
|
158
|
+
* @description
|
|
159
|
+
* Creates a comprehensive Taiwan National ID validator that supports both
|
|
160
|
+
* citizen IDs and resident certificates with configurable validation rules.
|
|
161
|
+
*
|
|
162
|
+
* Features:
|
|
163
|
+
* - Citizen ID validation (身分證字號)
|
|
164
|
+
* - Resident certificate validation (居留證號, old and new formats)
|
|
165
|
+
* - Configurable ID type acceptance
|
|
166
|
+
* - Automatic case conversion to uppercase
|
|
167
|
+
* - Checksum verification
|
|
168
|
+
* - Custom transformation functions
|
|
169
|
+
* - Comprehensive internationalization
|
|
170
|
+
* - Optional field support
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // Accept any valid Taiwan ID
|
|
175
|
+
* const anyIdSchema = twNationalId()
|
|
176
|
+
* anyIdSchema.parse("A123456789") // ✓ Valid citizen ID
|
|
177
|
+
* anyIdSchema.parse("A812345678") // ✓ Valid new resident ID
|
|
178
|
+
* anyIdSchema.parse("AA12345678") // ✓ Valid old resident ID
|
|
179
|
+
*
|
|
180
|
+
* // Citizen IDs only
|
|
181
|
+
* const citizenSchema = twNationalId(false, { type: "citizen" })
|
|
182
|
+
* citizenSchema.parse("A123456789") // ✓ Valid
|
|
183
|
+
* citizenSchema.parse("A812345678") // ✗ Invalid (resident ID)
|
|
184
|
+
*
|
|
185
|
+
* // Resident IDs only (new format only)
|
|
186
|
+
* const residentSchema = twNationalId(false, {
|
|
187
|
+
* type: "resident",
|
|
188
|
+
* allowOldResident: false
|
|
189
|
+
* })
|
|
190
|
+
* residentSchema.parse("A812345678") // ✓ Valid
|
|
191
|
+
* residentSchema.parse("AA12345678") // ✗ Invalid (old format)
|
|
192
|
+
*
|
|
193
|
+
* // Optional with custom transformation
|
|
194
|
+
* const optionalSchema = twNationalId(false, {
|
|
195
|
+
* transform: (value) => value.replace(/[^A-Z0-9]/g, '') // Remove special chars
|
|
196
|
+
* })
|
|
197
|
+
*
|
|
198
|
+
* // With custom error messages
|
|
199
|
+
* const customSchema = twNationalId(false, {
|
|
200
|
+
* i18n: {
|
|
201
|
+
* en: { invalid: "Please enter a valid Taiwan National ID" },
|
|
202
|
+
* 'zh-TW': { invalid: "請輸入有效的身分證或居留證號碼" }
|
|
203
|
+
* }
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
208
|
+
* @see {@link TwNationalIdOptions} for all available configuration options
|
|
209
|
+
* @see {@link NationalIdType} for supported ID types
|
|
210
|
+
* @see {@link validateTaiwanNationalId} for validation logic details
|
|
211
|
+
*/
|
|
212
|
+
declare function twNationalId<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwNationalIdOptions<IsRequired>, 'required'>): TwNationalIdSchema<IsRequired>;
|
|
213
|
+
|
|
214
|
+
export { type NationalIdType, type TwNationalIdMessages, type TwNationalIdOptions, type TwNationalIdSchema, twNationalId, validateCitizenId, validateNewResidentId, validateOldResidentId, validateTaiwanNationalId };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
twNationalId,
|
|
3
|
+
validateCitizenId,
|
|
4
|
+
validateNewResidentId,
|
|
5
|
+
validateOldResidentId,
|
|
6
|
+
validateTaiwanNationalId
|
|
7
|
+
} from "../chunk-COYKBWTI.js";
|
|
8
|
+
import "../chunk-6AAP4LPF.js";
|
|
9
|
+
export {
|
|
10
|
+
twNationalId,
|
|
11
|
+
validateCitizenId,
|
|
12
|
+
validateNewResidentId,
|
|
13
|
+
validateOldResidentId,
|
|
14
|
+
validateTaiwanNationalId
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkZNJLWJX3cjs = require('../chunk-ZNJLWJX3.cjs');
|
|
5
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.twPassport = _chunkZNJLWJX3cjs.twPassport; exports.validateTaiwanPassport = _chunkZNJLWJX3cjs.validateTaiwanPassport;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
type PassportType = "ordinary" | "diplomatic" | "official" | "travel" | "any";
|
|
5
|
+
type TwPassportMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
};
|
|
9
|
+
type TwPassportOptions<IsRequired extends boolean = true> = {
|
|
10
|
+
passportType?: PassportType;
|
|
11
|
+
transform?: (value: string) => string;
|
|
12
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
13
|
+
i18n?: Partial<Record<Locale, Partial<TwPassportMessages>>>;
|
|
14
|
+
};
|
|
15
|
+
type TwPassportSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
16
|
+
declare const validateTaiwanPassport: (value: string) => boolean;
|
|
17
|
+
declare function twPassport<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwPassportOptions<IsRequired>, "required">): TwPassportSchema<IsRequired>;
|
|
18
|
+
|
|
19
|
+
export { type PassportType, type TwPassportMessages, type TwPassportOptions, type TwPassportSchema, twPassport, validateTaiwanPassport };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
type PassportType = "ordinary" | "diplomatic" | "official" | "travel" | "any";
|
|
5
|
+
type TwPassportMessages = {
|
|
6
|
+
required?: string;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
};
|
|
9
|
+
type TwPassportOptions<IsRequired extends boolean = true> = {
|
|
10
|
+
passportType?: PassportType;
|
|
11
|
+
transform?: (value: string) => string;
|
|
12
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
13
|
+
i18n?: Partial<Record<Locale, Partial<TwPassportMessages>>>;
|
|
14
|
+
};
|
|
15
|
+
type TwPassportSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
16
|
+
declare const validateTaiwanPassport: (value: string) => boolean;
|
|
17
|
+
declare function twPassport<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwPassportOptions<IsRequired>, "required">): TwPassportSchema<IsRequired>;
|
|
18
|
+
|
|
19
|
+
export { type PassportType, type TwPassportMessages, type TwPassportOptions, type TwPassportSchema, twPassport, validateTaiwanPassport };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkJOLSGZGNcjs = require('../chunk-JOLSGZGN.cjs');
|
|
9
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exports.VALID_3_DIGIT_PREFIXES = _chunkJOLSGZGNcjs.VALID_3_DIGIT_PREFIXES; exports.twPostalCode = _chunkJOLSGZGNcjs.twPostalCode; exports.validate3DigitPostalCode = _chunkJOLSGZGNcjs.validate3DigitPostalCode; exports.validate5DigitPostalCode = _chunkJOLSGZGNcjs.validate5DigitPostalCode; exports.validate6DigitPostalCode = _chunkJOLSGZGNcjs.validate6DigitPostalCode; exports.validateTaiwanPostalCode = _chunkJOLSGZGNcjs.validateTaiwanPostalCode;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Taiwan Postal Code validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive validation for Taiwan postal codes with support for
|
|
8
|
+
* 3-digit, 5-digit (legacy), and 6-digit (current) formats based on official
|
|
9
|
+
* Chunghwa Post specifications.
|
|
10
|
+
*
|
|
11
|
+
* @author Ong Hoe Yuan
|
|
12
|
+
* @version 0.0.5
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Type definition for postal code validation error messages
|
|
17
|
+
*
|
|
18
|
+
* @interface TwPostalCodeMessages
|
|
19
|
+
* @property {string} [required] - Message when field is required but empty
|
|
20
|
+
* @property {string} [invalid] - Message when postal code format is invalid
|
|
21
|
+
* @property {string} [invalidFormat] - Message when format doesn't match expected pattern
|
|
22
|
+
* @property {string} [invalidRange] - Message when postal code is outside valid range
|
|
23
|
+
* @property {string} [legacy5DigitWarning] - Warning message for 5-digit legacy format
|
|
24
|
+
* @property {string} [format3Only] - Message when only 3-digit format is allowed
|
|
25
|
+
* @property {string} [format5Only] - Message when only 5-digit format is allowed
|
|
26
|
+
* @property {string} [format6Only] - Message when only 6-digit format is allowed
|
|
27
|
+
*/
|
|
28
|
+
type TwPostalCodeMessages = {
|
|
29
|
+
required?: string;
|
|
30
|
+
invalid?: string;
|
|
31
|
+
invalidFormat?: string;
|
|
32
|
+
invalidRange?: string;
|
|
33
|
+
legacy5DigitWarning?: string;
|
|
34
|
+
format3Only?: string;
|
|
35
|
+
format5Only?: string;
|
|
36
|
+
format6Only?: string;
|
|
37
|
+
invalidSuffix?: string;
|
|
38
|
+
deprecated5Digit?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Postal code format types supported in Taiwan
|
|
42
|
+
*
|
|
43
|
+
* @typedef {"3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all"} TwPostalCodeFormatType
|
|
44
|
+
*
|
|
45
|
+
* Available formats:
|
|
46
|
+
* - "3": 3-digit basic postal codes (100-982)
|
|
47
|
+
* - "5": 5-digit postal codes (3+2 format, legacy)
|
|
48
|
+
* - "6": 6-digit postal codes (3+3 format, current standard)
|
|
49
|
+
* - "3+5": Accept both 3-digit and 5-digit formats
|
|
50
|
+
* - "3+6": Accept both 3-digit and 6-digit formats (recommended)
|
|
51
|
+
* - "5+6": Accept both 5-digit and 6-digit formats
|
|
52
|
+
* - "all": Accept all formats (3, 5, and 6 digits)
|
|
53
|
+
*/
|
|
54
|
+
type TwPostalCodeFormatType = "3" | "5" | "6" | "3+5" | "3+6" | "5+6" | "all";
|
|
55
|
+
/**
|
|
56
|
+
* Configuration options for Taiwan postal code validation
|
|
57
|
+
*
|
|
58
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
59
|
+
*
|
|
60
|
+
* @interface TwPostalCodeOptions
|
|
61
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
62
|
+
* @property {TwPostalCodeFormatType} [format="3+6"] - Which postal code formats to accept
|
|
63
|
+
* @property {boolean} [strictValidation=true] - Enable strict validation against known postal code ranges
|
|
64
|
+
* @property {boolean} [allowDashes=true] - Whether to allow dashes in postal codes (e.g., "100-01" or "100-001")
|
|
65
|
+
* @property {boolean} [warn5Digit=true] - Whether to show warning for 5-digit legacy format
|
|
66
|
+
* @property {string[]} [allowedPrefixes] - Specific 3-digit prefixes to allow (if strictValidation is true)
|
|
67
|
+
* @property {string[]} [blockedPrefixes] - Specific 3-digit prefixes to block
|
|
68
|
+
* @property {Function} [transform] - Custom transformation function for postal codes
|
|
69
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
70
|
+
* @property {Record<Locale, TwPostalCodeMessages>} [i18n] - Custom error messages for different locales
|
|
71
|
+
*/
|
|
72
|
+
type TwPostalCodeOptions<IsRequired extends boolean = true> = {
|
|
73
|
+
format?: TwPostalCodeFormatType;
|
|
74
|
+
strictValidation?: boolean;
|
|
75
|
+
allowDashes?: boolean;
|
|
76
|
+
warn5Digit?: boolean;
|
|
77
|
+
allowedPrefixes?: string[];
|
|
78
|
+
blockedPrefixes?: string[];
|
|
79
|
+
transform?: (value: string) => string;
|
|
80
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
81
|
+
i18n?: Partial<Record<Locale, Partial<TwPostalCodeMessages>>>;
|
|
82
|
+
strictSuffixValidation?: boolean;
|
|
83
|
+
deprecate5Digit?: boolean;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Type alias for postal code validation schema based on required flag
|
|
87
|
+
*
|
|
88
|
+
* @template IsRequired - Whether the field is required
|
|
89
|
+
* @typedef TwPostalCodeSchema
|
|
90
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
91
|
+
*/
|
|
92
|
+
type TwPostalCodeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
93
|
+
/**
|
|
94
|
+
* Valid 3-digit postal code prefixes for Taiwan
|
|
95
|
+
* Based on official Chunghwa Post data (2024)
|
|
96
|
+
*/
|
|
97
|
+
declare const VALID_3_DIGIT_PREFIXES: string[];
|
|
98
|
+
/**
|
|
99
|
+
* Validates 3-digit Taiwan postal code
|
|
100
|
+
*
|
|
101
|
+
* @param {string} value - The 3-digit postal code to validate
|
|
102
|
+
* @param {boolean} strictValidation - Whether to validate against known postal code list
|
|
103
|
+
* @param {string[]} allowedPrefixes - Specific prefixes to allow (overrides strictValidation)
|
|
104
|
+
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
105
|
+
* @returns {boolean} True if the postal code is valid
|
|
106
|
+
*/
|
|
107
|
+
declare const validate3DigitPostalCode: (value: string, strictValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Validates 5-digit Taiwan postal code (legacy format)
|
|
110
|
+
*
|
|
111
|
+
* @param {string} value - The 5-digit postal code to validate
|
|
112
|
+
* @param {boolean} strictValidation - Whether to validate the 3-digit prefix
|
|
113
|
+
* @param {boolean} strictSuffixValidation - Whether to validate the 2-digit suffix
|
|
114
|
+
* @param {string[]} allowedPrefixes - Specific prefixes to allow
|
|
115
|
+
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
116
|
+
* @returns {boolean} True if the postal code is valid
|
|
117
|
+
*/
|
|
118
|
+
declare const validate5DigitPostalCode: (value: string, strictValidation?: boolean, strictSuffixValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Validates 6-digit Taiwan postal code (current format)
|
|
121
|
+
*
|
|
122
|
+
* @param {string} value - The 6-digit postal code to validate
|
|
123
|
+
* @param {boolean} strictValidation - Whether to validate the 3-digit prefix
|
|
124
|
+
* @param {boolean} strictSuffixValidation - Whether to validate the 3-digit suffix
|
|
125
|
+
* @param {string[]} allowedPrefixes - Specific prefixes to allow
|
|
126
|
+
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
127
|
+
* @returns {boolean} True if the postal code is valid
|
|
128
|
+
*/
|
|
129
|
+
declare const validate6DigitPostalCode: (value: string, strictValidation?: boolean, strictSuffixValidation?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Main validation function for Taiwan postal codes
|
|
132
|
+
*
|
|
133
|
+
* @param {string} value - The postal code to validate
|
|
134
|
+
* @param {TwPostalCodeFormatType} format - Which formats to accept
|
|
135
|
+
* @param {boolean} strictValidation - Whether to validate against known postal codes
|
|
136
|
+
* @param {boolean} strictSuffixValidation - Whether to validate suffix ranges
|
|
137
|
+
* @param {boolean} allowDashes - Whether dashes/spaces are allowed and should be removed
|
|
138
|
+
* @param {string[]} allowedPrefixes - Specific prefixes to allow
|
|
139
|
+
* @param {string[]} blockedPrefixes - Specific prefixes to block
|
|
140
|
+
* @returns {boolean} True if the postal code is valid
|
|
141
|
+
*/
|
|
142
|
+
declare const validateTaiwanPostalCode: (value: string, format?: TwPostalCodeFormatType, strictValidation?: boolean, strictSuffixValidation?: boolean, allowDashes?: boolean, allowedPrefixes?: string[], blockedPrefixes?: string[]) => boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Creates a Zod schema for Taiwan postal code validation
|
|
145
|
+
*
|
|
146
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
147
|
+
* @param {TwPostalCodeOptions<IsRequired>} [options] - Configuration options for postal code validation
|
|
148
|
+
* @returns {TwPostalCodeSchema<IsRequired>} Zod schema for postal code validation
|
|
149
|
+
*
|
|
150
|
+
* @description
|
|
151
|
+
* Creates a comprehensive Taiwan postal code validator that supports multiple formats
|
|
152
|
+
* and provides extensive configuration options for different validation scenarios.
|
|
153
|
+
*
|
|
154
|
+
* Features:
|
|
155
|
+
* - 3-digit, 5-digit, and 6-digit postal code format support
|
|
156
|
+
* - Strict validation against official postal code ranges
|
|
157
|
+
* - Legacy 5-digit format with optional warnings
|
|
158
|
+
* - Custom prefix allowlist/blocklist support
|
|
159
|
+
* - Dash and space handling in postal codes
|
|
160
|
+
* - Automatic normalization and formatting
|
|
161
|
+
* - Custom transformation functions
|
|
162
|
+
* - Comprehensive internationalization
|
|
163
|
+
* - Optional field support
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Accept 3-digit or 6-digit formats (recommended)
|
|
168
|
+
* const modernSchema = twPostalCode()
|
|
169
|
+
* modernSchema.parse("100") // ✓ Valid 3-digit
|
|
170
|
+
* modernSchema.parse("100001") // ✓ Valid 6-digit
|
|
171
|
+
* modernSchema.parse("10001") // ✗ Invalid (5-digit not allowed)
|
|
172
|
+
*
|
|
173
|
+
* // Accept all formats
|
|
174
|
+
* const flexibleSchema = twPostalCode(false, { format: "all" })
|
|
175
|
+
* flexibleSchema.parse("100") // ✓ Valid
|
|
176
|
+
* flexibleSchema.parse("10001") // ✓ Valid
|
|
177
|
+
* flexibleSchema.parse("100001") // ✓ Valid
|
|
178
|
+
*
|
|
179
|
+
* // Only 6-digit format (current standard)
|
|
180
|
+
* const modernOnlySchema = twPostalCode(false, { format: "6" })
|
|
181
|
+
* modernOnlySchema.parse("100001") // ✓ Valid
|
|
182
|
+
* modernOnlySchema.parse("100") // ✗ Invalid
|
|
183
|
+
*
|
|
184
|
+
* // With dashes allowed
|
|
185
|
+
* const dashSchema = twPostalCode(false, { allowDashes: true })
|
|
186
|
+
* dashSchema.parse("100-001") // ✓ Valid (normalized to "100001")
|
|
187
|
+
* dashSchema.parse("100-01") // ✓ Valid if 5-digit format allowed
|
|
188
|
+
*
|
|
189
|
+
* // Specific areas only
|
|
190
|
+
* const taipeiSchema = twPostalCode(false, {
|
|
191
|
+
* allowedPrefixes: ["100", "103", "104", "105", "106"]
|
|
192
|
+
* })
|
|
193
|
+
* taipeiSchema.parse("100001") // ✓ Valid (Taipei area)
|
|
194
|
+
* taipeiSchema.parse("200001") // ✗ Invalid (not in allowlist)
|
|
195
|
+
*
|
|
196
|
+
* // Block specific areas
|
|
197
|
+
* const blockedSchema = twPostalCode(false, {
|
|
198
|
+
* blockedPrefixes: ["999"] // Block test codes
|
|
199
|
+
* })
|
|
200
|
+
*
|
|
201
|
+
* // With warning for legacy format
|
|
202
|
+
* const warnSchema = twPostalCode(false, {
|
|
203
|
+
* format: "all",
|
|
204
|
+
* warn5Digit: true
|
|
205
|
+
* })
|
|
206
|
+
* // Will validate but may show warning for 5-digit codes
|
|
207
|
+
*
|
|
208
|
+
* // Optional with custom transformation
|
|
209
|
+
* const optionalSchema = twPostalCode(false, {
|
|
210
|
+
* transform: (value) => value.replace(/\D/g, '') // Remove non-digits
|
|
211
|
+
* })
|
|
212
|
+
*
|
|
213
|
+
* // Strict suffix validation for real postal codes
|
|
214
|
+
* const strictSchema = twPostalCode(false, {
|
|
215
|
+
* format: "6",
|
|
216
|
+
* strictSuffixValidation: true // Validates suffix range 001-999
|
|
217
|
+
* })
|
|
218
|
+
* strictSchema.parse("100001") // ✓ Valid
|
|
219
|
+
* strictSchema.parse("100000") // ✗ Invalid (suffix 000 not allowed)
|
|
220
|
+
*
|
|
221
|
+
* // Deprecate 5-digit codes entirely
|
|
222
|
+
* const modern2024Schema = twPostalCode(false, {
|
|
223
|
+
* format: "all",
|
|
224
|
+
* deprecate5Digit: true // Throws error for any 5-digit code
|
|
225
|
+
* })
|
|
226
|
+
* modern2024Schema.parse("100001") // ✓ Valid 6-digit
|
|
227
|
+
* modern2024Schema.parse("10001") // ✗ Error: deprecated format
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
231
|
+
* @see {@link TwPostalCodeOptions} for all available configuration options
|
|
232
|
+
* @see {@link TwPostalCodeFormatType} for supported formats
|
|
233
|
+
* @see {@link validateTaiwanPostalCode} for validation logic details
|
|
234
|
+
*/
|
|
235
|
+
declare function twPostalCode<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TwPostalCodeOptions<IsRequired>, 'required'>): TwPostalCodeSchema<IsRequired>;
|
|
236
|
+
|
|
237
|
+
export { type TwPostalCodeFormatType, type TwPostalCodeMessages, type TwPostalCodeOptions, type TwPostalCodeSchema, VALID_3_DIGIT_PREFIXES, twPostalCode, validate3DigitPostalCode, validate5DigitPostalCode, validate6DigitPostalCode, validateTaiwanPostalCode };
|