@hy_ong/zod-kit 0.1.12 → 0.1.13
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 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/package.json +1 -1
- package/src/validators/taiwan/tel.ts +7 -0
- package/tests/taiwan/tel.test.ts +15 -0
package/dist/index.cjs
CHANGED
|
@@ -3321,6 +3321,9 @@ var validateTaiwanTel = (value) => {
|
|
|
3321
3321
|
return false;
|
|
3322
3322
|
}
|
|
3323
3323
|
const areaCode4 = cleanValue.substring(0, 4);
|
|
3324
|
+
if (areaCode4 === "0800" || areaCode4 === "0809") {
|
|
3325
|
+
return cleanValue.length === 10 && /^080[09]\d{6}$/.test(cleanValue);
|
|
3326
|
+
}
|
|
3324
3327
|
if (areaCode4 === "0836") {
|
|
3325
3328
|
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3326
3329
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -2906,6 +2906,8 @@ type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
2906
2906
|
* - 06: Tainan - 7 digits
|
|
2907
2907
|
* - 07: Kaohsiung - 7 digits
|
|
2908
2908
|
* - 08: Pingtung - 7 digits
|
|
2909
|
+
* - 0800: Toll-free - 6 digits
|
|
2910
|
+
* - 0809: Toll-free - 6 digits
|
|
2909
2911
|
* - 082: Kinmen - 6 digits
|
|
2910
2912
|
* - 0836: Matsu - 5 digits
|
|
2911
2913
|
* - 089: Taitung - 6 digits
|
package/dist/index.d.ts
CHANGED
|
@@ -2906,6 +2906,8 @@ type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ? ZodStri
|
|
|
2906
2906
|
* - 06: Tainan - 7 digits
|
|
2907
2907
|
* - 07: Kaohsiung - 7 digits
|
|
2908
2908
|
* - 08: Pingtung - 7 digits
|
|
2909
|
+
* - 0800: Toll-free - 6 digits
|
|
2910
|
+
* - 0809: Toll-free - 6 digits
|
|
2909
2911
|
* - 082: Kinmen - 6 digits
|
|
2910
2912
|
* - 0836: Matsu - 5 digits
|
|
2911
2913
|
* - 089: Taitung - 6 digits
|
package/dist/index.js
CHANGED
|
@@ -3243,6 +3243,9 @@ var validateTaiwanTel = (value) => {
|
|
|
3243
3243
|
return false;
|
|
3244
3244
|
}
|
|
3245
3245
|
const areaCode4 = cleanValue.substring(0, 4);
|
|
3246
|
+
if (areaCode4 === "0800" || areaCode4 === "0809") {
|
|
3247
|
+
return cleanValue.length === 10 && /^080[09]\d{6}$/.test(cleanValue);
|
|
3248
|
+
}
|
|
3246
3249
|
if (areaCode4 === "0836") {
|
|
3247
3250
|
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue);
|
|
3248
3251
|
}
|
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.13",
|
|
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",
|
|
@@ -75,6 +75,8 @@ export type TwTelSchema<IsRequired extends boolean> = IsRequired extends true ?
|
|
|
75
75
|
* - 06: Tainan - 7 digits
|
|
76
76
|
* - 07: Kaohsiung - 7 digits
|
|
77
77
|
* - 08: Pingtung - 7 digits
|
|
78
|
+
* - 0800: Toll-free - 6 digits
|
|
79
|
+
* - 0809: Toll-free - 6 digits
|
|
78
80
|
* - 082: Kinmen - 6 digits
|
|
79
81
|
* - 0836: Matsu - 5 digits
|
|
80
82
|
* - 089: Taitung - 6 digits
|
|
@@ -99,6 +101,7 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
99
101
|
// 06: Tainan - 7 digits
|
|
100
102
|
// 07: Kaohsiung - 7 digits
|
|
101
103
|
// 08: Pingtung - 7 digits
|
|
104
|
+
// 0800/0809: Toll-free - 6 digits
|
|
102
105
|
// 082: Kinmen - 6 digits
|
|
103
106
|
// 0836: Matsu - 5 digits
|
|
104
107
|
// 089: Taitung - 6 digits
|
|
@@ -113,6 +116,10 @@ const validateTaiwanTel = (value: string): boolean => {
|
|
|
113
116
|
|
|
114
117
|
// Check 4-digit area codes first
|
|
115
118
|
const areaCode4 = cleanValue.substring(0, 4)
|
|
119
|
+
if (areaCode4 === "0800" || areaCode4 === "0809") {
|
|
120
|
+
// Toll-free: 0800/0809 + 6 digits, total 10 digits
|
|
121
|
+
return cleanValue.length === 10 && /^080[09]\d{6}$/.test(cleanValue)
|
|
122
|
+
}
|
|
116
123
|
if (areaCode4 === "0836") {
|
|
117
124
|
// Matsu: 0836 + 5 digits, total 9 digits
|
|
118
125
|
return cleanValue.length === 9 && /^0836\d{5}$/.test(cleanValue)
|
package/tests/taiwan/tel.test.ts
CHANGED
|
@@ -39,6 +39,11 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
39
39
|
// 4-digit area codes
|
|
40
40
|
expect(schema.parse("082661234")).toBe("082661234") // 0826-61234 (9 digits, Wuqiu)
|
|
41
41
|
expect(schema.parse("083621234")).toBe("083621234") // 0836-21234 (9 digits, Matsu)
|
|
42
|
+
|
|
43
|
+
// Toll-free numbers
|
|
44
|
+
expect(schema.parse("0800123456")).toBe("0800123456") // 0800-123-456 (10 digits)
|
|
45
|
+
expect(schema.parse("0809123456")).toBe("0809123456") // 0809-123-456 (10 digits)
|
|
46
|
+
expect(schema.parse("0800-012-345")).toBe("0800-012-345") // with separators
|
|
42
47
|
})
|
|
43
48
|
|
|
44
49
|
it("should validate numbers with separators", () => {
|
|
@@ -246,6 +251,11 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
246
251
|
expect(validateTaiwanTel("082661234")).toBe(true) // Wuqiu
|
|
247
252
|
expect(validateTaiwanTel("083621234")).toBe(true) // Matsu
|
|
248
253
|
|
|
254
|
+
// Toll-free numbers
|
|
255
|
+
expect(validateTaiwanTel("0800123456")).toBe(true) // 0800
|
|
256
|
+
expect(validateTaiwanTel("0809123456")).toBe(true) // 0809
|
|
257
|
+
expect(validateTaiwanTel("0800-123-456")).toBe(true) // with separators
|
|
258
|
+
|
|
249
259
|
// Valid with separators
|
|
250
260
|
expect(validateTaiwanTel("02-2345-6789")).toBe(true)
|
|
251
261
|
expect(validateTaiwanTel("07 234 5678")).toBe(true)
|
|
@@ -264,6 +274,9 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
264
274
|
expect(validateTaiwanTel("071234567")).toBe(false) // Invalid first digit for 07
|
|
265
275
|
expect(validateTaiwanTel("037134567")).toBe(false) // Invalid first digit for 037
|
|
266
276
|
expect(validateTaiwanTel("081234567")).toBe(false) // Invalid first digit for 08
|
|
277
|
+
expect(validateTaiwanTel("080012345")).toBe(false) // 0800 too short (9 digits)
|
|
278
|
+
expect(validateTaiwanTel("08001234567")).toBe(false) // 0800 too long (11 digits)
|
|
279
|
+
expect(validateTaiwanTel("0801123456")).toBe(false) // 0801 not valid toll-free prefix
|
|
267
280
|
})
|
|
268
281
|
})
|
|
269
282
|
})
|
|
@@ -361,6 +374,8 @@ describe("Taiwan twTel(true) validator", () => {
|
|
|
361
374
|
{ code: "08", numbers: ["084234567"] }, // Pingtung (9 digits, first digit 4) - from utility test ✓
|
|
362
375
|
{ code: "082", numbers: ["082234567"] }, // Kinmen (9 digits, first digit 2) - from utility test ✓
|
|
363
376
|
{ code: "089", numbers: ["089234567"] }, // Taitung (9 digits, first digit 2) - from utility test ✓
|
|
377
|
+
{ code: "0800", numbers: ["0800123456"] }, // Toll-free (10 digits)
|
|
378
|
+
{ code: "0809", numbers: ["0809123456"] }, // Toll-free (10 digits)
|
|
364
379
|
{ code: "0826", numbers: ["082661234"] }, // Wuqiu (9 digits, first digit 6) - from utility test ✓
|
|
365
380
|
{ code: "0836", numbers: ["083621234"] }, // Matsu (9 digits, first digit 2) - from utility test ✓
|
|
366
381
|
]
|