@hy_ong/zod-kit 0.1.5 → 0.1.7
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/dist/index.cjs +40 -8
- package/dist/index.js +40 -8
- package/package.json +1 -1
- package/src/validators/taiwan/fax.ts +24 -4
- package/src/validators/taiwan/tel.ts +24 -4
- package/tests/taiwan/tel.test.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -3331,7 +3331,11 @@ var validateTaiwanTel = (value) => {
|
|
|
3331
3331
|
}
|
|
3332
3332
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3333
3333
|
if (areaCode3 === "037") {
|
|
3334
|
-
|
|
3334
|
+
const firstDigit = cleanValue[3];
|
|
3335
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3336
|
+
return false;
|
|
3337
|
+
}
|
|
3338
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
3335
3339
|
}
|
|
3336
3340
|
if (areaCode3 === "049") {
|
|
3337
3341
|
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
@@ -3344,7 +3348,11 @@ var validateTaiwanTel = (value) => {
|
|
|
3344
3348
|
}
|
|
3345
3349
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3346
3350
|
if (areaCode2 === "02") {
|
|
3347
|
-
|
|
3351
|
+
const firstDigit = cleanValue[2];
|
|
3352
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3353
|
+
return false;
|
|
3354
|
+
}
|
|
3355
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue);
|
|
3348
3356
|
}
|
|
3349
3357
|
if (areaCode2 === "03") {
|
|
3350
3358
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
@@ -3359,10 +3367,18 @@ var validateTaiwanTel = (value) => {
|
|
|
3359
3367
|
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3360
3368
|
}
|
|
3361
3369
|
if (areaCode2 === "07") {
|
|
3362
|
-
|
|
3370
|
+
const firstDigit = cleanValue[2];
|
|
3371
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3372
|
+
return false;
|
|
3373
|
+
}
|
|
3374
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
3363
3375
|
}
|
|
3364
3376
|
if (areaCode2 === "08") {
|
|
3365
|
-
|
|
3377
|
+
const firstDigit = cleanValue[2];
|
|
3378
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
3379
|
+
return false;
|
|
3380
|
+
}
|
|
3381
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue);
|
|
3366
3382
|
}
|
|
3367
3383
|
return false;
|
|
3368
3384
|
};
|
|
@@ -3437,7 +3453,11 @@ var validateTaiwanFax = (value) => {
|
|
|
3437
3453
|
}
|
|
3438
3454
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3439
3455
|
if (areaCode3 === "037") {
|
|
3440
|
-
|
|
3456
|
+
const firstDigit = cleanValue[3];
|
|
3457
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3458
|
+
return false;
|
|
3459
|
+
}
|
|
3460
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
3441
3461
|
}
|
|
3442
3462
|
if (areaCode3 === "049") {
|
|
3443
3463
|
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
@@ -3450,7 +3470,11 @@ var validateTaiwanFax = (value) => {
|
|
|
3450
3470
|
}
|
|
3451
3471
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3452
3472
|
if (areaCode2 === "02") {
|
|
3453
|
-
|
|
3473
|
+
const firstDigit = cleanValue[2];
|
|
3474
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3475
|
+
return false;
|
|
3476
|
+
}
|
|
3477
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue);
|
|
3454
3478
|
}
|
|
3455
3479
|
if (areaCode2 === "03") {
|
|
3456
3480
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
@@ -3465,10 +3489,18 @@ var validateTaiwanFax = (value) => {
|
|
|
3465
3489
|
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3466
3490
|
}
|
|
3467
3491
|
if (areaCode2 === "07") {
|
|
3468
|
-
|
|
3492
|
+
const firstDigit = cleanValue[2];
|
|
3493
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3494
|
+
return false;
|
|
3495
|
+
}
|
|
3496
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
3469
3497
|
}
|
|
3470
3498
|
if (areaCode2 === "08") {
|
|
3471
|
-
|
|
3499
|
+
const firstDigit = cleanValue[2];
|
|
3500
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
3501
|
+
return false;
|
|
3502
|
+
}
|
|
3503
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue);
|
|
3472
3504
|
}
|
|
3473
3505
|
return false;
|
|
3474
3506
|
};
|
package/dist/index.js
CHANGED
|
@@ -3253,7 +3253,11 @@ var validateTaiwanTel = (value) => {
|
|
|
3253
3253
|
}
|
|
3254
3254
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3255
3255
|
if (areaCode3 === "037") {
|
|
3256
|
-
|
|
3256
|
+
const firstDigit = cleanValue[3];
|
|
3257
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3258
|
+
return false;
|
|
3259
|
+
}
|
|
3260
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
3257
3261
|
}
|
|
3258
3262
|
if (areaCode3 === "049") {
|
|
3259
3263
|
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
@@ -3266,7 +3270,11 @@ var validateTaiwanTel = (value) => {
|
|
|
3266
3270
|
}
|
|
3267
3271
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3268
3272
|
if (areaCode2 === "02") {
|
|
3269
|
-
|
|
3273
|
+
const firstDigit = cleanValue[2];
|
|
3274
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3275
|
+
return false;
|
|
3276
|
+
}
|
|
3277
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue);
|
|
3270
3278
|
}
|
|
3271
3279
|
if (areaCode2 === "03") {
|
|
3272
3280
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
@@ -3281,10 +3289,18 @@ var validateTaiwanTel = (value) => {
|
|
|
3281
3289
|
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3282
3290
|
}
|
|
3283
3291
|
if (areaCode2 === "07") {
|
|
3284
|
-
|
|
3292
|
+
const firstDigit = cleanValue[2];
|
|
3293
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3294
|
+
return false;
|
|
3295
|
+
}
|
|
3296
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
3285
3297
|
}
|
|
3286
3298
|
if (areaCode2 === "08") {
|
|
3287
|
-
|
|
3299
|
+
const firstDigit = cleanValue[2];
|
|
3300
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
3301
|
+
return false;
|
|
3302
|
+
}
|
|
3303
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue);
|
|
3288
3304
|
}
|
|
3289
3305
|
return false;
|
|
3290
3306
|
};
|
|
@@ -3359,7 +3375,11 @@ var validateTaiwanFax = (value) => {
|
|
|
3359
3375
|
}
|
|
3360
3376
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3361
3377
|
if (areaCode3 === "037") {
|
|
3362
|
-
|
|
3378
|
+
const firstDigit = cleanValue[3];
|
|
3379
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3380
|
+
return false;
|
|
3381
|
+
}
|
|
3382
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
3363
3383
|
}
|
|
3364
3384
|
if (areaCode3 === "049") {
|
|
3365
3385
|
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
@@ -3372,7 +3392,11 @@ var validateTaiwanFax = (value) => {
|
|
|
3372
3392
|
}
|
|
3373
3393
|
const areaCode2 = cleanValue.substring(0, 2);
|
|
3374
3394
|
if (areaCode2 === "02") {
|
|
3375
|
-
|
|
3395
|
+
const firstDigit = cleanValue[2];
|
|
3396
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3397
|
+
return false;
|
|
3398
|
+
}
|
|
3399
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue);
|
|
3376
3400
|
}
|
|
3377
3401
|
if (areaCode2 === "03") {
|
|
3378
3402
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^03\d{7,8}$/.test(cleanValue);
|
|
@@ -3387,10 +3411,18 @@ var validateTaiwanFax = (value) => {
|
|
|
3387
3411
|
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue);
|
|
3388
3412
|
}
|
|
3389
3413
|
if (areaCode2 === "07") {
|
|
3390
|
-
|
|
3414
|
+
const firstDigit = cleanValue[2];
|
|
3415
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
3416
|
+
return false;
|
|
3417
|
+
}
|
|
3418
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
3391
3419
|
}
|
|
3392
3420
|
if (areaCode2 === "08") {
|
|
3393
|
-
|
|
3421
|
+
const firstDigit = cleanValue[2];
|
|
3422
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
3423
|
+
return false;
|
|
3424
|
+
}
|
|
3425
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue);
|
|
3394
3426
|
}
|
|
3395
3427
|
return false;
|
|
3396
3428
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hy_ong/zod-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "A comprehensive TypeScript library providing pre-built Zod validation schemas with full internationalization support for common data types and Taiwan-specific formats",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -120,7 +120,12 @@ const validateTaiwanFax = (value: string): boolean => {
|
|
|
120
120
|
const areaCode3 = cleanValue.substring(0, 3)
|
|
121
121
|
if (areaCode3 === '037') {
|
|
122
122
|
// Miaoli: 037 + 6-7 digits, total 9-10 digits
|
|
123
|
-
|
|
123
|
+
// User number must start with 2-9 (not 0 or 1)
|
|
124
|
+
const firstDigit = cleanValue[3]
|
|
125
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue)
|
|
124
129
|
}
|
|
125
130
|
if (areaCode3 === '049') {
|
|
126
131
|
// Nantou: 049 + 7 digits, total 10 digits
|
|
@@ -140,7 +145,12 @@ const validateTaiwanFax = (value: string): boolean => {
|
|
|
140
145
|
|
|
141
146
|
if (areaCode2 === '02') {
|
|
142
147
|
// Taipei, New Taipei, Keelung: 02 + 8 digits, total 10 digits
|
|
143
|
-
|
|
148
|
+
// User number must start with 2-9 (not 0 or 1)
|
|
149
|
+
const firstDigit = cleanValue[2]
|
|
150
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue)
|
|
144
154
|
}
|
|
145
155
|
if (areaCode2 === '03') {
|
|
146
156
|
// Taoyuan, Hsinchu, Yilan, Hualien: 03 + 7-8 digits, total 9-10 digits
|
|
@@ -160,11 +170,21 @@ const validateTaiwanFax = (value: string): boolean => {
|
|
|
160
170
|
}
|
|
161
171
|
if (areaCode2 === '07') {
|
|
162
172
|
// Kaohsiung: 07 + 7 digits, total 9 digits
|
|
163
|
-
|
|
173
|
+
// User number must start with 2-9 (not 0 or 1)
|
|
174
|
+
const firstDigit = cleanValue[2]
|
|
175
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
176
|
+
return false
|
|
177
|
+
}
|
|
178
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue)
|
|
164
179
|
}
|
|
165
180
|
if (areaCode2 === '08') {
|
|
166
181
|
// Pingtung: 08 + 7 digits, total 9 digits
|
|
167
|
-
|
|
182
|
+
// User number must start with 4, 7, or 8 (format: 4&7&8+6D)
|
|
183
|
+
const firstDigit = cleanValue[2]
|
|
184
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
185
|
+
return false // Invalid first digit for 08 area code
|
|
186
|
+
}
|
|
187
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue)
|
|
168
188
|
}
|
|
169
189
|
|
|
170
190
|
return false
|
|
@@ -122,7 +122,12 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
122
122
|
const areaCode3 = cleanValue.substring(0, 3)
|
|
123
123
|
if (areaCode3 === "037") {
|
|
124
124
|
// Miaoli: 037 + 6-7 digits, total 9-10 digits
|
|
125
|
-
|
|
125
|
+
// User number must start with 2-9 (not 0 or 1)
|
|
126
|
+
const firstDigit = cleanValue[3]
|
|
127
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
128
|
+
return false
|
|
129
|
+
}
|
|
130
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue)
|
|
126
131
|
}
|
|
127
132
|
if (areaCode3 === "049") {
|
|
128
133
|
// Nantou: 049 + 7 digits, total 10 digits
|
|
@@ -142,7 +147,12 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
142
147
|
|
|
143
148
|
if (areaCode2 === "02") {
|
|
144
149
|
// Taipei, New Taipei, Keelung: 02 + 8 digits, total 10 digits
|
|
145
|
-
|
|
150
|
+
// User number must start with 2-9 (not 0 or 1)
|
|
151
|
+
const firstDigit = cleanValue[2]
|
|
152
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
return cleanValue.length === 10 && /^02[2-9]\d{7}$/.test(cleanValue)
|
|
146
156
|
}
|
|
147
157
|
if (areaCode2 === "03") {
|
|
148
158
|
// Taoyuan, Hsinchu, Yilan, Hualien: 03 + 7-8 digits, total 9-10 digits
|
|
@@ -162,11 +172,21 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
162
172
|
}
|
|
163
173
|
if (areaCode2 === "07") {
|
|
164
174
|
// Kaohsiung: 07 + 7 digits, total 9 digits
|
|
165
|
-
|
|
175
|
+
// User number must start with 2-9 (not 0 or 1)
|
|
176
|
+
const firstDigit = cleanValue[2]
|
|
177
|
+
if (firstDigit === "0" || firstDigit === "1") {
|
|
178
|
+
return false
|
|
179
|
+
}
|
|
180
|
+
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue)
|
|
166
181
|
}
|
|
167
182
|
if (areaCode2 === "08") {
|
|
168
183
|
// Pingtung: 08 + 7 digits, total 9 digits
|
|
169
|
-
|
|
184
|
+
// User number must start with 4, 7, or 8 (format: 4&7&8+6D)
|
|
185
|
+
const firstDigit = cleanValue[2]
|
|
186
|
+
if (firstDigit !== "4" && firstDigit !== "7" && firstDigit !== "8") {
|
|
187
|
+
return false // Invalid first digit for 08 area code
|
|
188
|
+
}
|
|
189
|
+
return cleanValue.length === 9 && /^08[478]\d{6}$/.test(cleanValue)
|
|
170
190
|
}
|
|
171
191
|
|
|
172
192
|
return false
|
package/tests/taiwan/tel.test.ts
CHANGED
|
@@ -20,6 +20,7 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
20
20
|
// Taichung (04) - requires 9 digits total
|
|
21
21
|
expect(schema.parse("041234567")).toBe("041234567") // 04-123-4567 (9 digits)
|
|
22
22
|
expect(schema.parse("043456789")).toBe("043456789") // 04-345-6789 (9 digits)
|
|
23
|
+
expect(schema.parse("04-23288882")).toBe("04-23288882") // 04-232-88882 (10 digits)
|
|
23
24
|
|
|
24
25
|
// Tainan (06) - requires 9 digits total
|
|
25
26
|
expect(schema.parse("061234567")).toBe("061234567") // 06-123-4567 (9 digits)
|