@hy_ong/zod-kit 0.1.13 → 0.1.14
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 +3 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/validators/taiwan/tel.ts +12 -12
- package/tests/taiwan/tel.test.ts +12 -5
package/dist/index.cjs
CHANGED
|
@@ -3325,7 +3325,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3325
3325
|
return cleanValue.length === 10 && /^080[09]\d{6}$/.test(cleanValue);
|
|
3326
3326
|
}
|
|
3327
3327
|
if (areaCode4 === "0836") {
|
|
3328
|
-
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3328
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^0836\d{5,6}$/.test(cleanValue);
|
|
3329
3329
|
}
|
|
3330
3330
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3331
3331
|
if (areaCode3 === "037") {
|
|
@@ -3336,7 +3336,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3336
3336
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
3337
3337
|
}
|
|
3338
3338
|
if (areaCode3 === "049") {
|
|
3339
|
-
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
3339
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^049\d{6,7}$/.test(cleanValue);
|
|
3340
3340
|
}
|
|
3341
3341
|
if (areaCode3 === "082") {
|
|
3342
3342
|
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
@@ -3369,7 +3369,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3369
3369
|
if (firstDigit === "0" || firstDigit === "1") {
|
|
3370
3370
|
return false;
|
|
3371
3371
|
}
|
|
3372
|
-
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
3372
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^07[2-9]\d{6,7}$/.test(cleanValue);
|
|
3373
3373
|
}
|
|
3374
3374
|
if (areaCode2 === "08") {
|
|
3375
3375
|
const firstDigit = cleanValue[2];
|
package/dist/index.d.cts
CHANGED
|
@@ -2901,15 +2901,15 @@ type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
2901
2901
|
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
2902
2902
|
* - 037: Miaoli - 6-7 digits
|
|
2903
2903
|
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
2904
|
-
* - 049: Nantou - 7 digits
|
|
2904
|
+
* - 049: Nantou - 6-7 digits
|
|
2905
2905
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
2906
2906
|
* - 06: Tainan - 7 digits
|
|
2907
|
-
* - 07: Kaohsiung - 7 digits
|
|
2907
|
+
* - 07: Kaohsiung - 7-8 digits
|
|
2908
2908
|
* - 08: Pingtung - 7 digits
|
|
2909
2909
|
* - 0800: Toll-free - 6 digits
|
|
2910
2910
|
* - 0809: Toll-free - 6 digits
|
|
2911
2911
|
* - 082: Kinmen - 6 digits
|
|
2912
|
-
* - 0836: Matsu - 5 digits
|
|
2912
|
+
* - 0836: Matsu - 5-6 digits
|
|
2913
2913
|
* - 089: Taitung - 6 digits
|
|
2914
2914
|
*
|
|
2915
2915
|
* @example
|
package/dist/index.d.ts
CHANGED
|
@@ -2901,15 +2901,15 @@ type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
2901
2901
|
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
2902
2902
|
* - 037: Miaoli - 6-7 digits
|
|
2903
2903
|
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
2904
|
-
* - 049: Nantou - 7 digits
|
|
2904
|
+
* - 049: Nantou - 6-7 digits
|
|
2905
2905
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
2906
2906
|
* - 06: Tainan - 7 digits
|
|
2907
|
-
* - 07: Kaohsiung - 7 digits
|
|
2907
|
+
* - 07: Kaohsiung - 7-8 digits
|
|
2908
2908
|
* - 08: Pingtung - 7 digits
|
|
2909
2909
|
* - 0800: Toll-free - 6 digits
|
|
2910
2910
|
* - 0809: Toll-free - 6 digits
|
|
2911
2911
|
* - 082: Kinmen - 6 digits
|
|
2912
|
-
* - 0836: Matsu - 5 digits
|
|
2912
|
+
* - 0836: Matsu - 5-6 digits
|
|
2913
2913
|
* - 089: Taitung - 6 digits
|
|
2914
2914
|
*
|
|
2915
2915
|
* @example
|
package/dist/index.js
CHANGED
|
@@ -3247,7 +3247,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3247
3247
|
return cleanValue.length === 10 && /^080[09]\d{6}$/.test(cleanValue);
|
|
3248
3248
|
}
|
|
3249
3249
|
if (areaCode4 === "0836") {
|
|
3250
|
-
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3250
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^0836\d{5,6}$/.test(cleanValue);
|
|
3251
3251
|
}
|
|
3252
3252
|
const areaCode3 = cleanValue.substring(0, 3);
|
|
3253
3253
|
if (areaCode3 === "037") {
|
|
@@ -3258,7 +3258,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3258
3258
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue);
|
|
3259
3259
|
}
|
|
3260
3260
|
if (areaCode3 === "049") {
|
|
3261
|
-
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue);
|
|
3261
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^049\d{6,7}$/.test(cleanValue);
|
|
3262
3262
|
}
|
|
3263
3263
|
if (areaCode3 === "082") {
|
|
3264
3264
|
return cleanValue.length === 9 && /^082\d{6}$/.test(cleanValue);
|
|
@@ -3291,7 +3291,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3291
3291
|
if (firstDigit === "0" || firstDigit === "1") {
|
|
3292
3292
|
return false;
|
|
3293
3293
|
}
|
|
3294
|
-
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue);
|
|
3294
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^07[2-9]\d{6,7}$/.test(cleanValue);
|
|
3295
3295
|
}
|
|
3296
3296
|
if (areaCode2 === "08") {
|
|
3297
3297
|
const firstDigit = cleanValue[2];
|
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.14",
|
|
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",
|
|
@@ -70,15 +70,15 @@ export type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ?
|
|
|
70
70
|
* - 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
71
71
|
* - 037: Miaoli - 6-7 digits
|
|
72
72
|
* - 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
73
|
-
* - 049: Nantou - 7 digits
|
|
73
|
+
* - 049: Nantou - 6-7 digits
|
|
74
74
|
* - 05: Yunlin, Chiayi - 7 digits
|
|
75
75
|
* - 06: Tainan - 7 digits
|
|
76
|
-
* - 07: Kaohsiung - 7 digits
|
|
76
|
+
* - 07: Kaohsiung - 7-8 digits
|
|
77
77
|
* - 08: Pingtung - 7 digits
|
|
78
78
|
* - 0800: Toll-free - 6 digits
|
|
79
79
|
* - 0809: Toll-free - 6 digits
|
|
80
80
|
* - 082: Kinmen - 6 digits
|
|
81
|
-
* - 0836: Matsu - 5 digits
|
|
81
|
+
* - 0836: Matsu - 5-6 digits
|
|
82
82
|
* - 089: Taitung - 6 digits
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
@@ -96,14 +96,14 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
96
96
|
// 03: Taoyuan, Hsinchu, Yilan, Hualien - 7-8 digits
|
|
97
97
|
// 037: Miaoli - 6-7 digits
|
|
98
98
|
// 04: Taichung, Changhua, Nantou - 7-8 digits
|
|
99
|
-
// 049: Nantou - 7 digits
|
|
99
|
+
// 049: Nantou - 6-7 digits
|
|
100
100
|
// 05: Yunlin, Chiayi - 7 digits
|
|
101
101
|
// 06: Tainan - 7 digits
|
|
102
|
-
// 07: Kaohsiung - 7 digits
|
|
102
|
+
// 07: Kaohsiung - 7-8 digits
|
|
103
103
|
// 08: Pingtung - 7 digits
|
|
104
104
|
// 0800/0809: Toll-free - 6 digits
|
|
105
105
|
// 082: Kinmen - 6 digits
|
|
106
|
-
// 0836: Matsu - 5 digits
|
|
106
|
+
// 0836: Matsu - 5-6 digits
|
|
107
107
|
// 089: Taitung - 6 digits
|
|
108
108
|
|
|
109
109
|
// Remove common separators for validation
|
|
@@ -121,8 +121,8 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
121
121
|
return cleanValue.length === 10 && /^080[09]\d{6}$/.test(cleanValue)
|
|
122
122
|
}
|
|
123
123
|
if (areaCode4 === "0836") {
|
|
124
|
-
// Matsu: 0836 + 5 digits, total 9 digits
|
|
125
|
-
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue)
|
|
124
|
+
// Matsu: 0836 + 5-6 digits, total 9-10 digits
|
|
125
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^0836\d{5,6}$/.test(cleanValue)
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// Check 3-digit area codes
|
|
@@ -137,8 +137,8 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
137
137
|
return (cleanValue.length === 9 || cleanValue.length === 10) && /^037[2-9]\d{5,6}$/.test(cleanValue)
|
|
138
138
|
}
|
|
139
139
|
if (areaCode3 === "049") {
|
|
140
|
-
// Nantou: 049 + 7 digits, total 10 digits
|
|
141
|
-
return cleanValue.length === 10 && /^049\d{7}$/.test(cleanValue)
|
|
140
|
+
// Nantou: 049 + 6-7 digits, total 9-10 digits
|
|
141
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^049\d{6,7}$/.test(cleanValue)
|
|
142
142
|
}
|
|
143
143
|
if (areaCode3 === "082") {
|
|
144
144
|
// Kinmen: 082 + 6 digits, total 9 digits
|
|
@@ -178,13 +178,13 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
178
178
|
return cleanValue.length === 9 && /^06\d{7}$/.test(cleanValue)
|
|
179
179
|
}
|
|
180
180
|
if (areaCode2 === "07") {
|
|
181
|
-
// Kaohsiung: 07 + 7 digits, total 9 digits
|
|
181
|
+
// Kaohsiung: 07 + 7-8 digits, total 9-10 digits
|
|
182
182
|
// User number must start with 2-9 (not 0 or 1)
|
|
183
183
|
const firstDigit = cleanValue[2]
|
|
184
184
|
if (firstDigit === "0" || firstDigit === "1") {
|
|
185
185
|
return false
|
|
186
186
|
}
|
|
187
|
-
return cleanValue.length === 9 && /^07[2-9]\d{6}$/.test(cleanValue)
|
|
187
|
+
return (cleanValue.length === 9 || cleanValue.length === 10) && /^07[2-9]\d{6,7}$/.test(cleanValue)
|
|
188
188
|
}
|
|
189
189
|
if (areaCode2 === "08") {
|
|
190
190
|
// Pingtung: 08 + 7 digits, total 9 digits
|
package/tests/taiwan/tel.test.ts
CHANGED
|
@@ -13,9 +13,10 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
13
13
|
expect(schema.parse("0223456789")).toBe("0223456789") // 02-2345-6789 (10 digits)
|
|
14
14
|
expect(schema.parse("0232345678")).toBe("0232345678") // 02-3234-5678 (10 digits)
|
|
15
15
|
|
|
16
|
-
// Kaohsiung (07) - requires 9 digits total, the first digit after 07 must be 2-9
|
|
16
|
+
// Kaohsiung (07) - requires 9-10 digits total, the first digit after 07 must be 2-9
|
|
17
17
|
expect(schema.parse("072345678")).toBe("072345678") // 07-234-5678 (9 digits)
|
|
18
18
|
expect(schema.parse("073456789")).toBe("073456789") // 07-345-6789 (9 digits)
|
|
19
|
+
expect(schema.parse("0787267820")).toBe("0787267820") // 07-8726-7820 (10 digits)
|
|
19
20
|
|
|
20
21
|
// Taichung (04) - requires 9 digits total
|
|
21
22
|
expect(schema.parse("041234567")).toBe("041234567") // 04-123-4567 (9 digits)
|
|
@@ -52,6 +53,7 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
52
53
|
// Numbers with dashes
|
|
53
54
|
expect(schema.parse("02-2345-6789")).toBe("02-2345-6789")
|
|
54
55
|
expect(schema.parse("07-234-5678")).toBe("07-234-5678")
|
|
56
|
+
expect(schema.parse("07-87267820")).toBe("07-87267820")
|
|
55
57
|
expect(schema.parse("082-234567")).toBe("082-234567")
|
|
56
58
|
|
|
57
59
|
// Numbers with spaces
|
|
@@ -241,15 +243,18 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
241
243
|
it("should correctly validate Taiwan telephone numbers", () => {
|
|
242
244
|
// Valid numbers
|
|
243
245
|
expect(validateTaiwanTel("0223456789")).toBe(true) // Taipei
|
|
244
|
-
expect(validateTaiwanTel("072345678")).toBe(true) // Kaohsiung
|
|
246
|
+
expect(validateTaiwanTel("072345678")).toBe(true) // Kaohsiung 9 digits
|
|
247
|
+
expect(validateTaiwanTel("0787267820")).toBe(true) // Kaohsiung 10 digits
|
|
245
248
|
expect(validateTaiwanTel("041234567")).toBe(true) // Taichung
|
|
246
249
|
expect(validateTaiwanTel("037234567")).toBe(true) // Miaoli
|
|
247
|
-
expect(validateTaiwanTel("0492345678")).toBe(true) // Nantou
|
|
250
|
+
expect(validateTaiwanTel("0492345678")).toBe(true) // Nantou 10 digits
|
|
251
|
+
expect(validateTaiwanTel("049234567")).toBe(true) // Nantou 9 digits
|
|
248
252
|
expect(validateTaiwanTel("084234567")).toBe(true) // Pingtung
|
|
249
253
|
expect(validateTaiwanTel("082234567")).toBe(true) // Kinmen
|
|
250
254
|
expect(validateTaiwanTel("089234567")).toBe(true) // Taitung
|
|
251
255
|
expect(validateTaiwanTel("082661234")).toBe(true) // Wuqiu
|
|
252
|
-
expect(validateTaiwanTel("083621234")).toBe(true) // Matsu
|
|
256
|
+
expect(validateTaiwanTel("083621234")).toBe(true) // Matsu 9 digits
|
|
257
|
+
expect(validateTaiwanTel("0836212345")).toBe(true) // Matsu 10 digits
|
|
253
258
|
|
|
254
259
|
// Toll-free numbers
|
|
255
260
|
expect(validateTaiwanTel("0800123456")).toBe(true) // 0800
|
|
@@ -259,6 +264,7 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
259
264
|
// Valid with separators
|
|
260
265
|
expect(validateTaiwanTel("02-2345-6789")).toBe(true)
|
|
261
266
|
expect(validateTaiwanTel("07 234 5678")).toBe(true)
|
|
267
|
+
expect(validateTaiwanTel("07-8726-7820")).toBe(true)
|
|
262
268
|
expect(validateTaiwanTel("082-234567")).toBe(true)
|
|
263
269
|
|
|
264
270
|
// Invalid numbers
|
|
@@ -370,7 +376,7 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
370
376
|
{ code: "04", numbers: ["041234567"] }, // Taichung (9 digits) - from utility test ✓
|
|
371
377
|
{ code: "037", numbers: ["037234567"] }, // Miaoli (9 digits, first digit 2) - from utility test ✓
|
|
372
378
|
{ code: "049", numbers: ["0492345678"] }, // Nantou (10 digits, first digit 2) - from utility test ✓
|
|
373
|
-
{ code: "07", numbers: ["072345678"] }, // Kaohsiung (9 digits, first digit 2) - from utility test ✓
|
|
379
|
+
{ code: "07", numbers: ["072345678", "0787267820"] }, // Kaohsiung (9-10 digits, first digit 2-9) - from utility test ✓
|
|
374
380
|
{ code: "08", numbers: ["084234567"] }, // Pingtung (9 digits, first digit 4) - from utility test ✓
|
|
375
381
|
{ code: "082", numbers: ["082234567"] }, // Kinmen (9 digits, first digit 2) - from utility test ✓
|
|
376
382
|
{ code: "089", numbers: ["089234567"] }, // Taitung (9 digits, first digit 2) - from utility test ✓
|
|
@@ -405,6 +411,7 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
405
411
|
const realLandlineNumbers = [
|
|
406
412
|
"0223456789", // Taipei 10-digit (valid first digit 2) - from utility test ✓
|
|
407
413
|
"072345678", // Kaohsiung 9-digit (valid first digit 2) - from utility test ✓
|
|
414
|
+
"0787267820", // Kaohsiung 10-digit (valid first digit 8) ✓
|
|
408
415
|
"041234567", // Taichung 9-digit - from utility test ✓
|
|
409
416
|
"037234567", // Miaoli 9-digit (valid first digit 2) - from utility test ✓
|
|
410
417
|
"0492345678", // Nantou 10-digit (valid first digit 2) - from utility test ✓
|