@hy_ong/zod-kit 0.0.4 → 0.0.6

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.
Files changed (59) hide show
  1. package/.claude/settings.local.json +28 -0
  2. package/LICENSE +21 -0
  3. package/README.md +465 -97
  4. package/debug.js +21 -0
  5. package/debug.ts +16 -0
  6. package/dist/index.cjs +3127 -146
  7. package/dist/index.d.cts +3021 -25
  8. package/dist/index.d.ts +3021 -25
  9. package/dist/index.js +3081 -144
  10. package/eslint.config.mts +8 -0
  11. package/package.json +10 -9
  12. package/src/config.ts +1 -1
  13. package/src/i18n/locales/en.json +161 -25
  14. package/src/i18n/locales/zh-TW.json +165 -26
  15. package/src/index.ts +17 -7
  16. package/src/validators/common/boolean.ts +191 -0
  17. package/src/validators/common/date.ts +299 -0
  18. package/src/validators/common/datetime.ts +673 -0
  19. package/src/validators/common/email.ts +313 -0
  20. package/src/validators/common/file.ts +384 -0
  21. package/src/validators/common/id.ts +471 -0
  22. package/src/validators/common/number.ts +319 -0
  23. package/src/validators/common/password.ts +386 -0
  24. package/src/validators/common/text.ts +271 -0
  25. package/src/validators/common/time.ts +600 -0
  26. package/src/validators/common/url.ts +347 -0
  27. package/src/validators/taiwan/business-id.ts +262 -0
  28. package/src/validators/taiwan/fax.ts +327 -0
  29. package/src/validators/taiwan/mobile.ts +242 -0
  30. package/src/validators/taiwan/national-id.ts +425 -0
  31. package/src/validators/taiwan/postal-code.ts +1049 -0
  32. package/src/validators/taiwan/tel.ts +330 -0
  33. package/tests/common/boolean.test.ts +340 -92
  34. package/tests/common/date.test.ts +458 -0
  35. package/tests/common/datetime.test.ts +693 -0
  36. package/tests/common/email.test.ts +232 -60
  37. package/tests/common/file.test.ts +479 -0
  38. package/tests/common/id.test.ts +535 -0
  39. package/tests/common/number.test.ts +230 -60
  40. package/tests/common/password.test.ts +271 -44
  41. package/tests/common/text.test.ts +210 -13
  42. package/tests/common/time.test.ts +528 -0
  43. package/tests/common/url.test.ts +492 -67
  44. package/tests/taiwan/business-id.test.ts +240 -0
  45. package/tests/taiwan/fax.test.ts +463 -0
  46. package/tests/taiwan/mobile.test.ts +373 -0
  47. package/tests/taiwan/national-id.test.ts +435 -0
  48. package/tests/taiwan/postal-code.test.ts +705 -0
  49. package/tests/taiwan/tel.test.ts +467 -0
  50. package/eslint.config.mjs +0 -10
  51. package/src/common/boolean.ts +0 -36
  52. package/src/common/date.ts +0 -43
  53. package/src/common/email.ts +0 -44
  54. package/src/common/integer.ts +0 -46
  55. package/src/common/number.ts +0 -37
  56. package/src/common/password.ts +0 -33
  57. package/src/common/text.ts +0 -34
  58. package/src/common/url.ts +0 -37
  59. package/tests/common/integer.test.ts +0 -90
