@hy_ong/zod-kit 0.1.15 → 0.2.0
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/CLAUDE.md +142 -0
- package/README.md +5 -5
- package/dist/index.cjs +1660 -4
- package/dist/index.d.cts +18 -18
- package/dist/index.d.ts +18 -18
- package/dist/index.js +1660 -4
- package/package.json +4 -3
- package/src/config.ts +2 -2
- package/src/i18n/index.ts +18 -2
- package/src/i18n/locales/en-GB.json +204 -0
- package/src/i18n/locales/id-ID.json +204 -0
- package/src/i18n/locales/ja-JP.json +204 -0
- package/src/i18n/locales/ko-KR.json +204 -0
- package/src/i18n/locales/ms-MY.json +204 -0
- package/src/i18n/locales/th-TH.json +204 -0
- package/src/i18n/locales/vi-VN.json +204 -0
- package/src/i18n/locales/zh-CN.json +204 -0
- package/src/validators/common/boolean.ts +1 -1
- package/src/validators/common/date.ts +1 -1
- package/src/validators/common/datetime.ts +1 -1
- package/src/validators/common/email.ts +1 -1
- package/src/validators/common/file.ts +1 -1
- package/src/validators/common/id.ts +1 -1
- package/src/validators/common/number.ts +1 -1
- package/src/validators/common/password.ts +1 -1
- package/src/validators/common/text.ts +1 -1
- package/src/validators/common/time.ts +1 -1
- package/src/validators/common/url.ts +1 -1
- package/src/validators/taiwan/business-id.ts +1 -1
- package/src/validators/taiwan/fax.ts +1 -1
- package/src/validators/taiwan/mobile.ts +1 -1
- package/src/validators/taiwan/national-id.ts +1 -1
- package/src/validators/taiwan/postal-code.ts +1 -1
- package/src/validators/taiwan/tel.ts +1 -1
- package/tests/common/boolean.test.ts +6 -6
- package/tests/common/date.test.ts +8 -8
- package/tests/common/datetime.test.ts +7 -7
- package/tests/common/email.test.ts +6 -6
- package/tests/common/file.test.ts +6 -6
- package/tests/common/id.test.ts +5 -5
- package/tests/common/number.test.ts +6 -6
- package/tests/common/password.test.ts +5 -5
- package/tests/common/text.test.ts +7 -7
- package/tests/common/time.test.ts +7 -7
- package/tests/common/url.test.ts +10 -10
- package/tests/taiwan/business-id.test.ts +4 -4
- package/tests/taiwan/fax.test.ts +7 -7
- package/tests/taiwan/mobile.test.ts +7 -7
- package/tests/taiwan/national-id.test.ts +4 -4
- package/tests/taiwan/postal-code.test.ts +6 -6
- package/tests/taiwan/tel.test.ts +7 -7
- /package/src/i18n/locales/{en.json → en-US.json} +0 -0
|
@@ -71,7 +71,7 @@ export type EmailOptions<IsRequired extends boolean = true> = {
|
|
|
71
71
|
lowercase?: boolean
|
|
72
72
|
transform?: (value: string) => string
|
|
73
73
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
74
|
-
i18n?: Record<Locale, EmailMessages
|
|
74
|
+
i18n?: Partial<Record<Locale, Partial<EmailMessages>>>
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -92,7 +92,7 @@ export type FileOptions<IsRequired extends boolean = true> = {
|
|
|
92
92
|
caseSensitive?: boolean
|
|
93
93
|
transform?: (value: File) => File
|
|
94
94
|
defaultValue?: IsRequired extends true ? File : File | null
|
|
95
|
-
i18n?: Record<Locale, FileMessages
|
|
95
|
+
i18n?: Partial<Record<Locale, Partial<FileMessages>>>
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -116,7 +116,7 @@ export type IdOptions<Type extends IdType | undefined = undefined> = {
|
|
|
116
116
|
caseSensitive?: boolean
|
|
117
117
|
transform?: (value: string) => string
|
|
118
118
|
defaultValue?: any // Simplified to avoid complex conditional types
|
|
119
|
-
i18n?: Record<Locale, IdMessages
|
|
119
|
+
i18n?: Partial<Record<Locale, Partial<IdMessages>>>
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/**
|
|
@@ -82,7 +82,7 @@ export type NumberOptions<IsRequired extends boolean = true> = {
|
|
|
82
82
|
finite?: boolean
|
|
83
83
|
transform?: (value: number) => number
|
|
84
84
|
parseCommas?: boolean // Parse "1,234" as 1234
|
|
85
|
-
i18n?: Record<Locale, NumberMessages
|
|
85
|
+
i18n?: Partial<Record<Locale, Partial<NumberMessages>>>
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
@@ -100,7 +100,7 @@ export type PasswordOptions<IsRequired extends boolean = true> = {
|
|
|
100
100
|
regex?: RegExp
|
|
101
101
|
transform?: (value: string) => string
|
|
102
102
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
103
|
-
i18n?: Record<Locale, PasswordMessages
|
|
103
|
+
i18n?: Partial<Record<Locale, Partial<PasswordMessages>>>
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
@@ -72,7 +72,7 @@ export type TextOptions<IsRequired extends boolean = true> = {
|
|
|
72
72
|
transform?: (value: string) => string
|
|
73
73
|
notEmpty?: boolean
|
|
74
74
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
75
|
-
i18n?: Record<Locale, TextMessages
|
|
75
|
+
i18n?: Partial<Record<Locale, Partial<TextMessages>>>
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -109,7 +109,7 @@ export type TimeOptions<IsRequired extends boolean = true> = {
|
|
|
109
109
|
whitelistOnly?: boolean // If true, only allow values in whitelist (default: false)
|
|
110
110
|
transform?: (value: string) => string
|
|
111
111
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
112
|
-
i18n?: Record<Locale, TimeMessages
|
|
112
|
+
i18n?: Partial<Record<Locale, Partial<TimeMessages>>>
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
@@ -104,7 +104,7 @@ export type UrlOptions<IsRequired extends boolean = true> = {
|
|
|
104
104
|
blockLocalhost?: boolean
|
|
105
105
|
transform?: (value: string) => string
|
|
106
106
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
107
|
-
i18n?: Record<Locale, UrlMessages
|
|
107
|
+
i18n?: Partial<Record<Locale, Partial<UrlMessages>>>
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
@@ -38,7 +38,7 @@ export type TwBusinessIdMessages = {
|
|
|
38
38
|
export type TwBusinessIdOptions<IsRequired extends boolean = true> = {
|
|
39
39
|
transform?: (value: string) => string
|
|
40
40
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
41
|
-
i18n?: Record<Locale, TwBusinessIdMessages
|
|
41
|
+
i18n?: Partial<Record<Locale, Partial<TwBusinessIdMessages>>>
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -42,7 +42,7 @@ export type TwFaxOptions<IsRequired extends boolean = true> = {
|
|
|
42
42
|
whitelist?: string[]
|
|
43
43
|
transform?: (value: string) => string
|
|
44
44
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
45
|
-
i18n?: Record<Locale, TwFaxMessages
|
|
45
|
+
i18n?: Partial<Record<Locale, Partial<TwFaxMessages>>>
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -42,7 +42,7 @@ export type TwMobileOptions<IsRequired extends boolean = true> = {
|
|
|
42
42
|
whitelist?: string[]
|
|
43
43
|
transform?: (value: string) => string
|
|
44
44
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
45
|
-
i18n?: Record<Locale, TwMobileMessages
|
|
45
|
+
i18n?: Partial<Record<Locale, Partial<TwMobileMessages>>>
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -57,7 +57,7 @@ export type TwNationalIdOptions<IsRequired extends boolean = true> = {
|
|
|
57
57
|
allowOldResident?: boolean
|
|
58
58
|
transform?: (value: string) => string
|
|
59
59
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
60
|
-
i18n?: Record<Locale, TwNationalIdMessages
|
|
60
|
+
i18n?: Partial<Record<Locale, Partial<TwNationalIdMessages>>>
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
@@ -88,7 +88,7 @@ export type TwPostalCodeOptions<IsRequired extends boolean = true> = {
|
|
|
88
88
|
blockedPrefixes?: string[]
|
|
89
89
|
transform?: (value: string) => string
|
|
90
90
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
91
|
-
i18n?: Record<Locale, TwPostalCodeMessages
|
|
91
|
+
i18n?: Partial<Record<Locale, Partial<TwPostalCodeMessages>>>
|
|
92
92
|
strictSuffixValidation?: boolean
|
|
93
93
|
deprecate5Digit?: boolean
|
|
94
94
|
}
|
|
@@ -42,7 +42,7 @@ export type TwTelOptions<IsRequired extends boolean = true> = {
|
|
|
42
42
|
whitelist?: string[]
|
|
43
43
|
transform?: (value: string) => string
|
|
44
44
|
defaultValue?: IsRequired extends true ? string : string | null
|
|
45
|
-
i18n?: Record<Locale, TwTelMessages
|
|
45
|
+
i18n?: Partial<Record<Locale, Partial<TwTelMessages>>>
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
@@ -272,13 +272,13 @@ describe("boolean", () => {
|
|
|
272
272
|
})
|
|
273
273
|
|
|
274
274
|
describe("custom i18n messages", () => {
|
|
275
|
-
beforeEach(() => setLocale("en"))
|
|
275
|
+
beforeEach(() => setLocale("en-US"))
|
|
276
276
|
|
|
277
277
|
it("should use custom messages when provided", () => {
|
|
278
278
|
const schema = boolean(true, {
|
|
279
279
|
shouldBe: true,
|
|
280
280
|
i18n: {
|
|
281
|
-
en: {
|
|
281
|
+
"en-US": {
|
|
282
282
|
required: "Custom required message",
|
|
283
283
|
shouldBeTrue: "Custom should be true message",
|
|
284
284
|
},
|
|
@@ -297,7 +297,7 @@ describe("boolean", () => {
|
|
|
297
297
|
const schema = boolean(true, {
|
|
298
298
|
shouldBe: false,
|
|
299
299
|
i18n: {
|
|
300
|
-
en: {
|
|
300
|
+
"en-US": {
|
|
301
301
|
required: "Custom required message",
|
|
302
302
|
},
|
|
303
303
|
"zh-TW": {
|
|
@@ -311,10 +311,10 @@ describe("boolean", () => {
|
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
it("should use correct locale for custom messages", () => {
|
|
314
|
-
setLocale("en")
|
|
314
|
+
setLocale("en-US")
|
|
315
315
|
const schemaEn = boolean(true, {
|
|
316
316
|
i18n: {
|
|
317
|
-
en: {
|
|
317
|
+
"en-US": {
|
|
318
318
|
required: "English required",
|
|
319
319
|
},
|
|
320
320
|
"zh-TW": {
|
|
@@ -327,7 +327,7 @@ describe("boolean", () => {
|
|
|
327
327
|
setLocale("zh-TW")
|
|
328
328
|
const schemaZh = boolean(true, {
|
|
329
329
|
i18n: {
|
|
330
|
-
en: {
|
|
330
|
+
"en-US": {
|
|
331
331
|
required: "English required",
|
|
332
332
|
},
|
|
333
333
|
"zh-TW": {
|
|
@@ -159,7 +159,7 @@ describe("date", () => {
|
|
|
159
159
|
|
|
160
160
|
describe("localization", () => {
|
|
161
161
|
it("should use English error messages", () => {
|
|
162
|
-
setLocale("en")
|
|
162
|
+
setLocale("en-US")
|
|
163
163
|
const schema = date(true)
|
|
164
164
|
|
|
165
165
|
try {
|
|
@@ -366,12 +366,12 @@ describe("date", () => {
|
|
|
366
366
|
it("should use custom English messages", () => {
|
|
367
367
|
const schema = date(true, {
|
|
368
368
|
i18n: {
|
|
369
|
-
en: { format: "Custom date format error: ${format}" },
|
|
369
|
+
"en-US": { format: "Custom date format error: ${format}" },
|
|
370
370
|
"zh-TW": { format: "自定義日期格式錯誤: ${format}" },
|
|
371
371
|
},
|
|
372
372
|
})
|
|
373
373
|
|
|
374
|
-
setLocale("en")
|
|
374
|
+
setLocale("en-US")
|
|
375
375
|
try {
|
|
376
376
|
schema.parse("invalid")
|
|
377
377
|
} catch (error: any) {
|
|
@@ -382,7 +382,7 @@ describe("date", () => {
|
|
|
382
382
|
it("should use custom Chinese messages", () => {
|
|
383
383
|
const schema = date(true, {
|
|
384
384
|
i18n: {
|
|
385
|
-
en: { format: "Custom date format error: ${format}" },
|
|
385
|
+
"en-US": { format: "Custom date format error: ${format}" },
|
|
386
386
|
"zh-TW": { format: "自定義日期格式錯誤: ${format}" },
|
|
387
387
|
},
|
|
388
388
|
})
|
|
@@ -398,12 +398,12 @@ describe("date", () => {
|
|
|
398
398
|
it("should fallback to default messages when custom not provided", () => {
|
|
399
399
|
const schema = date(true, {
|
|
400
400
|
i18n: {
|
|
401
|
-
en: { format: "Custom format error" },
|
|
401
|
+
"en-US": { format: "Custom format error" },
|
|
402
402
|
"zh-TW": { format: "自定義格式錯誤" },
|
|
403
403
|
},
|
|
404
404
|
})
|
|
405
405
|
|
|
406
|
-
setLocale("en")
|
|
406
|
+
setLocale("en-US")
|
|
407
407
|
try {
|
|
408
408
|
schema.parse("")
|
|
409
409
|
} catch (error: any) {
|
|
@@ -415,7 +415,7 @@ describe("date", () => {
|
|
|
415
415
|
const schema = date(true, {
|
|
416
416
|
mustBePast: true,
|
|
417
417
|
i18n: {
|
|
418
|
-
en: { past: "Date must be in the past!" },
|
|
418
|
+
"en-US": { past: "Date must be in the past!" },
|
|
419
419
|
"zh-TW": { past: "日期必須在過去!" },
|
|
420
420
|
},
|
|
421
421
|
})
|
|
@@ -424,7 +424,7 @@ describe("date", () => {
|
|
|
424
424
|
tomorrow.setDate(tomorrow.getDate() + 1)
|
|
425
425
|
const tomorrowStr = tomorrow.toISOString().split("T")[0]
|
|
426
426
|
|
|
427
|
-
setLocale("en")
|
|
427
|
+
setLocale("en-US")
|
|
428
428
|
try {
|
|
429
429
|
schema.parse(tomorrowStr)
|
|
430
430
|
} catch (error: any) {
|
|
@@ -3,7 +3,7 @@ import { datetime, setLocale, validateDateTimeFormat, parseDateTimeValue, normal
|
|
|
3
3
|
import dayjs from "dayjs"
|
|
4
4
|
|
|
5
5
|
describe("Taiwan datetime(true) validator", () => {
|
|
6
|
-
beforeEach(() => setLocale("en"))
|
|
6
|
+
beforeEach(() => setLocale("en-US"))
|
|
7
7
|
|
|
8
8
|
describe("basic functionality", () => {
|
|
9
9
|
it("should validate correct datetime formats", () => {
|
|
@@ -503,7 +503,7 @@ describe("Taiwan datetime(true) validator", () => {
|
|
|
503
503
|
|
|
504
504
|
describe("i18n support", () => {
|
|
505
505
|
it("should use English messages by default", () => {
|
|
506
|
-
setLocale("en")
|
|
506
|
+
setLocale("en-US")
|
|
507
507
|
expect(() => datetime(true).parse("")).toThrow("Required")
|
|
508
508
|
expect(() => datetime(true).parse("invalid")).toThrow("Must be in YYYY-MM-DD HH:mm format")
|
|
509
509
|
})
|
|
@@ -517,7 +517,7 @@ describe("Taiwan datetime(true) validator", () => {
|
|
|
517
517
|
})
|
|
518
518
|
|
|
519
519
|
it("should support whitelist error messages", () => {
|
|
520
|
-
setLocale("en")
|
|
520
|
+
setLocale("en-US")
|
|
521
521
|
const schema = datetime(true, {
|
|
522
522
|
format: "YYYY-MM-DD HH:mm",
|
|
523
523
|
whitelist: ["now"],
|
|
@@ -531,7 +531,7 @@ describe("Taiwan datetime(true) validator", () => {
|
|
|
531
531
|
const schema = datetime(true, {
|
|
532
532
|
format: "YYYY-MM-DD HH:mm",
|
|
533
533
|
i18n: {
|
|
534
|
-
en: {
|
|
534
|
+
"en-US": {
|
|
535
535
|
required: "DateTime is required",
|
|
536
536
|
invalid: "Invalid datetime value",
|
|
537
537
|
},
|
|
@@ -542,7 +542,7 @@ describe("Taiwan datetime(true) validator", () => {
|
|
|
542
542
|
},
|
|
543
543
|
})
|
|
544
544
|
|
|
545
|
-
setLocale("en")
|
|
545
|
+
setLocale("en-US")
|
|
546
546
|
expect(() => schema.parse("")).toThrow("DateTime is required")
|
|
547
547
|
|
|
548
548
|
setLocale("zh-TW")
|
|
@@ -555,7 +555,7 @@ describe("Taiwan datetime(true) validator", () => {
|
|
|
555
555
|
whitelist: ["now"],
|
|
556
556
|
whitelistOnly: true,
|
|
557
557
|
i18n: {
|
|
558
|
-
en: {
|
|
558
|
+
"en-US": {
|
|
559
559
|
notInWhitelist: "This datetime is not allowed",
|
|
560
560
|
},
|
|
561
561
|
"zh-TW": {
|
|
@@ -564,7 +564,7 @@ describe("Taiwan datetime(true) validator", () => {
|
|
|
564
564
|
},
|
|
565
565
|
})
|
|
566
566
|
|
|
567
|
-
setLocale("en")
|
|
567
|
+
setLocale("en-US")
|
|
568
568
|
expect(() => schema.parse("2024-03-15 14:30")).toThrow("This datetime is not allowed")
|
|
569
569
|
|
|
570
570
|
setLocale("zh-TW")
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"
|
|
|
2
2
|
import { email, setLocale } from "../../src"
|
|
3
3
|
|
|
4
4
|
describe("email(true) features", () => {
|
|
5
|
-
beforeEach(() => setLocale("en"))
|
|
5
|
+
beforeEach(() => setLocale("en-US"))
|
|
6
6
|
|
|
7
7
|
describe("multiple domain support", () => {
|
|
8
8
|
it("should accept multiple allowed domains", () => {
|
|
@@ -135,7 +135,7 @@ describe("email(true) features", () => {
|
|
|
135
135
|
domain: "company.com",
|
|
136
136
|
businessOnly: true,
|
|
137
137
|
i18n: {
|
|
138
|
-
en: {
|
|
138
|
+
"en-US": {
|
|
139
139
|
required: "Custom required message",
|
|
140
140
|
domain: "Custom domain message: ${domain}",
|
|
141
141
|
businessOnly: "Custom business only message",
|
|
@@ -157,7 +157,7 @@ describe("email(true) features", () => {
|
|
|
157
157
|
const schema = email(true, {
|
|
158
158
|
noDisposable: true,
|
|
159
159
|
i18n: {
|
|
160
|
-
en: {
|
|
160
|
+
"en-US": {
|
|
161
161
|
required: "Custom required message",
|
|
162
162
|
},
|
|
163
163
|
"zh-TW": {
|
|
@@ -171,11 +171,11 @@ describe("email(true) features", () => {
|
|
|
171
171
|
})
|
|
172
172
|
|
|
173
173
|
it("should use correct locale for custom messages", () => {
|
|
174
|
-
setLocale("en")
|
|
174
|
+
setLocale("en-US")
|
|
175
175
|
const schemaEn = email(true, {
|
|
176
176
|
businessOnly: true,
|
|
177
177
|
i18n: {
|
|
178
|
-
en: {
|
|
178
|
+
"en-US": {
|
|
179
179
|
businessOnly: "English business message",
|
|
180
180
|
},
|
|
181
181
|
"zh-TW": {
|
|
@@ -189,7 +189,7 @@ describe("email(true) features", () => {
|
|
|
189
189
|
const schemaZh = email(true, {
|
|
190
190
|
businessOnly: true,
|
|
191
191
|
i18n: {
|
|
192
|
-
en: {
|
|
192
|
+
"en-US": {
|
|
193
193
|
businessOnly: "English business message",
|
|
194
194
|
},
|
|
195
195
|
"zh-TW": {
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"
|
|
|
2
2
|
import { file, setLocale } from "../../src"
|
|
3
3
|
|
|
4
4
|
describe("file(true) features", () => {
|
|
5
|
-
beforeEach(() => setLocale("en"))
|
|
5
|
+
beforeEach(() => setLocale("en-US"))
|
|
6
6
|
|
|
7
7
|
// Helper function to create mock files for testing
|
|
8
8
|
const createMockFile = (name: string, size: number, type: string, content?: string): File => {
|
|
@@ -297,7 +297,7 @@ describe("file(true) features", () => {
|
|
|
297
297
|
extension: [".pdf"],
|
|
298
298
|
imageOnly: true,
|
|
299
299
|
i18n: {
|
|
300
|
-
en: {
|
|
300
|
+
"en-US": {
|
|
301
301
|
required: "Custom required message",
|
|
302
302
|
maxSize: "Custom size message: ${maxSize}",
|
|
303
303
|
extension: "Custom extension message: ${extension}",
|
|
@@ -326,7 +326,7 @@ describe("file(true) features", () => {
|
|
|
326
326
|
const schema = file(true, {
|
|
327
327
|
videoOnly: true,
|
|
328
328
|
i18n: {
|
|
329
|
-
en: {
|
|
329
|
+
"en-US": {
|
|
330
330
|
required: "Custom required message",
|
|
331
331
|
},
|
|
332
332
|
"zh-TW": {
|
|
@@ -342,11 +342,11 @@ describe("file(true) features", () => {
|
|
|
342
342
|
})
|
|
343
343
|
|
|
344
344
|
it("should use correct locale for custom messages", () => {
|
|
345
|
-
setLocale("en")
|
|
345
|
+
setLocale("en-US")
|
|
346
346
|
const schemaEn = file(true, {
|
|
347
347
|
imageOnly: true,
|
|
348
348
|
i18n: {
|
|
349
|
-
en: {
|
|
349
|
+
"en-US": {
|
|
350
350
|
imageOnly: "English image message",
|
|
351
351
|
},
|
|
352
352
|
"zh-TW": {
|
|
@@ -361,7 +361,7 @@ describe("file(true) features", () => {
|
|
|
361
361
|
const schemaZh = file(true, {
|
|
362
362
|
imageOnly: true,
|
|
363
363
|
i18n: {
|
|
364
|
-
en: {
|
|
364
|
+
"en-US": {
|
|
365
365
|
imageOnly: "English image message",
|
|
366
366
|
},
|
|
367
367
|
"zh-TW": {
|
package/tests/common/id.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Locale, setLocale, id, detectIdType, validateIdType, ID_PATTERNS } from
|
|
|
3
3
|
|
|
4
4
|
const locales = [
|
|
5
5
|
{
|
|
6
|
-
locale: "en",
|
|
6
|
+
locale: "en-US",
|
|
7
7
|
messages: {
|
|
8
8
|
required: "Required",
|
|
9
9
|
invalid: "Invalid ID format",
|
|
@@ -388,7 +388,7 @@ describe.each(locales)("id(true) locale: $locale", ({ locale, messages }) => {
|
|
|
388
388
|
describe("custom i18n messages", () => {
|
|
389
389
|
it("should use custom i18n messages when provided", () => {
|
|
390
390
|
const customMessages = {
|
|
391
|
-
en: {
|
|
391
|
+
"en-US": {
|
|
392
392
|
required: "Custom required message",
|
|
393
393
|
invalid: "Custom invalid message",
|
|
394
394
|
numeric: "Custom numeric message",
|
|
@@ -405,7 +405,7 @@ describe.each(locales)("id(true) locale: $locale", ({ locale, messages }) => {
|
|
|
405
405
|
i18n: customMessages,
|
|
406
406
|
})
|
|
407
407
|
|
|
408
|
-
if (locale === "en") {
|
|
408
|
+
if (locale === "en-US") {
|
|
409
409
|
expect(() => schema.parse("")).toThrow("Custom required message")
|
|
410
410
|
expect(() => schema.parse("abc")).toThrow("Custom numeric message")
|
|
411
411
|
} else {
|
|
@@ -416,7 +416,7 @@ describe.each(locales)("id(true) locale: $locale", ({ locale, messages }) => {
|
|
|
416
416
|
|
|
417
417
|
it("should fallback to default i18n when custom message not provided", () => {
|
|
418
418
|
const customMessages = {
|
|
419
|
-
en: { required: "Custom required message" },
|
|
419
|
+
"en-US": { required: "Custom required message" },
|
|
420
420
|
"zh-TW": { required: "自訂必填訊息" },
|
|
421
421
|
}
|
|
422
422
|
|
|
@@ -425,7 +425,7 @@ describe.each(locales)("id(true) locale: $locale", ({ locale, messages }) => {
|
|
|
425
425
|
i18n: customMessages,
|
|
426
426
|
})
|
|
427
427
|
|
|
428
|
-
if (locale === "en") {
|
|
428
|
+
if (locale === "en-US") {
|
|
429
429
|
expect(() => schema.parse("")).toThrow("Custom required message")
|
|
430
430
|
expect(() => schema.parse("abc")).toThrow(messages.numeric)
|
|
431
431
|
} else {
|
|
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest"
|
|
|
2
2
|
import { number, setLocale } from "../../src"
|
|
3
3
|
|
|
4
4
|
describe("number(true) features", () => {
|
|
5
|
-
beforeEach(() => setLocale("en"))
|
|
5
|
+
beforeEach(() => setLocale("en-US"))
|
|
6
6
|
|
|
7
7
|
describe("type validation", () => {
|
|
8
8
|
it("should accept integers when type='integer'", () => {
|
|
@@ -133,7 +133,7 @@ describe("number(true) features", () => {
|
|
|
133
133
|
type: "integer",
|
|
134
134
|
min: 0,
|
|
135
135
|
i18n: {
|
|
136
|
-
en: {
|
|
136
|
+
"en-US": {
|
|
137
137
|
required: "Custom required message",
|
|
138
138
|
integer: "Custom integer message",
|
|
139
139
|
min: "Custom min: at least ${min}",
|
|
@@ -156,7 +156,7 @@ describe("number(true) features", () => {
|
|
|
156
156
|
type: "integer",
|
|
157
157
|
max: 10,
|
|
158
158
|
i18n: {
|
|
159
|
-
en: {
|
|
159
|
+
"en-US": {
|
|
160
160
|
required: "Custom required message",
|
|
161
161
|
},
|
|
162
162
|
"zh-TW": {
|
|
@@ -171,11 +171,11 @@ describe("number(true) features", () => {
|
|
|
171
171
|
})
|
|
172
172
|
|
|
173
173
|
it("should use correct locale for custom messages", () => {
|
|
174
|
-
setLocale("en")
|
|
174
|
+
setLocale("en-US")
|
|
175
175
|
const schemaEn = number(true, {
|
|
176
176
|
type: "integer",
|
|
177
177
|
i18n: {
|
|
178
|
-
en: {
|
|
178
|
+
"en-US": {
|
|
179
179
|
integer: "English integer message",
|
|
180
180
|
},
|
|
181
181
|
"zh-TW": {
|
|
@@ -189,7 +189,7 @@ describe("number(true) features", () => {
|
|
|
189
189
|
const schemaZh = number(true, {
|
|
190
190
|
type: "integer",
|
|
191
191
|
i18n: {
|
|
192
|
-
en: {
|
|
192
|
+
"en-US": {
|
|
193
193
|
integer: "English integer message",
|
|
194
194
|
},
|
|
195
195
|
"zh-TW": {
|
|
@@ -3,7 +3,7 @@ import { Locale, setLocale, password } from "../../src"
|
|
|
3
3
|
|
|
4
4
|
const locales = [
|
|
5
5
|
{
|
|
6
|
-
locale: "en",
|
|
6
|
+
locale: "en-US",
|
|
7
7
|
messages: {
|
|
8
8
|
required: "Required",
|
|
9
9
|
min: "Must be at least 8 characters",
|
|
@@ -193,7 +193,7 @@ describe.each(locales)("password(true) locale: $locale", ({ locale, messages })
|
|
|
193
193
|
describe("custom i18n messages", () => {
|
|
194
194
|
it("should use custom i18n messages when provided", () => {
|
|
195
195
|
const customMessages = {
|
|
196
|
-
en: {
|
|
196
|
+
"en-US": {
|
|
197
197
|
required: "Custom required message",
|
|
198
198
|
min: "Custom min ${min} message",
|
|
199
199
|
uppercase: "Custom uppercase message",
|
|
@@ -211,7 +211,7 @@ describe.each(locales)("password(true) locale: $locale", ({ locale, messages })
|
|
|
211
211
|
i18n: customMessages,
|
|
212
212
|
})
|
|
213
213
|
|
|
214
|
-
if (locale === "en") {
|
|
214
|
+
if (locale === "en-US") {
|
|
215
215
|
expect(() => schema.parse("")).toThrow("Custom required message")
|
|
216
216
|
expect(() => schema.parse("short")).toThrow("Custom min 8 message")
|
|
217
217
|
expect(() => schema.parse("nouppercase")).toThrow("Custom uppercase message")
|
|
@@ -224,7 +224,7 @@ describe.each(locales)("password(true) locale: $locale", ({ locale, messages })
|
|
|
224
224
|
|
|
225
225
|
it("should fallback to default i18n when custom message not provided", () => {
|
|
226
226
|
const customMessages = {
|
|
227
|
-
en: { required: "Custom required message" },
|
|
227
|
+
"en-US": { required: "Custom required message" },
|
|
228
228
|
"zh-TW": { required: "自訂必填訊息" },
|
|
229
229
|
}
|
|
230
230
|
|
|
@@ -233,7 +233,7 @@ describe.each(locales)("password(true) locale: $locale", ({ locale, messages })
|
|
|
233
233
|
i18n: customMessages,
|
|
234
234
|
})
|
|
235
235
|
|
|
236
|
-
if (locale === "en") {
|
|
236
|
+
if (locale === "en-US") {
|
|
237
237
|
expect(() => schema.parse("")).toThrow("Custom required message")
|
|
238
238
|
expect(() => schema.parse("nouppercase")).toThrow(messages.uppercase)
|
|
239
239
|
} else {
|
|
@@ -3,7 +3,7 @@ import { Locale, setLocale, text } from "../../src"
|
|
|
3
3
|
|
|
4
4
|
const locales = [
|
|
5
5
|
{
|
|
6
|
-
locale: "en",
|
|
6
|
+
locale: "en-US",
|
|
7
7
|
messages: {
|
|
8
8
|
required: "Required",
|
|
9
9
|
notEmpty: "Cannot be empty or whitespace only",
|
|
@@ -193,13 +193,13 @@ describe("text(true) defaultValue functionality", () => {
|
|
|
193
193
|
})
|
|
194
194
|
|
|
195
195
|
describe("text(true) custom i18n messages", () => {
|
|
196
|
-
beforeEach(() => setLocale("en"))
|
|
196
|
+
beforeEach(() => setLocale("en-US"))
|
|
197
197
|
|
|
198
198
|
it("should use custom messages when provided", () => {
|
|
199
199
|
const schema = text(true, {
|
|
200
200
|
minLength: 5,
|
|
201
201
|
i18n: {
|
|
202
|
-
en: {
|
|
202
|
+
"en-US": {
|
|
203
203
|
required: "Custom required message",
|
|
204
204
|
minLength: "Custom min message: at least ${minLength} chars",
|
|
205
205
|
},
|
|
@@ -218,7 +218,7 @@ describe("text(true) custom i18n messages", () => {
|
|
|
218
218
|
const schema = text(true, {
|
|
219
219
|
maxLength: 3,
|
|
220
220
|
i18n: {
|
|
221
|
-
en: {
|
|
221
|
+
"en-US": {
|
|
222
222
|
required: "Custom required message",
|
|
223
223
|
},
|
|
224
224
|
"zh-TW": {
|
|
@@ -234,7 +234,7 @@ describe("text(true) custom i18n messages", () => {
|
|
|
234
234
|
it("should use correct locale for custom messages", () => {
|
|
235
235
|
const schema = text(true, {
|
|
236
236
|
i18n: {
|
|
237
|
-
en: {
|
|
237
|
+
"en-US": {
|
|
238
238
|
required: "English required",
|
|
239
239
|
},
|
|
240
240
|
"zh-TW": {
|
|
@@ -243,7 +243,7 @@ describe("text(true) custom i18n messages", () => {
|
|
|
243
243
|
},
|
|
244
244
|
})
|
|
245
245
|
|
|
246
|
-
setLocale("en")
|
|
246
|
+
setLocale("en-US")
|
|
247
247
|
expect(() => schema.parse("")).toThrow("English required")
|
|
248
248
|
|
|
249
249
|
setLocale("zh-TW")
|
|
@@ -252,7 +252,7 @@ describe("text(true) custom i18n messages", () => {
|
|
|
252
252
|
})
|
|
253
253
|
|
|
254
254
|
describe("text(true) complex scenarios", () => {
|
|
255
|
-
beforeEach(() => setLocale("en")) // Ensure a consistent locale for this test
|
|
255
|
+
beforeEach(() => setLocale("en-US")) // Ensure a consistent locale for this test
|
|
256
256
|
|
|
257
257
|
it("should work with multiple validations", () => {
|
|
258
258
|
const schema = text(true, {
|