@hy_ong/zod-kit 0.1.1 → 0.1.3
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 -21
- package/dist/index.d.cts +24 -11
- package/dist/index.d.ts +24 -11
- package/dist/index.js +40 -21
- package/package.json +1 -1
- package/src/validators/common/date.ts +26 -16
- package/src/validators/common/datetime.ts +46 -28
- package/src/validators/common/email.ts +57 -15
- package/src/validators/common/id.ts +139 -58
- package/src/validators/common/number.ts +80 -43
- package/src/validators/common/password.ts +30 -18
- package/src/validators/common/text.ts +48 -14
- package/src/validators/common/time.ts +34 -22
- package/src/validators/common/url.ts +40 -23
- package/src/validators/taiwan/business-id.ts +19 -19
- package/src/validators/taiwan/fax.ts +29 -28
- package/src/validators/taiwan/mobile.ts +29 -28
- package/src/validators/taiwan/national-id.ts +27 -27
- package/src/validators/taiwan/postal-code.ts +51 -45
- package/src/validators/taiwan/tel.ts +29 -28
- package/tests/common/id.test.ts +62 -4
- package/tests/taiwan/business-id.test.ts +23 -23
- package/tests/taiwan/fax.test.ts +34 -34
- package/tests/taiwan/mobile.test.ts +33 -33
- package/tests/taiwan/national-id.test.ts +32 -32
- package/tests/taiwan/postal-code.test.ts +62 -62
- package/tests/taiwan/tel.test.ts +34 -34
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach } from "vitest"
|
|
2
|
-
import {
|
|
2
|
+
import { twBusinessId, setLocale, validateTaiwanBusinessId } from "../../src"
|
|
3
3
|
|
|
4
|
-
describe("Taiwan
|
|
4
|
+
describe("Taiwan twBusinessId(true) validator", () => {
|
|
5
5
|
beforeEach(() => setLocale("en"))
|
|
6
6
|
|
|
7
7
|
describe("basic functionality", () => {
|
|
8
8
|
it("should validate correct Taiwan business IDs", () => {
|
|
9
|
-
const schema =
|
|
9
|
+
const schema = twBusinessId(true)
|
|
10
10
|
|
|
11
11
|
// Valid Taiwan business IDs (統一編號) - using calculation based on new/old rules
|
|
12
12
|
expect(schema.parse("22550077")).toBe("22550077") // Sum = 50, 50 % 5 = 0 (new rule)
|
|
@@ -15,7 +15,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
it("should reject invalid Taiwan business IDs", () => {
|
|
18
|
-
const schema =
|
|
18
|
+
const schema = twBusinessId(true)
|
|
19
19
|
|
|
20
20
|
// Invalid checksums
|
|
21
21
|
expect(() => schema.parse("12345672")).toThrow("Invalid Taiwan Business ID")
|
|
@@ -24,7 +24,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
it("should reject non-numeric inputs", () => {
|
|
27
|
-
const schema =
|
|
27
|
+
const schema = twBusinessId(true)
|
|
28
28
|
|
|
29
29
|
expect(() => schema.parse("1234567A")).toThrow("Invalid Taiwan Business ID")
|
|
30
30
|
expect(() => schema.parse("abcdefgh")).toThrow("Invalid Taiwan Business ID")
|
|
@@ -32,7 +32,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
it("should reject wrong length inputs", () => {
|
|
35
|
-
const schema =
|
|
35
|
+
const schema = twBusinessId(true)
|
|
36
36
|
|
|
37
37
|
expect(() => schema.parse("1234567")).toThrow("Invalid Taiwan Business ID")
|
|
38
38
|
expect(() => schema.parse("123456789")).toThrow("Invalid Taiwan Business ID")
|
|
@@ -43,7 +43,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
43
43
|
|
|
44
44
|
describe("special case validation (7th digit = 7)", () => {
|
|
45
45
|
it("should handle special case where 7th digit is 7", () => {
|
|
46
|
-
const schema =
|
|
46
|
+
const schema = twBusinessId(true)
|
|
47
47
|
|
|
48
48
|
// Valid number with 7th digit = 7 for testing special case
|
|
49
49
|
expect(schema.parse("12345670")).toBe("12345670") // Should be valid with special case
|
|
@@ -75,7 +75,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
75
75
|
|
|
76
76
|
describe("required/optional behavior", () => {
|
|
77
77
|
it("should handle required=true (default)", () => {
|
|
78
|
-
const schema =
|
|
78
|
+
const schema = twBusinessId(true)
|
|
79
79
|
|
|
80
80
|
expect(() => schema.parse("")).toThrow("Required")
|
|
81
81
|
expect(() => schema.parse(null)).toThrow()
|
|
@@ -83,7 +83,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
it("should handle required=false", () => {
|
|
86
|
-
const schema =
|
|
86
|
+
const schema = twBusinessId(false)
|
|
87
87
|
|
|
88
88
|
expect(schema.parse("")).toBe(null)
|
|
89
89
|
expect(schema.parse(null)).toBe(null)
|
|
@@ -92,8 +92,8 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
92
92
|
})
|
|
93
93
|
|
|
94
94
|
it("should use default values", () => {
|
|
95
|
-
const requiredSchema =
|
|
96
|
-
const optionalSchema =
|
|
95
|
+
const requiredSchema = twBusinessId(true, { defaultValue: "12345675" })
|
|
96
|
+
const optionalSchema = twBusinessId(false, { defaultValue: "12345675" })
|
|
97
97
|
|
|
98
98
|
expect(requiredSchema.parse("")).toBe("12345675")
|
|
99
99
|
expect(optionalSchema.parse("")).toBe("12345675")
|
|
@@ -102,7 +102,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
102
102
|
|
|
103
103
|
describe("transform function", () => {
|
|
104
104
|
it("should apply custom transform", () => {
|
|
105
|
-
const schema =
|
|
105
|
+
const schema = twBusinessId(true, {
|
|
106
106
|
transform: (val) => val.replace(/[-\s]/g, ""),
|
|
107
107
|
})
|
|
108
108
|
|
|
@@ -112,7 +112,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
112
112
|
})
|
|
113
113
|
|
|
114
114
|
it("should apply transform before validation", () => {
|
|
115
|
-
const schema =
|
|
115
|
+
const schema = twBusinessId(true, {
|
|
116
116
|
transform: (val) => val.replace(/\s+/g, ""),
|
|
117
117
|
})
|
|
118
118
|
|
|
@@ -123,14 +123,14 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
123
123
|
|
|
124
124
|
describe("input preprocessing", () => {
|
|
125
125
|
it("should handle string conversion", () => {
|
|
126
|
-
const schema =
|
|
126
|
+
const schema = twBusinessId(true)
|
|
127
127
|
|
|
128
128
|
expect(schema.parse(12345675)).toBe("12345675")
|
|
129
129
|
expect(() => schema.parse(12345672)).toThrow("Invalid Taiwan Business ID")
|
|
130
130
|
})
|
|
131
131
|
|
|
132
132
|
it("should trim whitespace", () => {
|
|
133
|
-
const schema =
|
|
133
|
+
const schema = twBusinessId(true)
|
|
134
134
|
|
|
135
135
|
expect(schema.parse(" 12345675 ")).toBe("12345675")
|
|
136
136
|
expect(schema.parse("\t12345675\n")).toBe("12345675")
|
|
@@ -140,7 +140,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
140
140
|
describe("i18n support", () => {
|
|
141
141
|
it("should use English messages by default", () => {
|
|
142
142
|
setLocale("en")
|
|
143
|
-
const schema =
|
|
143
|
+
const schema = twBusinessId(true)
|
|
144
144
|
|
|
145
145
|
expect(() => schema.parse("")).toThrow("Required")
|
|
146
146
|
expect(() => schema.parse("1234567")).toThrow("Invalid Taiwan Business ID")
|
|
@@ -149,7 +149,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
149
149
|
|
|
150
150
|
it("should use Chinese messages when locale is zh-TW", () => {
|
|
151
151
|
setLocale("zh-TW")
|
|
152
|
-
const schema =
|
|
152
|
+
const schema = twBusinessId(true)
|
|
153
153
|
|
|
154
154
|
expect(() => schema.parse("")).toThrow("必填")
|
|
155
155
|
expect(() => schema.parse("1234567")).toThrow("無效的統一編號")
|
|
@@ -157,7 +157,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
157
157
|
})
|
|
158
158
|
|
|
159
159
|
it("should support custom i18n messages", () => {
|
|
160
|
-
const schema =
|
|
160
|
+
const schema = twBusinessId(true, {
|
|
161
161
|
i18n: {
|
|
162
162
|
en: {
|
|
163
163
|
required: "Business ID is required",
|
|
@@ -182,7 +182,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
182
182
|
|
|
183
183
|
describe("real world Taiwan business IDs", () => {
|
|
184
184
|
it("should validate known real business IDs", () => {
|
|
185
|
-
const schema =
|
|
185
|
+
const schema = twBusinessId(true)
|
|
186
186
|
|
|
187
187
|
// These are example valid Taiwan business IDs for testing
|
|
188
188
|
const validIds = [
|
|
@@ -198,7 +198,7 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
198
198
|
})
|
|
199
199
|
|
|
200
200
|
it("should reject common invalid patterns", () => {
|
|
201
|
-
const schema =
|
|
201
|
+
const schema = twBusinessId(true)
|
|
202
202
|
|
|
203
203
|
const invalidIds = [
|
|
204
204
|
"00000001", // All zeros with bad checksum
|
|
@@ -218,15 +218,15 @@ describe("Taiwan businessId(true) validator", () => {
|
|
|
218
218
|
|
|
219
219
|
describe("edge cases", () => {
|
|
220
220
|
it("should handle leading zeros", () => {
|
|
221
|
-
const schema =
|
|
221
|
+
const schema = twBusinessId(true)
|
|
222
222
|
|
|
223
223
|
expect(schema.parse("04595257")).toBe("04595257")
|
|
224
224
|
expect(() => schema.parse("00123456")).toThrow("Invalid Taiwan Business ID")
|
|
225
225
|
})
|
|
226
226
|
|
|
227
227
|
it("should handle empty and whitespace inputs", () => {
|
|
228
|
-
const schema =
|
|
229
|
-
const optionalSchema =
|
|
228
|
+
const schema = twBusinessId(true)
|
|
229
|
+
const optionalSchema = twBusinessId(false)
|
|
230
230
|
|
|
231
231
|
expect(() => schema.parse("")).toThrow("Required")
|
|
232
232
|
expect(() => schema.parse(" ")).toThrow("Required")
|
package/tests/taiwan/fax.test.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach } from "vitest"
|
|
2
|
-
import {
|
|
2
|
+
import { twFax, setLocale, validateTaiwanFax } from "../../src"
|
|
3
3
|
|
|
4
|
-
describe("Taiwan
|
|
4
|
+
describe("Taiwan twFax(true) validator", () => {
|
|
5
5
|
beforeEach(() => setLocale("en"))
|
|
6
6
|
|
|
7
7
|
describe("basic functionality", () => {
|
|
8
8
|
it("should validate correct Taiwan fax numbers", () => {
|
|
9
|
-
const schema =
|
|
9
|
+
const schema = twFax(true)
|
|
10
10
|
|
|
11
11
|
// Valid Taiwan fax numbers (same format as landline numbers)
|
|
12
12
|
// Taipei (02) - requires 10 digits total, the first digit after 02 must be 2,3,5-8
|
|
@@ -41,7 +41,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
41
41
|
})
|
|
42
42
|
|
|
43
43
|
it("should validate numbers with separators", () => {
|
|
44
|
-
const schema =
|
|
44
|
+
const schema = twFax(true)
|
|
45
45
|
|
|
46
46
|
// Numbers with dashes
|
|
47
47
|
expect(schema.parse("02-2345-6789")).toBe("02-2345-6789")
|
|
@@ -59,7 +59,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
it("should reject invalid Taiwan fax numbers", () => {
|
|
62
|
-
const schema =
|
|
62
|
+
const schema = twFax(true)
|
|
63
63
|
|
|
64
64
|
// Invalid formats
|
|
65
65
|
expect(() => schema.parse("123456789")).toThrow("Invalid Taiwan fax format") // Missing leading 0
|
|
@@ -84,7 +84,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
it("should handle whitespace trimming", () => {
|
|
87
|
-
const schema =
|
|
87
|
+
const schema = twFax(true)
|
|
88
88
|
|
|
89
89
|
expect(schema.parse(" 0223456789 ")).toBe("0223456789")
|
|
90
90
|
expect(schema.parse("\t072345678\n")).toBe("072345678")
|
|
@@ -93,7 +93,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
93
93
|
|
|
94
94
|
describe("whitelist functionality", () => {
|
|
95
95
|
it("should accept any string in whitelist regardless of format", () => {
|
|
96
|
-
const schema =
|
|
96
|
+
const schema = twFax(true, {
|
|
97
97
|
whitelist: ["custom-fax", "emergency-fax", "0912345678"],
|
|
98
98
|
})
|
|
99
99
|
|
|
@@ -108,7 +108,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
it("should reject values not in whitelist when whitelist is provided", () => {
|
|
111
|
-
const schema =
|
|
111
|
+
const schema = twFax(true, {
|
|
112
112
|
whitelist: ["allowed-value", "0223456789"],
|
|
113
113
|
})
|
|
114
114
|
|
|
@@ -117,7 +117,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
117
117
|
})
|
|
118
118
|
|
|
119
119
|
it("should work with empty whitelist", () => {
|
|
120
|
-
const schema =
|
|
120
|
+
const schema = twFax(true, {
|
|
121
121
|
whitelist: [],
|
|
122
122
|
})
|
|
123
123
|
|
|
@@ -127,7 +127,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
127
127
|
})
|
|
128
128
|
|
|
129
129
|
it("should prioritize whitelist over format validation", () => {
|
|
130
|
-
const schema =
|
|
130
|
+
const schema = twFax(false, { whitelist: ["not-a-fax", "123", ""] })
|
|
131
131
|
|
|
132
132
|
// These should be accepted despite being invalid fax formats
|
|
133
133
|
expect(schema.parse("not-a-fax")).toBe("not-a-fax")
|
|
@@ -138,7 +138,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
138
138
|
|
|
139
139
|
describe("required/optional behavior", () => {
|
|
140
140
|
it("should handle required=true (default)", () => {
|
|
141
|
-
const schema =
|
|
141
|
+
const schema = twFax(true)
|
|
142
142
|
|
|
143
143
|
expect(() => schema.parse("")).toThrow("Required")
|
|
144
144
|
expect(() => schema.parse(null)).toThrow()
|
|
@@ -146,7 +146,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
146
146
|
})
|
|
147
147
|
|
|
148
148
|
it("should handle required=false", () => {
|
|
149
|
-
const schema =
|
|
149
|
+
const schema = twFax(false)
|
|
150
150
|
|
|
151
151
|
expect(schema.parse("")).toBe(null)
|
|
152
152
|
expect(schema.parse(null)).toBe(null)
|
|
@@ -155,15 +155,15 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
155
155
|
})
|
|
156
156
|
|
|
157
157
|
it("should use default values", () => {
|
|
158
|
-
const requiredSchema =
|
|
159
|
-
const optionalSchema =
|
|
158
|
+
const requiredSchema = twFax(true, { defaultValue: "0223456789" })
|
|
159
|
+
const optionalSchema = twFax(false, { defaultValue: "0223456789" })
|
|
160
160
|
|
|
161
161
|
expect(requiredSchema.parse("")).toBe("0223456789")
|
|
162
162
|
expect(optionalSchema.parse("")).toBe("0223456789")
|
|
163
163
|
})
|
|
164
164
|
|
|
165
165
|
it("should handle whitelist with optional fields", () => {
|
|
166
|
-
const schema =
|
|
166
|
+
const schema = twFax(false, { whitelist: ["custom-value", "0223456789"] })
|
|
167
167
|
|
|
168
168
|
expect(schema.parse("")).toBe(null)
|
|
169
169
|
expect(schema.parse("custom-value")).toBe("custom-value")
|
|
@@ -174,7 +174,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
174
174
|
|
|
175
175
|
describe("transform function", () => {
|
|
176
176
|
it("should apply custom transform", () => {
|
|
177
|
-
const schema =
|
|
177
|
+
const schema = twFax(true, {
|
|
178
178
|
transform: (val) => val.replace(/[-\s]/g, ""),
|
|
179
179
|
})
|
|
180
180
|
|
|
@@ -183,7 +183,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
183
183
|
})
|
|
184
184
|
|
|
185
185
|
it("should apply transform before validation", () => {
|
|
186
|
-
const schema =
|
|
186
|
+
const schema = twFax(true, {
|
|
187
187
|
transform: (val) => val.replace(/\s+/g, ""),
|
|
188
188
|
})
|
|
189
189
|
|
|
@@ -192,7 +192,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
192
192
|
})
|
|
193
193
|
|
|
194
194
|
it("should work with whitelist after transform", () => {
|
|
195
|
-
const schema =
|
|
195
|
+
const schema = twFax(true, {
|
|
196
196
|
transform: (val) => val.replace(/[-\s]/g, ""),
|
|
197
197
|
whitelist: ["0223456789", "customvalue"],
|
|
198
198
|
})
|
|
@@ -204,14 +204,14 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
204
204
|
|
|
205
205
|
describe("input preprocessing", () => {
|
|
206
206
|
it("should handle string conversion", () => {
|
|
207
|
-
const schema =
|
|
207
|
+
const schema = twFax(true)
|
|
208
208
|
|
|
209
209
|
// Test string conversion of numbers
|
|
210
210
|
expect(() => schema.parse(212345678)).toThrow("Invalid Taiwan fax format") // Invalid because missing leading 0
|
|
211
211
|
})
|
|
212
212
|
|
|
213
213
|
it("should trim whitespace", () => {
|
|
214
|
-
const schema =
|
|
214
|
+
const schema = twFax(true)
|
|
215
215
|
|
|
216
216
|
expect(schema.parse(" 0223456789 ")).toBe("0223456789")
|
|
217
217
|
expect(schema.parse("\t072345678\n")).toBe("072345678")
|
|
@@ -254,7 +254,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
254
254
|
describe("i18n support", () => {
|
|
255
255
|
it("should use English messages by default", () => {
|
|
256
256
|
setLocale("en")
|
|
257
|
-
const schema =
|
|
257
|
+
const schema = twFax(true)
|
|
258
258
|
|
|
259
259
|
expect(() => schema.parse("")).toThrow("Required")
|
|
260
260
|
expect(() => schema.parse("0912345678")).toThrow("Invalid Taiwan fax format")
|
|
@@ -262,7 +262,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
262
262
|
|
|
263
263
|
it("should use Chinese messages when locale is zh-TW", () => {
|
|
264
264
|
setLocale("zh-TW")
|
|
265
|
-
const schema =
|
|
265
|
+
const schema = twFax(true)
|
|
266
266
|
|
|
267
267
|
expect(() => schema.parse("")).toThrow("必填")
|
|
268
268
|
expect(() => schema.parse("0912345678")).toThrow("無效的傳真號碼格式")
|
|
@@ -270,7 +270,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
270
270
|
|
|
271
271
|
it("should support whitelist error messages", () => {
|
|
272
272
|
setLocale("en")
|
|
273
|
-
const schema =
|
|
273
|
+
const schema = twFax(true, {
|
|
274
274
|
whitelist: ["0223456789"],
|
|
275
275
|
})
|
|
276
276
|
|
|
@@ -281,7 +281,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
281
281
|
})
|
|
282
282
|
|
|
283
283
|
it("should support custom i18n messages", () => {
|
|
284
|
-
const schema =
|
|
284
|
+
const schema = twFax(true, {
|
|
285
285
|
i18n: {
|
|
286
286
|
en: {
|
|
287
287
|
required: "Fax number is required",
|
|
@@ -306,7 +306,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
306
306
|
})
|
|
307
307
|
|
|
308
308
|
it("should support custom whitelist messages", () => {
|
|
309
|
-
const schema =
|
|
309
|
+
const schema = twFax(true, {
|
|
310
310
|
whitelist: ["0223456789"],
|
|
311
311
|
i18n: {
|
|
312
312
|
en: {
|
|
@@ -328,7 +328,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
328
328
|
|
|
329
329
|
describe("real world Taiwan fax numbers", () => {
|
|
330
330
|
it("should validate all major area codes", () => {
|
|
331
|
-
const schema =
|
|
331
|
+
const schema = twFax(true)
|
|
332
332
|
|
|
333
333
|
// Test Taiwan fax area codes using exact working numbers from tel utility test
|
|
334
334
|
const validAreaCodes = [
|
|
@@ -352,7 +352,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
352
352
|
})
|
|
353
353
|
|
|
354
354
|
it("should reject mobile phone prefixes", () => {
|
|
355
|
-
const schema =
|
|
355
|
+
const schema = twFax(true)
|
|
356
356
|
|
|
357
357
|
// Test invalid mobile prefixes (090-099)
|
|
358
358
|
const mobilePrefixes = ["090", "091", "092", "093", "094", "095", "096", "097", "098", "099"]
|
|
@@ -364,7 +364,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
364
364
|
})
|
|
365
365
|
|
|
366
366
|
it("should validate realistic fax number patterns", () => {
|
|
367
|
-
const schema =
|
|
367
|
+
const schema = twFax(true)
|
|
368
368
|
|
|
369
369
|
const realFaxNumbers = [
|
|
370
370
|
"0223456789", // Taipei 10-digit (valid first digit 2) - from utility test ✓
|
|
@@ -387,15 +387,15 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
387
387
|
|
|
388
388
|
describe("edge cases", () => {
|
|
389
389
|
it("should handle various input types", () => {
|
|
390
|
-
const schema =
|
|
390
|
+
const schema = twFax(true)
|
|
391
391
|
|
|
392
392
|
// Test different input types that should be converted to string
|
|
393
393
|
expect(schema.parse("0223456789")).toBe("0223456789")
|
|
394
394
|
})
|
|
395
395
|
|
|
396
396
|
it("should handle empty and whitespace inputs", () => {
|
|
397
|
-
const schema =
|
|
398
|
-
const optionalSchema =
|
|
397
|
+
const schema = twFax(true)
|
|
398
|
+
const optionalSchema = twFax(false)
|
|
399
399
|
|
|
400
400
|
expect(() => schema.parse("")).toThrow("Required")
|
|
401
401
|
expect(() => schema.parse(" ")).toThrow("Required")
|
|
@@ -407,7 +407,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
407
407
|
})
|
|
408
408
|
|
|
409
409
|
it("should preserve valid format after transformation", () => {
|
|
410
|
-
const schema =
|
|
410
|
+
const schema = twFax(true, {
|
|
411
411
|
transform: (val) => val.replace(/[^0-9]/g, ""),
|
|
412
412
|
})
|
|
413
413
|
|
|
@@ -418,7 +418,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
418
418
|
})
|
|
419
419
|
|
|
420
420
|
it("should work with complex whitelist scenarios", () => {
|
|
421
|
-
const schema =
|
|
421
|
+
const schema = twFax(false, { whitelist: ["0223456789", "emergency", "custom-fax-123", ""] })
|
|
422
422
|
|
|
423
423
|
// Allowlist scenarios
|
|
424
424
|
expect(schema.parse("0223456789")).toBe("0223456789")
|
|
@@ -432,7 +432,7 @@ describe("Taiwan fax(true) validator", () => {
|
|
|
432
432
|
})
|
|
433
433
|
|
|
434
434
|
it("should handle boundary cases for area codes", () => {
|
|
435
|
-
const schema =
|
|
435
|
+
const schema = twFax(true)
|
|
436
436
|
|
|
437
437
|
// Test minimum and maximum valid lengths for different area codes
|
|
438
438
|
// 2-digit area codes: 9-10 digits total
|