@@ -0,0 +1,463 @@
1
+ import { describe, it, expect, beforeEach } from "vitest"
2
+ import { fax, setLocale, validateTaiwanFax } from "../../src"
3
+
4
+ describe("Taiwan fax() validator", () => {
5
+ beforeEach(() => setLocale("en"))
6
+
7
+ describe("basic functionality", () => {
8
+ it("should validate correct Taiwan fax numbers", () => {
9
+ const schema = fax()
10
+
11
+ // Valid Taiwan fax numbers (same format as landline numbers)
12
+ // Taipei (02) - requires 10 digits total, the first digit after 02 must be 2,3,5-8
13
+ expect(schema.parse("0223456789")).toBe("0223456789") // 02-2345-6789 (10 digits)
14
+ expect(schema.parse("0232345678")).toBe("0232345678") // 02-3234-5678 (10 digits)
15
+
16
+ // Kaohsiung (07) - requires 9 digits total, the first digit after 07 must be 2-9
17
+ expect(schema.parse("072345678")).toBe("072345678") // 07-234-5678 (9 digits)
18
+ expect(schema.parse("073456789")).toBe("073456789") // 07-345-6789 (9 digits)
19
+
20
+ // Taichung (04) - requires 9 digits total
21
+ expect(schema.parse("041234567")).toBe("041234567") // 04-123-4567 (9 digits)
22
+ expect(schema.parse("043456789")).toBe("043456789") // 04-345-6789 (9 digits)
23
+
24
+ // Tainan (06) - requires 9 digits total
25
+ expect(schema.parse("061234567")).toBe("061234567") // 06-123-4567 (9 digits)
26
+ expect(schema.parse("063456789")).toBe("063456789") // 06-345-6789 (9 digits)
27
+
28
+ // Other areas
29
+ expect(schema.parse("031234567")).toBe("031234567") // 03-123-4567 (9 digits)
30
+ expect(schema.parse("051234567")).toBe("051234567") // 05-123-4567 (9 digits)
31
+ expect(schema.parse("084234567")).toBe("084234567") // 08-423-4567 (9 digits, 08 area code with 4)
32
+ expect(schema.parse("087234567")).toBe("087234567") // 08-723-4567 (9 digits, 08 area code with 7)
33
+
34
+ // 3-digit area codes
35
+ expect(schema.parse("082234567")).toBe("082234567") // 082-234567 (9 digits, Kinmen)
36
+ expect(schema.parse("089234567")).toBe("089234567") // 089-234567 (9 digits, Taitung)
37
+
38
+ // 4-digit area codes
39
+ expect(schema.parse("082661234")).toBe("082661234") // 0826-61234 (9 digits, Wuqiu)
40
+ expect(schema.parse("083621234")).toBe("083621234") // 0836-21234 (9 digits, Matsu)
41
+ })
42
+
43
+ it("should validate numbers with separators", () => {
44
+ const schema = fax()
45
+
46
+ // Numbers with dashes
47
+ expect(schema.parse("02-2345-6789")).toBe("02-2345-6789")
48
+ expect(schema.parse("07-234-5678")).toBe("07-234-5678")
49
+ expect(schema.parse("082-234567")).toBe("082-234567")
50
+
51
+ // Numbers with spaces
52
+ expect(schema.parse("02 2345 6789")).toBe("02 2345 6789")
53
+ expect(schema.parse("07 234 5678")).toBe("07 234 5678")
54
+ expect(schema.parse("082 234567")).toBe("082 234567")
55
+
56
+ // Mixed separators
57
+ expect(schema.parse("02-2345 6789")).toBe("02-2345 6789")
58
+ expect(schema.parse("07 234-5678")).toBe("07 234-5678")
59
+ })
60
+
61
+ it("should reject invalid Taiwan fax numbers", () => {
62
+ const schema = fax()
63
+
64
+ // Invalid formats
65
+ expect(() => schema.parse("123456789")).toThrow("Invalid Taiwan fax format") // Missing leading 0
66
+ expect(() => schema.parse("01234567890")).toThrow("Invalid Taiwan fax format") // Too long
67
+ expect(() => schema.parse("0123456")).toThrow("Invalid Taiwan fax format") // Too short
68
+ expect(() => schema.parse("1012345678")).toThrow("Invalid Taiwan fax format") // Wrong prefix (10)
69
+ expect(() => schema.parse("")).toThrow("Required")
70
+ expect(() => schema.parse("abcdefghij")).toThrow("Invalid Taiwan fax format")
71
+
72
+ // Invalid area codes
73
+ expect(() => schema.parse("0012345678")).toThrow("Invalid Taiwan fax format") // 00 not valid
74
+ expect(() => schema.parse("0112345678")).toThrow("Invalid Taiwan fax format") // 01 not valid
75
+ expect(() => schema.parse("0912345678")).toThrow("Invalid Taiwan fax format") // 09 is mobile, not fax
76
+
77
+ // Invalid 3-digit codes
78
+ expect(() => schema.parse("081123456")).toThrow("Invalid Taiwan fax format") // 081 not valid
79
+ expect(() => schema.parse("083123456")).toThrow("Invalid Taiwan fax format") // 083 not valid
80
+
81
+ // Wrong length for valid area codes
82
+ expect(() => schema.parse("02234567899")).toThrow("Invalid Taiwan fax format") // Too long for 02
83
+ expect(() => schema.parse("82123456")).toThrow("Invalid Taiwan fax format") // Missing leading 0
84
+ })
85
+
86
+ it("should handle whitespace trimming", () => {
87
+ const schema = fax()
88
+
89
+ expect(schema.parse(" 0223456789 ")).toBe("0223456789")
90
+ expect(schema.parse("\t072345678\n")).toBe("072345678")
91
+ })
92
+ })
93
+
94
+ describe("whitelist functionality", () => {
95
+ it("should accept any string in whitelist regardless of format", () => {
96
+ const schema = fax({
97
+ whitelist: ["custom-fax", "emergency-fax", "0912345678"],
98
+ })
99
+
100
+ // Allowlist entries should be accepted even if they don't match Taiwan fax formats
101
+ expect(schema.parse("custom-fax")).toBe("custom-fax")
102
+ expect(schema.parse("emergency-fax")).toBe("emergency-fax")
103
+ expect(schema.parse("0912345678")).toBe("0912345678") // Mobile number but in allowlist
104
+
105
+ // Valid fax numbers not in the allowlist should be rejected
106
+ expect(() => schema.parse("0223456789")).toThrow("Not in allowed fax list")
107
+ expect(() => schema.parse("0711111111")).toThrow("Not in allowed fax list")
108
+ })
109
+
110
+ it("should reject values not in whitelist when whitelist is provided", () => {
111
+ const schema = fax({
112
+ whitelist: ["allowed-value", "0223456789"],
113
+ })
114
+
115
+ expect(() => schema.parse("0312345678")).toThrow("Not in allowed fax list")
116
+ expect(() => schema.parse("invalid-value")).toThrow("Not in allowed fax list")
117
+ })
118
+
119
+ it("should work with empty whitelist", () => {
120
+ const schema = fax({
121
+ whitelist: [],
122
+ })
123
+
124
+ // With an empty allowlist, should still validate fax formats
125
+ expect(schema.parse("0223456789")).toBe("0223456789")
126
+ expect(() => schema.parse("0912345678")).toThrow("Invalid Taiwan fax format")
127
+ })
128
+
129
+ it("should prioritize whitelist over format validation", () => {
130
+ const schema = fax({
131
+ required: false,
132
+ whitelist: ["not-a-fax", "123", ""],
133
+ })
134
+
135
+ // These should be accepted despite being invalid fax formats
136
+ expect(schema.parse("not-a-fax")).toBe("not-a-fax")
137
+ expect(schema.parse("123")).toBe("123")
138
+ expect(schema.parse("")).toBe("")
139
+ })
140
+ })
141
+
142
+ describe("required/optional behavior", () => {
143
+ it("should handle required=true (default)", () => {
144
+ const schema = fax()
145
+
146
+ expect(() => schema.parse("")).toThrow("Required")
147
+ expect(() => schema.parse(null)).toThrow()
148
+ expect(() => schema.parse(undefined)).toThrow()
149
+ })
150
+
151
+ it("should handle required=false", () => {
152
+ const schema = fax({ required: false })
153
+
154
+ expect(schema.parse("")).toBe(null)
155
+ expect(schema.parse(null)).toBe(null)
156
+ expect(schema.parse(undefined)).toBe(null)
157
+ expect(schema.parse("0223456789")).toBe("0223456789")
158
+ })
159
+
160
+ it("should use default values", () => {
161
+ const requiredSchema = fax({ defaultValue: "0223456789" })
162
+ const optionalSchema = fax({ required: false, defaultValue: "0223456789" })
163
+
164
+ expect(requiredSchema.parse("")).toBe("0223456789")
165
+ expect(optionalSchema.parse("")).toBe("0223456789")
166
+ })
167
+
168
+ it("should handle whitelist with optional fields", () => {
169
+ const schema = fax({
170
+ required: false,
171
+ whitelist: ["custom-value", "0223456789"],
172
+ })
173
+
174
+ expect(schema.parse("")).toBe(null)
175
+ expect(schema.parse("custom-value")).toBe("custom-value")
176
+ expect(schema.parse("0223456789")).toBe("0223456789")
177
+ expect(() => schema.parse("0312345678")).toThrow("Not in allowed fax list")
178
+ })
179
+ })
180
+
181
+ describe("transform function", () => {
182
+ it("should apply custom transform", () => {
183
+ const schema = fax({
184
+ transform: (val) => val.replace(/[-\s]/g, ""),
185
+ })
186
+
187
+ expect(schema.parse("02-234-56789")).toBe("0223456789")
188
+ expect(schema.parse("07 234 5678")).toBe("072345678")
189
+ })
190
+
191
+ it("should apply transform before validation", () => {
192
+ const schema = fax({
193
+ transform: (val) => val.replace(/\s+/g, ""),
194
+ })
195
+
196
+ expect(schema.parse(" 02 234 567 89 ")).toBe("0223456789")
197
+ expect(() => schema.parse(" 09 123 4567 8 ")).toThrow("Invalid Taiwan fax format")
198
+ })
199
+
200
+ it("should work with whitelist after transform", () => {
201
+ const schema = fax({
202
+ transform: (val) => val.replace(/[-\s]/g, ""),
203
+ whitelist: ["0223456789", "customvalue"],
204
+ })
205
+
206
+ expect(schema.parse("customvalue")).toBe("customvalue")
207
+ expect(() => schema.parse("03-123-4567")).toThrow("Not in allowed fax list")
208
+ })
209
+ })
210
+
211
+ describe("input preprocessing", () => {
212
+ it("should handle string conversion", () => {
213
+ const schema = fax()
214
+
215
+ // Test string conversion of numbers
216
+ expect(() => schema.parse(212345678)).toThrow("Invalid Taiwan fax format") // Invalid because missing leading 0
217
+ })
218
+
219
+ it("should trim whitespace", () => {
220
+ const schema = fax()
221
+
222
+ expect(schema.parse(" 0223456789 ")).toBe("0223456789")
223
+ expect(schema.parse("\t072345678\n")).toBe("072345678")
224
+ })
225
+ })
226
+
227
+ describe("utility function", () => {
228
+ describe("validateTaiwanFax", () => {
229
+ it("should correctly validate Taiwan fax numbers", () => {
230
+ // Valid numbers (using exact working patterns from tel utility test)
231
+ expect(validateTaiwanFax("0223456789")).toBe(true) // Taipei
232
+ expect(validateTaiwanFax("072345678")).toBe(true) // Kaohsiung
233
+ expect(validateTaiwanFax("041234567")).toBe(true) // Taichung
234
+ expect(validateTaiwanFax("037234567")).toBe(true) // Miaoli
235
+ expect(validateTaiwanFax("0492345678")).toBe(true) // Nantou
236
+ expect(validateTaiwanFax("084234567")).toBe(true) // Pingtung
237
+ expect(validateTaiwanFax("082234567")).toBe(true) // Kinmen
238
+ expect(validateTaiwanFax("089234567")).toBe(true) // Taitung
239
+ expect(validateTaiwanFax("082661234")).toBe(true) // Wuqiu
240
+ expect(validateTaiwanFax("083621234")).toBe(true) // Matsu
241
+
242
+ // Valid with separators
243
+ expect(validateTaiwanFax("02-2345-6789")).toBe(true)
244
+ expect(validateTaiwanFax("07 234 5678")).toBe(true)
245
+ expect(validateTaiwanFax("082-234567")).toBe(true)
246
+
247
+ // Invalid numbers
248
+ expect(validateTaiwanFax("0912345678")).toBe(false) // Mobile prefix
249
+ expect(validateTaiwanFax("1212345678")).toBe(false) // Wrong prefix
250
+ expect(validateTaiwanFax("02123456")).toBe(false) // Too short
251
+ expect(validateTaiwanFax("022345678990")).toBe(false) // Too long
252
+ expect(validateTaiwanFax("212345678")).toBe(false) // Missing leading 0
253
+ expect(validateTaiwanFax("")).toBe(false) // Empty
254
+ expect(validateTaiwanFax("abcdefghij")).toBe(false) // Non-numeric
255
+ expect(validateTaiwanFax("081123456")).toBe(false) // Invalid 3-digit area code
256
+ })
257
+ })
258
+ })
259
+
260
+ describe("i18n support", () => {
261
+ it("should use English messages by default", () => {
262
+ setLocale("en")
263
+ const schema = fax()
264
+
265
+ expect(() => schema.parse("")).toThrow("Required")
266
+ expect(() => schema.parse("0912345678")).toThrow("Invalid Taiwan fax format")
267
+ })
268
+
269
+ it("should use Chinese messages when locale is zh-TW", () => {
270
+ setLocale("zh-TW")
271
+ const schema = fax()
272
+
273
+ expect(() => schema.parse("")).toThrow("必填")
274
+ expect(() => schema.parse("0912345678")).toThrow("無效的傳真號碼格式")
275
+ })
276
+
277
+ it("should support whitelist error messages", () => {
278
+ setLocale("en")
279
+ const schema = fax({
280
+ whitelist: ["0223456789"],
281
+ })
282
+
283
+ expect(() => schema.parse("0312345678")).toThrow("Not in allowed fax list")
284
+
285
+ setLocale("zh-TW")
286
+ expect(() => schema.parse("0312345678")).toThrow("不在允許的傳真號碼清單中")
287
+ })
288
+
289
+ it("should support custom i18n messages", () => {
290
+ const schema = fax({
291
+ i18n: {
292
+ en: {
293
+ required: "Fax number is required",
294
+ invalid: "Fax number format is invalid",
295
+ notInWhitelist: "Fax number not allowed",
296
+ },
297
+ "zh-TW": {
298
+ required: "請輸入傳真號碼",
299
+ invalid: "傳真號碼格式錯誤",
300
+ notInWhitelist: "傳真號碼不被允許",
301
+ },
302
+ },
303
+ })
304
+
305
+ setLocale("en")
306
+ expect(() => schema.parse("")).toThrow("Fax number is required")
307
+ expect(() => schema.parse("0912345678")).toThrow("Fax number format is invalid")
308
+
309
+ setLocale("zh-TW")
310
+ expect(() => schema.parse("")).toThrow("請輸入傳真號碼")
311
+ expect(() => schema.parse("0912345678")).toThrow("傳真號碼格式錯誤")
312
+ })
313
+
314
+ it("should support custom whitelist messages", () => {
315
+ const schema = fax({
316
+ whitelist: ["0223456789"],
317
+ i18n: {
318
+ en: {
319
+ notInWhitelist: "This fax number is not allowed",
320
+ },
321
+ "zh-TW": {
322
+ notInWhitelist: "此傳真號碼不被允許",
323
+ },
324
+ },
325
+ })
326
+
327
+ setLocale("en")
328
+ expect(() => schema.parse("0312345678")).toThrow("This fax number is not allowed")
329
+
330
+ setLocale("zh-TW")
331
+ expect(() => schema.parse("0312345678")).toThrow("此傳真號碼不被允許")
332
+ })
333
+ })
334
+
335
+ describe("real world Taiwan fax numbers", () => {
336
+ it("should validate all major area codes", () => {
337
+ const schema = fax()
338
+
339
+ // Test Taiwan fax area codes using exact working numbers from tel utility test
340
+ const validAreaCodes = [
341
+ { code: "02", numbers: ["0223456789"] }, // Taipei (10 digits, first digit 2) - from utility test ✓
342
+ { code: "04", numbers: ["041234567"] }, // Taichung (9 digits) - from utility test ✓
343
+ { code: "037", numbers: ["037234567"] }, // Miaoli (9 digits, first digit 2) - from utility test ✓
344
+ { code: "049", numbers: ["0492345678"] }, // Nantou (10 digits, first digit 2) - from utility test ✓
345
+ { code: "07", numbers: ["072345678"] }, // Kaohsiung (9 digits, first digit 2) - from utility test ✓
346
+ { code: "08", numbers: ["084234567"] }, // Pingtung (9 digits, first digit 4) - from utility test ✓
347
+ { code: "082", numbers: ["082234567"] }, // Kinmen (9 digits, first digit 2) - from utility test ✓
348
+ { code: "089", numbers: ["089234567"] }, // Taitung (9 digits, first digit 2) - from utility test ✓
349
+ { code: "0826", numbers: ["082661234"] }, // Wuqiu (9 digits, first digit 6) - from utility test ✓
350
+ { code: "0836", numbers: ["083621234"] }, // Matsu (9 digits, first digit 2) - from utility test ✓
351
+ ]
352
+
353
+ validAreaCodes.forEach(({ numbers }) => {
354
+ numbers.forEach((number) => {
355
+ expect(schema.parse(number)).toBe(number)
356
+ })
357
+ })
358
+ })
359
+
360
+ it("should reject mobile phone prefixes", () => {
361
+ const schema = fax()
362
+
363
+ // Test invalid mobile prefixes (090-099)
364
+ const mobilePrefixes = ["090", "091", "092", "093", "094", "095", "096", "097", "098", "099"]
365
+
366
+ mobilePrefixes.forEach((prefix) => {
367
+ const phoneNumber = prefix + "1234567"
368
+ expect(() => schema.parse(phoneNumber)).toThrow("Invalid Taiwan fax format")
369
+ })
370
+ })
371
+
372
+ it("should validate realistic fax number patterns", () => {
373
+ const schema = fax()
374
+
375
+ const realFaxNumbers = [
376
+ "0223456789", // Taipei 10-digit (valid first digit 2) - from utility test ✓
377
+ "072345678", // Kaohsiung 9-digit (valid first digit 2) - from utility test ✓
378
+ "041234567", // Taichung 9-digit - from utility test ✓
379
+ "037234567", // Miaoli 9-digit (valid first digit 2) - from utility test ✓
380
+ "0492345678", // Nantou 10-digit (valid first digit 2) - from utility test ✓
381
+ "084234567", // Pingtung 9-digit (valid first digit 4) - from utility test ✓
382
+ "082234567", // Kinmen 9-digit (valid first digit 2) - from utility test ✓
383
+ "089234567", // Taitung 9-digit (valid first digit 2) - from utility test ✓
384
+ "082661234", // Wuqiu 9-digit (valid first digit 6) - from utility test ✓
385
+ "083621234", // Matsu (valid) - from utility test ✓
386
+ ]
387
+
388
+ realFaxNumbers.forEach((faxNum) => {
389
+ expect(schema.parse(faxNum)).toBe(faxNum)
390
+ })
391
+ })
392
+ })
393
+
394
+ describe("edge cases", () => {
395
+ it("should handle various input types", () => {
396
+ const schema = fax()
397
+
398
+ // Test different input types that should be converted to string
399
+ expect(schema.parse("0223456789")).toBe("0223456789")
400
+ })
401
+
402
+ it("should handle empty and whitespace inputs", () => {
403
+ const schema = fax()
404
+ const optionalSchema = fax({ required: false })
405
+
406
+ expect(() => schema.parse("")).toThrow("Required")
407
+ expect(() => schema.parse(" ")).toThrow("Required")
408
+ expect(() => schema.parse("\t\n")).toThrow("Required")
409
+
410
+ expect(optionalSchema.parse("")).toBe(null)
411
+ expect(optionalSchema.parse(" ")).toBe(null)
412
+ expect(optionalSchema.parse("\t\n")).toBe(null)
413
+ })
414
+
415
+ it("should preserve valid format after transformation", () => {
416
+ const schema = fax({
417
+ transform: (val) => val.replace(/[^0-9]/g, ""),
418
+ })
419
+
420
+ expect(schema.parse("02-234-56789")).toBe("0223456789")
421
+ expect(schema.parse("07 234 5678")).toBe("072345678")
422
+ // Test with letters that should be filtered out, leaving a valid number
423
+ expect(schema.parse("02abc234def56789")).toBe("0223456789")
424
+ })
425
+
426
+ it("should work with complex whitelist scenarios", () => {
427
+ const schema = fax({
428
+ whitelist: ["0223456789", "emergency", "custom-fax-123", ""],
429
+ required: false,
430
+ })
431
+
432
+ // Allowlist scenarios
433
+ expect(schema.parse("0223456789")).toBe("0223456789")
434
+ expect(schema.parse("emergency")).toBe("emergency")
435
+ expect(schema.parse("custom-fax-123")).toBe("custom-fax-123")
436
+ expect(schema.parse("")).toBe("")
437
+
438
+ // Not in the allowlist
439
+ expect(() => schema.parse("0312345678")).toThrow("Not in allowed fax list")
440
+ expect(() => schema.parse("other-value")).toThrow("Not in allowed fax list")
441
+ })
442
+
443
+ it("should handle boundary cases for area codes", () => {
444
+ const schema = fax()
445
+
446
+ // Test minimum and maximum valid lengths for different area codes
447
+ // 2-digit area codes: 9-10 digits total
448
+ expect(schema.parse("0223456789")).toBe("0223456789") // 10 digits (02 area requires 10)
449
+ expect(() => schema.parse("02123456")).toThrow("Invalid Taiwan fax format") // 8 digits (too short)
450
+ expect(() => schema.parse("022345678990")).toThrow("Invalid Taiwan fax format") // 12 digits (too long)
451
+
452
+ // 3-digit area codes: 9 digits total
453
+ expect(schema.parse("082234567")).toBe("082234567") // 9 digits (082 area, first digit 2)
454
+ expect(() => schema.parse("08212345")).toThrow("Invalid Taiwan fax format") // 8 digits (too short)
455
+ expect(() => schema.parse("0821234567")).toThrow("Invalid Taiwan fax format") // 10 digits (too long)
456
+
457
+ // 4-digit area codes: 9 digits total
458
+ expect(schema.parse("082661234")).toBe("082661234") // 9 digits
459
+ expect(() => schema.parse("08261234")).toThrow("Invalid Taiwan fax format") // 8 digits (too short)
460
+ expect(() => schema.parse("0826612346")).toThrow("Invalid Taiwan fax format") // 10 digits (too long)
461
+ })
462
+ })
463
+ })