@hy_ong/zod-kit 0.1.2 → 0.1.4
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 +485 -267
- package/dist/index.d.cts +107 -106
- package/dist/index.d.ts +107 -106
- package/dist/index.js +479 -261
- 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 +40 -26
- 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 +24 -28
- 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/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
package/dist/index.cjs
CHANGED
|
@@ -35,28 +35,28 @@ __export(index_exports, {
|
|
|
35
35
|
TIME_PATTERNS: () => TIME_PATTERNS,
|
|
36
36
|
VALID_3_DIGIT_PREFIXES: () => VALID_3_DIGIT_PREFIXES,
|
|
37
37
|
boolean: () => boolean,
|
|
38
|
-
businessId: () => businessId,
|
|
39
38
|
date: () => date,
|
|
40
39
|
datetime: () => datetime,
|
|
41
40
|
detectIdType: () => detectIdType,
|
|
42
41
|
email: () => email,
|
|
43
|
-
fax: () => fax,
|
|
44
42
|
file: () => file,
|
|
45
43
|
getLocale: () => getLocale,
|
|
46
44
|
id: () => id,
|
|
47
|
-
mobile: () => mobile,
|
|
48
|
-
nationalId: () => nationalId,
|
|
49
45
|
normalizeDateTimeValue: () => normalizeDateTimeValue,
|
|
50
46
|
normalizeTime: () => normalizeTime,
|
|
51
47
|
number: () => number,
|
|
52
48
|
parseDateTimeValue: () => parseDateTimeValue,
|
|
53
49
|
parseTimeToMinutes: () => parseTimeToMinutes,
|
|
54
50
|
password: () => password,
|
|
55
|
-
postalCode: () => postalCode,
|
|
56
51
|
setLocale: () => setLocale,
|
|
57
|
-
tel: () => tel,
|
|
58
52
|
text: () => text,
|
|
59
53
|
time: () => time,
|
|
54
|
+
twBusinessId: () => twBusinessId,
|
|
55
|
+
twFax: () => twFax,
|
|
56
|
+
twMobile: () => twMobile,
|
|
57
|
+
twNationalId: () => twNationalId,
|
|
58
|
+
twPostalCode: () => twPostalCode,
|
|
59
|
+
twTel: () => twTel,
|
|
60
60
|
url: () => url,
|
|
61
61
|
validate3DigitPostalCode: () => validate3DigitPostalCode,
|
|
62
62
|
validate5DigitPostalCode: () => validate5DigitPostalCode,
|
|
@@ -630,53 +630,64 @@ function date(required, options) {
|
|
|
630
630
|
return processed;
|
|
631
631
|
};
|
|
632
632
|
const baseSchema = isRequired ? import_zod2.z.preprocess(preprocessFn, import_zod2.z.string()) : import_zod2.z.preprocess(preprocessFn, import_zod2.z.string().nullable());
|
|
633
|
-
const schema = baseSchema.
|
|
634
|
-
if (val === null) return
|
|
633
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
634
|
+
if (val === null) return;
|
|
635
635
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
636
|
-
|
|
636
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
637
|
+
return;
|
|
637
638
|
}
|
|
638
639
|
if (val !== null && !(0, import_dayjs.default)(val, format, true).isValid()) {
|
|
639
|
-
|
|
640
|
+
ctx.addIssue({ code: "custom", message: getMessage("format", { format }) });
|
|
641
|
+
return;
|
|
640
642
|
}
|
|
641
643
|
const dateObj = (0, import_dayjs.default)(val, format);
|
|
642
644
|
if (val !== null && min !== void 0 && !dateObj.isSameOrAfter((0, import_dayjs.default)(min, format))) {
|
|
643
|
-
|
|
645
|
+
ctx.addIssue({ code: "custom", message: getMessage("min", { min }) });
|
|
646
|
+
return;
|
|
644
647
|
}
|
|
645
648
|
if (val !== null && max !== void 0 && !dateObj.isSameOrBefore((0, import_dayjs.default)(max, format))) {
|
|
646
|
-
|
|
649
|
+
ctx.addIssue({ code: "custom", message: getMessage("max", { max }) });
|
|
650
|
+
return;
|
|
647
651
|
}
|
|
648
652
|
if (val !== null && includes !== void 0 && !val.includes(includes)) {
|
|
649
|
-
|
|
653
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
654
|
+
return;
|
|
650
655
|
}
|
|
651
656
|
if (val !== null && excludes !== void 0) {
|
|
652
657
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
653
658
|
for (const exclude of excludeList) {
|
|
654
659
|
if (val.includes(exclude)) {
|
|
655
|
-
|
|
660
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
661
|
+
return;
|
|
656
662
|
}
|
|
657
663
|
}
|
|
658
664
|
}
|
|
659
665
|
const today = (0, import_dayjs.default)().startOf("day");
|
|
660
666
|
const targetDate = dateObj.startOf("day");
|
|
661
667
|
if (val !== null && mustBePast && !targetDate.isBefore(today)) {
|
|
662
|
-
|
|
668
|
+
ctx.addIssue({ code: "custom", message: getMessage("past") });
|
|
669
|
+
return;
|
|
663
670
|
}
|
|
664
671
|
if (val !== null && mustBeFuture && !targetDate.isAfter(today)) {
|
|
665
|
-
|
|
672
|
+
ctx.addIssue({ code: "custom", message: getMessage("future") });
|
|
673
|
+
return;
|
|
666
674
|
}
|
|
667
675
|
if (val !== null && mustBeToday && !targetDate.isSame(today)) {
|
|
668
|
-
|
|
676
|
+
ctx.addIssue({ code: "custom", message: getMessage("today") });
|
|
677
|
+
return;
|
|
669
678
|
}
|
|
670
679
|
if (val !== null && mustNotBeToday && targetDate.isSame(today)) {
|
|
671
|
-
|
|
680
|
+
ctx.addIssue({ code: "custom", message: getMessage("notToday") });
|
|
681
|
+
return;
|
|
672
682
|
}
|
|
673
683
|
if (val !== null && weekdaysOnly && (dateObj.day() === 0 || dateObj.day() === 6)) {
|
|
674
|
-
|
|
684
|
+
ctx.addIssue({ code: "custom", message: getMessage("weekday") });
|
|
685
|
+
return;
|
|
675
686
|
}
|
|
676
687
|
if (val !== null && weekendsOnly && dateObj.day() !== 0 && dateObj.day() !== 6) {
|
|
677
|
-
|
|
688
|
+
ctx.addIssue({ code: "custom", message: getMessage("weekend") });
|
|
689
|
+
return;
|
|
678
690
|
}
|
|
679
|
-
return true;
|
|
680
691
|
});
|
|
681
692
|
return schema;
|
|
682
693
|
}
|
|
@@ -849,104 +860,123 @@ function datetime(required, options) {
|
|
|
849
860
|
return processed;
|
|
850
861
|
};
|
|
851
862
|
const baseSchema = isRequired ? import_zod3.z.preprocess(preprocessFn, import_zod3.z.string()) : import_zod3.z.preprocess(preprocessFn, import_zod3.z.string().nullable());
|
|
852
|
-
const schema = baseSchema.
|
|
853
|
-
if (val === null) return
|
|
863
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
864
|
+
if (val === null) return;
|
|
854
865
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
855
|
-
|
|
866
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
867
|
+
return;
|
|
856
868
|
}
|
|
857
|
-
if (val === null) return
|
|
858
|
-
if (!isRequired && val === "") return
|
|
869
|
+
if (val === null) return;
|
|
870
|
+
if (!isRequired && val === "") return;
|
|
859
871
|
if (whitelist && whitelist.length > 0) {
|
|
860
872
|
if (whitelist.includes(val)) {
|
|
861
|
-
return
|
|
873
|
+
return;
|
|
862
874
|
}
|
|
863
875
|
if (whitelistOnly) {
|
|
864
|
-
|
|
876
|
+
ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
|
|
877
|
+
return;
|
|
865
878
|
}
|
|
866
879
|
}
|
|
867
880
|
if (regex) {
|
|
868
881
|
if (!regex.test(val)) {
|
|
869
|
-
|
|
882
|
+
ctx.addIssue({ code: "custom", message: getMessage("customRegex") });
|
|
883
|
+
return;
|
|
870
884
|
}
|
|
871
885
|
} else {
|
|
872
886
|
if (!validateDateTimeFormat(val, format)) {
|
|
873
|
-
|
|
887
|
+
ctx.addIssue({ code: "custom", message: getMessage("format", { format }) });
|
|
888
|
+
return;
|
|
874
889
|
}
|
|
875
890
|
}
|
|
876
891
|
if (includes && !val.includes(includes)) {
|
|
877
|
-
|
|
892
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
893
|
+
return;
|
|
878
894
|
}
|
|
879
895
|
if (excludes) {
|
|
880
896
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
881
897
|
for (const exclude of excludeList) {
|
|
882
898
|
if (val.includes(exclude)) {
|
|
883
|
-
|
|
899
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
900
|
+
return;
|
|
884
901
|
}
|
|
885
902
|
}
|
|
886
903
|
}
|
|
887
904
|
if (regex) {
|
|
888
|
-
return
|
|
905
|
+
return;
|
|
889
906
|
}
|
|
890
907
|
const parsed = parseDateTimeValue(val, format, timezone2);
|
|
891
908
|
if (!parsed) {
|
|
892
909
|
const pattern = DATETIME_PATTERNS[format];
|
|
893
910
|
if (!pattern.test(val.trim())) {
|
|
894
|
-
|
|
911
|
+
ctx.addIssue({ code: "custom", message: getMessage("format", { format }) });
|
|
912
|
+
return;
|
|
895
913
|
} else {
|
|
896
|
-
|
|
914
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
915
|
+
return;
|
|
897
916
|
}
|
|
898
917
|
}
|
|
899
918
|
const hour = parsed.hour();
|
|
900
919
|
if (minHour !== void 0 && hour < minHour) {
|
|
901
|
-
|
|
920
|
+
ctx.addIssue({ code: "custom", message: getMessage("hour", { minHour, maxHour: maxHour ?? 23 }) });
|
|
921
|
+
return;
|
|
902
922
|
}
|
|
903
923
|
if (maxHour !== void 0 && hour > maxHour) {
|
|
904
|
-
|
|
924
|
+
ctx.addIssue({ code: "custom", message: getMessage("hour", { minHour: minHour ?? 0, maxHour }) });
|
|
925
|
+
return;
|
|
905
926
|
}
|
|
906
927
|
if (allowedHours && allowedHours.length > 0) {
|
|
907
928
|
if (!allowedHours.includes(hour)) {
|
|
908
|
-
|
|
929
|
+
ctx.addIssue({ code: "custom", message: getMessage("hour", { allowedHours: allowedHours.join(", ") }) });
|
|
930
|
+
return;
|
|
909
931
|
}
|
|
910
932
|
}
|
|
911
933
|
const minute = parsed.minute();
|
|
912
934
|
if (minuteStep !== void 0 && minute % minuteStep !== 0) {
|
|
913
|
-
|
|
935
|
+
ctx.addIssue({ code: "custom", message: getMessage("minute", { minuteStep }) });
|
|
936
|
+
return;
|
|
914
937
|
}
|
|
915
938
|
if (min) {
|
|
916
939
|
const minParsed = typeof min === "string" ? parseDateTimeValue(min, format, timezone2) : (0, import_dayjs2.default)(min);
|
|
917
940
|
if (minParsed && parsed.isBefore(minParsed)) {
|
|
918
941
|
const minFormatted = typeof min === "string" ? min : minParsed.format(format);
|
|
919
|
-
|
|
942
|
+
ctx.addIssue({ code: "custom", message: getMessage("min", { min: minFormatted }) });
|
|
943
|
+
return;
|
|
920
944
|
}
|
|
921
945
|
}
|
|
922
946
|
if (max) {
|
|
923
947
|
const maxParsed = typeof max === "string" ? parseDateTimeValue(max, format, timezone2) : (0, import_dayjs2.default)(max);
|
|
924
948
|
if (maxParsed && parsed.isAfter(maxParsed)) {
|
|
925
949
|
const maxFormatted = typeof max === "string" ? max : maxParsed.format(format);
|
|
926
|
-
|
|
950
|
+
ctx.addIssue({ code: "custom", message: getMessage("max", { max: maxFormatted }) });
|
|
951
|
+
return;
|
|
927
952
|
}
|
|
928
953
|
}
|
|
929
954
|
const now = timezone2 ? (0, import_dayjs2.default)().tz(timezone2) : (0, import_dayjs2.default)();
|
|
930
955
|
if (mustBePast && !parsed.isBefore(now)) {
|
|
931
|
-
|
|
956
|
+
ctx.addIssue({ code: "custom", message: getMessage("past") });
|
|
957
|
+
return;
|
|
932
958
|
}
|
|
933
959
|
if (mustBeFuture && !parsed.isAfter(now)) {
|
|
934
|
-
|
|
960
|
+
ctx.addIssue({ code: "custom", message: getMessage("future") });
|
|
961
|
+
return;
|
|
935
962
|
}
|
|
936
963
|
if (mustBeToday && !parsed.isSame(now, "day")) {
|
|
937
|
-
|
|
964
|
+
ctx.addIssue({ code: "custom", message: getMessage("today") });
|
|
965
|
+
return;
|
|
938
966
|
}
|
|
939
967
|
if (mustNotBeToday && parsed.isSame(now, "day")) {
|
|
940
|
-
|
|
968
|
+
ctx.addIssue({ code: "custom", message: getMessage("notToday") });
|
|
969
|
+
return;
|
|
941
970
|
}
|
|
942
971
|
const dayOfWeek = parsed.day();
|
|
943
972
|
if (weekdaysOnly && (dayOfWeek === 0 || dayOfWeek === 6)) {
|
|
944
|
-
|
|
973
|
+
ctx.addIssue({ code: "custom", message: getMessage("weekday") });
|
|
974
|
+
return;
|
|
945
975
|
}
|
|
946
976
|
if (weekendsOnly && dayOfWeek !== 0 && dayOfWeek !== 6) {
|
|
947
|
-
|
|
977
|
+
ctx.addIssue({ code: "custom", message: getMessage("weekend") });
|
|
978
|
+
return;
|
|
948
979
|
}
|
|
949
|
-
return true;
|
|
950
980
|
});
|
|
951
981
|
return schema;
|
|
952
982
|
}
|
|
@@ -1000,34 +1030,62 @@ function email(required, options) {
|
|
|
1000
1030
|
},
|
|
1001
1031
|
import_zod4.z.union([import_zod4.z.string().email(), import_zod4.z.null()])
|
|
1002
1032
|
);
|
|
1003
|
-
const schema = baseSchema.
|
|
1033
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
1004
1034
|
if (isRequired && val === null) {
|
|
1005
|
-
|
|
1035
|
+
ctx.addIssue({
|
|
1036
|
+
code: "custom",
|
|
1037
|
+
message: getMessage("required")
|
|
1038
|
+
});
|
|
1039
|
+
return;
|
|
1006
1040
|
}
|
|
1007
|
-
if (val === null) return
|
|
1041
|
+
if (val === null) return;
|
|
1008
1042
|
if (typeof val !== "string") {
|
|
1009
|
-
|
|
1043
|
+
ctx.addIssue({
|
|
1044
|
+
code: "custom",
|
|
1045
|
+
message: getMessage("invalid")
|
|
1046
|
+
});
|
|
1047
|
+
return;
|
|
1010
1048
|
}
|
|
1011
1049
|
if (minLength !== void 0 && val.length < minLength) {
|
|
1012
|
-
|
|
1050
|
+
ctx.addIssue({
|
|
1051
|
+
code: "custom",
|
|
1052
|
+
message: getMessage("minLength", { minLength })
|
|
1053
|
+
});
|
|
1054
|
+
return;
|
|
1013
1055
|
}
|
|
1014
1056
|
if (maxLength !== void 0 && val.length > maxLength) {
|
|
1015
|
-
|
|
1057
|
+
ctx.addIssue({
|
|
1058
|
+
code: "custom",
|
|
1059
|
+
message: getMessage("maxLength", { maxLength })
|
|
1060
|
+
});
|
|
1061
|
+
return;
|
|
1016
1062
|
}
|
|
1017
1063
|
if (includes !== void 0 && !val.includes(includes)) {
|
|
1018
|
-
|
|
1064
|
+
ctx.addIssue({
|
|
1065
|
+
code: "custom",
|
|
1066
|
+
message: getMessage("includes", { includes })
|
|
1067
|
+
});
|
|
1068
|
+
return;
|
|
1019
1069
|
}
|
|
1020
1070
|
if (excludes !== void 0) {
|
|
1021
1071
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
1022
1072
|
for (const exclude of excludeList) {
|
|
1023
1073
|
if (val.includes(exclude)) {
|
|
1024
|
-
|
|
1074
|
+
ctx.addIssue({
|
|
1075
|
+
code: "custom",
|
|
1076
|
+
message: getMessage("includes", { includes: exclude })
|
|
1077
|
+
});
|
|
1078
|
+
return;
|
|
1025
1079
|
}
|
|
1026
1080
|
}
|
|
1027
1081
|
}
|
|
1028
1082
|
const emailDomain = val.split("@")[1]?.toLowerCase();
|
|
1029
1083
|
if (!emailDomain) {
|
|
1030
|
-
|
|
1084
|
+
ctx.addIssue({
|
|
1085
|
+
code: "custom",
|
|
1086
|
+
message: getMessage("invalid")
|
|
1087
|
+
});
|
|
1088
|
+
return;
|
|
1031
1089
|
}
|
|
1032
1090
|
if (businessOnly) {
|
|
1033
1091
|
const isFreeProvider = freeEmailDomains.some((freeDomain) => {
|
|
@@ -1037,7 +1095,11 @@ function email(required, options) {
|
|
|
1037
1095
|
return emailDomain === freeDomain;
|
|
1038
1096
|
});
|
|
1039
1097
|
if (isFreeProvider) {
|
|
1040
|
-
|
|
1098
|
+
ctx.addIssue({
|
|
1099
|
+
code: "custom",
|
|
1100
|
+
message: getMessage("businessOnly")
|
|
1101
|
+
});
|
|
1102
|
+
return;
|
|
1041
1103
|
}
|
|
1042
1104
|
}
|
|
1043
1105
|
if (domainBlacklist && domainBlacklist.length > 0) {
|
|
@@ -1049,7 +1111,11 @@ function email(required, options) {
|
|
|
1049
1111
|
return emailDomain === lowerDomain;
|
|
1050
1112
|
});
|
|
1051
1113
|
if (isBlacklisted) {
|
|
1052
|
-
|
|
1114
|
+
ctx.addIssue({
|
|
1115
|
+
code: "custom",
|
|
1116
|
+
message: getMessage("domainBlacklist", { domain: emailDomain })
|
|
1117
|
+
});
|
|
1118
|
+
return;
|
|
1053
1119
|
}
|
|
1054
1120
|
}
|
|
1055
1121
|
if (domain !== void 0) {
|
|
@@ -1062,7 +1128,11 @@ function email(required, options) {
|
|
|
1062
1128
|
return emailDomain === lowerDomain;
|
|
1063
1129
|
});
|
|
1064
1130
|
if (!isAllowed) {
|
|
1065
|
-
|
|
1131
|
+
ctx.addIssue({
|
|
1132
|
+
code: "custom",
|
|
1133
|
+
message: getMessage("domain", { domain: Array.isArray(domain) ? domain.join(", ") : domain })
|
|
1134
|
+
});
|
|
1135
|
+
return;
|
|
1066
1136
|
}
|
|
1067
1137
|
}
|
|
1068
1138
|
if (noDisposable) {
|
|
@@ -1073,10 +1143,13 @@ function email(required, options) {
|
|
|
1073
1143
|
return emailDomain === disposableDomain;
|
|
1074
1144
|
});
|
|
1075
1145
|
if (isDisposable) {
|
|
1076
|
-
|
|
1146
|
+
ctx.addIssue({
|
|
1147
|
+
code: "custom",
|
|
1148
|
+
message: getMessage("noDisposable")
|
|
1149
|
+
});
|
|
1150
|
+
return;
|
|
1077
1151
|
}
|
|
1078
1152
|
}
|
|
1079
|
-
return true;
|
|
1080
1153
|
});
|
|
1081
1154
|
return schema;
|
|
1082
1155
|
}
|
|
@@ -1326,45 +1399,53 @@ function id(required, options) {
|
|
|
1326
1399
|
return processed;
|
|
1327
1400
|
};
|
|
1328
1401
|
if (isNumericType) {
|
|
1329
|
-
const numericSchema = import_zod6.z.preprocess(preprocessNumericFn, import_zod6.z.any()).
|
|
1330
|
-
if (!isRequired && val === null) return
|
|
1402
|
+
const numericSchema = import_zod6.z.preprocess(preprocessNumericFn, import_zod6.z.any()).superRefine((val, ctx) => {
|
|
1403
|
+
if (!isRequired && val === null) return;
|
|
1331
1404
|
if (val === void 0 || isRequired && val === null) {
|
|
1332
|
-
|
|
1405
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
1406
|
+
return;
|
|
1333
1407
|
}
|
|
1334
1408
|
if (typeof val !== "number" || isNaN(val)) {
|
|
1335
|
-
|
|
1409
|
+
ctx.addIssue({ code: "custom", message: getMessage("numeric") });
|
|
1410
|
+
return;
|
|
1336
1411
|
}
|
|
1337
1412
|
const strVal = String(val);
|
|
1338
1413
|
if (!ID_PATTERNS.numeric.test(strVal)) {
|
|
1339
|
-
|
|
1414
|
+
ctx.addIssue({ code: "custom", message: getMessage("numeric") });
|
|
1415
|
+
return;
|
|
1340
1416
|
}
|
|
1341
1417
|
if (minLength !== void 0 && strVal.length < minLength) {
|
|
1342
|
-
|
|
1418
|
+
ctx.addIssue({ code: "custom", message: getMessage("minLength", { minLength }) });
|
|
1419
|
+
return;
|
|
1343
1420
|
}
|
|
1344
1421
|
if (maxLength !== void 0 && strVal.length > maxLength) {
|
|
1345
|
-
|
|
1422
|
+
ctx.addIssue({ code: "custom", message: getMessage("maxLength", { maxLength }) });
|
|
1423
|
+
return;
|
|
1346
1424
|
}
|
|
1347
|
-
return true;
|
|
1348
1425
|
});
|
|
1349
1426
|
return numericSchema;
|
|
1350
1427
|
}
|
|
1351
1428
|
const baseSchema = isRequired ? import_zod6.z.preprocess(preprocessStringFn, import_zod6.z.string()) : import_zod6.z.preprocess(preprocessStringFn, import_zod6.z.string().nullable());
|
|
1352
|
-
const schema = baseSchema.
|
|
1353
|
-
if (val === null) return
|
|
1429
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
1430
|
+
if (val === null) return;
|
|
1354
1431
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1355
|
-
|
|
1432
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
1433
|
+
return;
|
|
1356
1434
|
}
|
|
1357
1435
|
const comparisonVal = !caseSensitive ? val.toLowerCase() : val;
|
|
1358
1436
|
if (val !== null && minLength !== void 0 && val.length < minLength) {
|
|
1359
|
-
|
|
1437
|
+
ctx.addIssue({ code: "custom", message: getMessage("minLength", { minLength }) });
|
|
1438
|
+
return;
|
|
1360
1439
|
}
|
|
1361
1440
|
if (val !== null && maxLength !== void 0 && val.length > maxLength) {
|
|
1362
|
-
|
|
1441
|
+
ctx.addIssue({ code: "custom", message: getMessage("maxLength", { maxLength }) });
|
|
1442
|
+
return;
|
|
1363
1443
|
}
|
|
1364
1444
|
const hasContentValidations = customRegex !== void 0 || startsWith !== void 0 || endsWith !== void 0 || includes !== void 0 || excludes !== void 0;
|
|
1365
1445
|
if (val !== null && customRegex !== void 0) {
|
|
1366
1446
|
if (!customRegex.test(val)) {
|
|
1367
|
-
|
|
1447
|
+
ctx.addIssue({ code: "custom", message: getMessage("customFormat") });
|
|
1448
|
+
return;
|
|
1368
1449
|
}
|
|
1369
1450
|
} else if (val !== null && !hasContentValidations) {
|
|
1370
1451
|
let isValidId;
|
|
@@ -1372,17 +1453,20 @@ function id(required, options) {
|
|
|
1372
1453
|
isValidId = allowedTypes.some((allowedType) => validateIdType(val, allowedType));
|
|
1373
1454
|
if (!isValidId) {
|
|
1374
1455
|
const typeNames = allowedTypes.join(", ");
|
|
1375
|
-
|
|
1456
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") + ` (allowed types: ${typeNames})` });
|
|
1457
|
+
return;
|
|
1376
1458
|
}
|
|
1377
1459
|
} else if (type && type !== "auto") {
|
|
1378
1460
|
isValidId = validateIdType(val, type);
|
|
1379
1461
|
if (!isValidId) {
|
|
1380
|
-
|
|
1462
|
+
ctx.addIssue({ code: "custom", message: getMessage(type) || getMessage("invalid") });
|
|
1463
|
+
return;
|
|
1381
1464
|
}
|
|
1382
1465
|
} else {
|
|
1383
1466
|
isValidId = detectIdType(val) !== null;
|
|
1384
1467
|
if (!isValidId) {
|
|
1385
|
-
|
|
1468
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
1469
|
+
return;
|
|
1386
1470
|
}
|
|
1387
1471
|
}
|
|
1388
1472
|
} else if (val !== null && hasContentValidations && type && type !== "auto" && !customRegex) {
|
|
@@ -1390,11 +1474,13 @@ function id(required, options) {
|
|
|
1390
1474
|
const isValidType = allowedTypes.some((allowedType) => validateIdType(val, allowedType));
|
|
1391
1475
|
if (!isValidType) {
|
|
1392
1476
|
const typeNames = allowedTypes.join(", ");
|
|
1393
|
-
|
|
1477
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") + ` (allowed types: ${typeNames})` });
|
|
1478
|
+
return;
|
|
1394
1479
|
}
|
|
1395
1480
|
} else {
|
|
1396
1481
|
if (!validateIdType(val, type)) {
|
|
1397
|
-
|
|
1482
|
+
ctx.addIssue({ code: "custom", message: getMessage(type) || getMessage("invalid") });
|
|
1483
|
+
return;
|
|
1398
1484
|
}
|
|
1399
1485
|
}
|
|
1400
1486
|
}
|
|
@@ -1402,24 +1488,27 @@ function id(required, options) {
|
|
|
1402
1488
|
const searchEndsWith = !caseSensitive && endsWith ? endsWith.toLowerCase() : endsWith;
|
|
1403
1489
|
const searchIncludes = !caseSensitive && includes ? includes.toLowerCase() : includes;
|
|
1404
1490
|
if (val !== null && startsWith !== void 0 && !comparisonVal.startsWith(searchStartsWith)) {
|
|
1405
|
-
|
|
1491
|
+
ctx.addIssue({ code: "custom", message: getMessage("startsWith", { startsWith }) });
|
|
1492
|
+
return;
|
|
1406
1493
|
}
|
|
1407
1494
|
if (val !== null && endsWith !== void 0 && !comparisonVal.endsWith(searchEndsWith)) {
|
|
1408
|
-
|
|
1495
|
+
ctx.addIssue({ code: "custom", message: getMessage("endsWith", { endsWith }) });
|
|
1496
|
+
return;
|
|
1409
1497
|
}
|
|
1410
1498
|
if (val !== null && includes !== void 0 && !comparisonVal.includes(searchIncludes)) {
|
|
1411
|
-
|
|
1499
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
1500
|
+
return;
|
|
1412
1501
|
}
|
|
1413
1502
|
if (val !== null && excludes !== void 0) {
|
|
1414
1503
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
1415
1504
|
for (const exclude of excludeList) {
|
|
1416
1505
|
const searchExclude = !caseSensitive ? exclude.toLowerCase() : exclude;
|
|
1417
1506
|
if (comparisonVal.includes(searchExclude)) {
|
|
1418
|
-
|
|
1507
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
1508
|
+
return;
|
|
1419
1509
|
}
|
|
1420
1510
|
}
|
|
1421
1511
|
}
|
|
1422
|
-
return true;
|
|
1423
1512
|
}).transform((val) => {
|
|
1424
1513
|
if (val === null) return val;
|
|
1425
1514
|
const shouldPreserveCase = type === "uuid" || type === "objectId";
|
|
@@ -1434,22 +1523,7 @@ function id(required, options) {
|
|
|
1434
1523
|
// src/validators/common/number.ts
|
|
1435
1524
|
var import_zod7 = require("zod");
|
|
1436
1525
|
function number(required, options) {
|
|
1437
|
-
const {
|
|
1438
|
-
min,
|
|
1439
|
-
max,
|
|
1440
|
-
defaultValue,
|
|
1441
|
-
type = "both",
|
|
1442
|
-
positive,
|
|
1443
|
-
negative,
|
|
1444
|
-
nonNegative,
|
|
1445
|
-
nonPositive,
|
|
1446
|
-
multipleOf,
|
|
1447
|
-
precision,
|
|
1448
|
-
finite = true,
|
|
1449
|
-
transform,
|
|
1450
|
-
parseCommas = false,
|
|
1451
|
-
i18n
|
|
1452
|
-
} = options ?? {};
|
|
1526
|
+
const { min, max, defaultValue, type = "both", positive, negative, nonNegative, nonPositive, multipleOf, precision, finite = true, transform, parseCommas = false, i18n } = options ?? {};
|
|
1453
1527
|
const isRequired = required ?? false;
|
|
1454
1528
|
const getMessage = (key, params) => {
|
|
1455
1529
|
if (i18n) {
|
|
@@ -1491,60 +1565,114 @@ function number(required, options) {
|
|
|
1491
1565
|
return val;
|
|
1492
1566
|
},
|
|
1493
1567
|
import_zod7.z.union([import_zod7.z.number(), import_zod7.z.null(), import_zod7.z.nan(), import_zod7.z.custom((val) => val === Infinity || val === -Infinity)])
|
|
1494
|
-
).
|
|
1568
|
+
).superRefine((val, ctx) => {
|
|
1495
1569
|
if (isRequired && val === null) {
|
|
1496
|
-
|
|
1570
|
+
ctx.addIssue({
|
|
1571
|
+
code: "custom",
|
|
1572
|
+
message: getMessage("required")
|
|
1573
|
+
});
|
|
1574
|
+
return;
|
|
1497
1575
|
}
|
|
1498
|
-
if (val === null) return
|
|
1499
|
-
if (
|
|
1576
|
+
if (val === null) return;
|
|
1577
|
+
if (isNaN(val)) {
|
|
1500
1578
|
if (type === "integer") {
|
|
1501
|
-
|
|
1579
|
+
ctx.addIssue({
|
|
1580
|
+
code: "custom",
|
|
1581
|
+
message: getMessage("integer")
|
|
1582
|
+
});
|
|
1502
1583
|
} else if (type === "float") {
|
|
1503
|
-
|
|
1584
|
+
ctx.addIssue({
|
|
1585
|
+
code: "custom",
|
|
1586
|
+
message: getMessage("float")
|
|
1587
|
+
});
|
|
1504
1588
|
} else {
|
|
1505
|
-
|
|
1589
|
+
ctx.addIssue({
|
|
1590
|
+
code: "custom",
|
|
1591
|
+
message: getMessage("invalid")
|
|
1592
|
+
});
|
|
1506
1593
|
}
|
|
1507
|
-
|
|
1508
|
-
if (typeof val !== "number") {
|
|
1509
|
-
throw new import_zod7.z.ZodError([{ code: "custom", message: getMessage("invalid"), path: [] }]);
|
|
1594
|
+
return;
|
|
1510
1595
|
}
|
|
1511
1596
|
if (finite && !Number.isFinite(val)) {
|
|
1512
|
-
|
|
1597
|
+
ctx.addIssue({
|
|
1598
|
+
code: "custom",
|
|
1599
|
+
message: getMessage("finite")
|
|
1600
|
+
});
|
|
1601
|
+
return;
|
|
1513
1602
|
}
|
|
1514
1603
|
if (type === "integer" && !Number.isInteger(val)) {
|
|
1515
|
-
|
|
1604
|
+
ctx.addIssue({
|
|
1605
|
+
code: "custom",
|
|
1606
|
+
message: getMessage("integer")
|
|
1607
|
+
});
|
|
1608
|
+
return;
|
|
1516
1609
|
}
|
|
1517
1610
|
if (type === "float" && Number.isInteger(val)) {
|
|
1518
|
-
|
|
1611
|
+
ctx.addIssue({
|
|
1612
|
+
code: "custom",
|
|
1613
|
+
message: getMessage("float")
|
|
1614
|
+
});
|
|
1615
|
+
return;
|
|
1519
1616
|
}
|
|
1520
1617
|
if (positive && val <= 0) {
|
|
1521
|
-
|
|
1618
|
+
ctx.addIssue({
|
|
1619
|
+
code: "custom",
|
|
1620
|
+
message: getMessage("positive")
|
|
1621
|
+
});
|
|
1622
|
+
return;
|
|
1522
1623
|
}
|
|
1523
1624
|
if (negative && val >= 0) {
|
|
1524
|
-
|
|
1625
|
+
ctx.addIssue({
|
|
1626
|
+
code: "custom",
|
|
1627
|
+
message: getMessage("negative")
|
|
1628
|
+
});
|
|
1629
|
+
return;
|
|
1525
1630
|
}
|
|
1526
1631
|
if (nonNegative && val < 0) {
|
|
1527
|
-
|
|
1632
|
+
ctx.addIssue({
|
|
1633
|
+
code: "custom",
|
|
1634
|
+
message: getMessage("nonNegative")
|
|
1635
|
+
});
|
|
1636
|
+
return;
|
|
1528
1637
|
}
|
|
1529
1638
|
if (nonPositive && val > 0) {
|
|
1530
|
-
|
|
1639
|
+
ctx.addIssue({
|
|
1640
|
+
code: "custom",
|
|
1641
|
+
message: getMessage("nonPositive")
|
|
1642
|
+
});
|
|
1643
|
+
return;
|
|
1531
1644
|
}
|
|
1532
1645
|
if (min !== void 0 && val < min) {
|
|
1533
|
-
|
|
1646
|
+
ctx.addIssue({
|
|
1647
|
+
code: "custom",
|
|
1648
|
+
message: getMessage("min", { min })
|
|
1649
|
+
});
|
|
1650
|
+
return;
|
|
1534
1651
|
}
|
|
1535
1652
|
if (max !== void 0 && val > max) {
|
|
1536
|
-
|
|
1653
|
+
ctx.addIssue({
|
|
1654
|
+
code: "custom",
|
|
1655
|
+
message: getMessage("max", { max })
|
|
1656
|
+
});
|
|
1657
|
+
return;
|
|
1537
1658
|
}
|
|
1538
1659
|
if (multipleOf !== void 0 && val % multipleOf !== 0) {
|
|
1539
|
-
|
|
1660
|
+
ctx.addIssue({
|
|
1661
|
+
code: "custom",
|
|
1662
|
+
message: getMessage("multipleOf", { multipleOf })
|
|
1663
|
+
});
|
|
1664
|
+
return;
|
|
1540
1665
|
}
|
|
1541
1666
|
if (precision !== void 0) {
|
|
1542
1667
|
const decimalPlaces = (val.toString().split(".")[1] || "").length;
|
|
1543
1668
|
if (decimalPlaces > precision) {
|
|
1544
|
-
|
|
1669
|
+
ctx.addIssue({
|
|
1670
|
+
code: "custom",
|
|
1671
|
+
message: getMessage("precision", { precision })
|
|
1672
|
+
});
|
|
1673
|
+
return;
|
|
1545
1674
|
}
|
|
1546
1675
|
}
|
|
1547
|
-
return true;
|
|
1548
1676
|
});
|
|
1549
1677
|
return schema;
|
|
1550
1678
|
}
|
|
@@ -1628,37 +1756,47 @@ function password(required, options) {
|
|
|
1628
1756
|
return processed;
|
|
1629
1757
|
};
|
|
1630
1758
|
const baseSchema = isRequired ? import_zod8.z.preprocess(preprocessFn, import_zod8.z.string()) : import_zod8.z.preprocess(preprocessFn, import_zod8.z.string().nullable());
|
|
1631
|
-
const schema = baseSchema.
|
|
1632
|
-
if (val === null) return
|
|
1759
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
1760
|
+
if (val === null) return;
|
|
1633
1761
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1634
|
-
|
|
1762
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
1763
|
+
return;
|
|
1635
1764
|
}
|
|
1636
1765
|
if (val !== null && min !== void 0 && val.length < min) {
|
|
1637
|
-
|
|
1766
|
+
ctx.addIssue({ code: "custom", message: getMessage("min", { min }) });
|
|
1767
|
+
return;
|
|
1638
1768
|
}
|
|
1639
1769
|
if (val !== null && max !== void 0 && val.length > max) {
|
|
1640
|
-
|
|
1770
|
+
ctx.addIssue({ code: "custom", message: getMessage("max", { max }) });
|
|
1771
|
+
return;
|
|
1641
1772
|
}
|
|
1642
1773
|
if (val !== null && uppercase && !/[A-Z]/.test(val)) {
|
|
1643
|
-
|
|
1774
|
+
ctx.addIssue({ code: "custom", message: getMessage("uppercase") });
|
|
1775
|
+
return;
|
|
1644
1776
|
}
|
|
1645
1777
|
if (val !== null && lowercase && !/[a-z]/.test(val)) {
|
|
1646
|
-
|
|
1778
|
+
ctx.addIssue({ code: "custom", message: getMessage("lowercase") });
|
|
1779
|
+
return;
|
|
1647
1780
|
}
|
|
1648
1781
|
if (val !== null && digits && !/[0-9]/.test(val)) {
|
|
1649
|
-
|
|
1782
|
+
ctx.addIssue({ code: "custom", message: getMessage("digits") });
|
|
1783
|
+
return;
|
|
1650
1784
|
}
|
|
1651
1785
|
if (val !== null && special && !/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(val)) {
|
|
1652
|
-
|
|
1786
|
+
ctx.addIssue({ code: "custom", message: getMessage("special") });
|
|
1787
|
+
return;
|
|
1653
1788
|
}
|
|
1654
1789
|
if (val !== null && noRepeating && /(.)\1{2,}/.test(val)) {
|
|
1655
|
-
|
|
1790
|
+
ctx.addIssue({ code: "custom", message: getMessage("noRepeating") });
|
|
1791
|
+
return;
|
|
1656
1792
|
}
|
|
1657
1793
|
if (val !== null && noSequential && /(?:abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)/i.test(val)) {
|
|
1658
|
-
|
|
1794
|
+
ctx.addIssue({ code: "custom", message: getMessage("noSequential") });
|
|
1795
|
+
return;
|
|
1659
1796
|
}
|
|
1660
1797
|
if (val !== null && noCommonWords && COMMON_PASSWORDS.some((common) => val.toLowerCase().includes(common.toLowerCase()))) {
|
|
1661
|
-
|
|
1798
|
+
ctx.addIssue({ code: "custom", message: getMessage("noCommonWords") });
|
|
1799
|
+
return;
|
|
1662
1800
|
}
|
|
1663
1801
|
if (val !== null && minStrength) {
|
|
1664
1802
|
const strength = calculatePasswordStrength(val);
|
|
@@ -1666,24 +1804,27 @@ function password(required, options) {
|
|
|
1666
1804
|
const currentLevel = strengthLevels.indexOf(strength);
|
|
1667
1805
|
const requiredLevel = strengthLevels.indexOf(minStrength);
|
|
1668
1806
|
if (currentLevel < requiredLevel) {
|
|
1669
|
-
|
|
1807
|
+
ctx.addIssue({ code: "custom", message: getMessage("minStrength", { minStrength }) });
|
|
1808
|
+
return;
|
|
1670
1809
|
}
|
|
1671
1810
|
}
|
|
1672
1811
|
if (val !== null && includes !== void 0 && !val.includes(includes)) {
|
|
1673
|
-
|
|
1812
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
1813
|
+
return;
|
|
1674
1814
|
}
|
|
1675
1815
|
if (val !== null && excludes !== void 0) {
|
|
1676
1816
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
1677
1817
|
for (const exclude of excludeList) {
|
|
1678
1818
|
if (val.includes(exclude)) {
|
|
1679
|
-
|
|
1819
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
1820
|
+
return;
|
|
1680
1821
|
}
|
|
1681
1822
|
}
|
|
1682
1823
|
}
|
|
1683
1824
|
if (val !== null && regex !== void 0 && !regex.test(val)) {
|
|
1684
|
-
|
|
1825
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid", { regex }) });
|
|
1826
|
+
return;
|
|
1685
1827
|
}
|
|
1686
|
-
return true;
|
|
1687
1828
|
});
|
|
1688
1829
|
return schema;
|
|
1689
1830
|
}
|
|
@@ -1742,41 +1883,76 @@ function text(required, options) {
|
|
|
1742
1883
|
return processed;
|
|
1743
1884
|
};
|
|
1744
1885
|
const baseSchema = isRequired ? import_zod9.z.preprocess(preprocessFn, import_zod9.z.string()) : import_zod9.z.preprocess(preprocessFn, import_zod9.z.string().nullable());
|
|
1745
|
-
const schema = baseSchema.
|
|
1746
|
-
if (val === null) return
|
|
1886
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
1887
|
+
if (val === null) return;
|
|
1747
1888
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1748
|
-
|
|
1889
|
+
ctx.addIssue({
|
|
1890
|
+
code: "custom",
|
|
1891
|
+
message: getMessage("required")
|
|
1892
|
+
});
|
|
1893
|
+
return;
|
|
1749
1894
|
}
|
|
1750
1895
|
if (notEmpty && val !== null && val.trim() === "") {
|
|
1751
|
-
|
|
1896
|
+
ctx.addIssue({
|
|
1897
|
+
code: "custom",
|
|
1898
|
+
message: getMessage("notEmpty")
|
|
1899
|
+
});
|
|
1900
|
+
return;
|
|
1752
1901
|
}
|
|
1753
1902
|
if (val !== null && minLength !== void 0 && val.length < minLength) {
|
|
1754
|
-
|
|
1903
|
+
ctx.addIssue({
|
|
1904
|
+
code: "custom",
|
|
1905
|
+
message: getMessage("minLength", { minLength })
|
|
1906
|
+
});
|
|
1907
|
+
return;
|
|
1755
1908
|
}
|
|
1756
1909
|
if (val !== null && maxLength !== void 0 && val.length > maxLength) {
|
|
1757
|
-
|
|
1910
|
+
ctx.addIssue({
|
|
1911
|
+
code: "custom",
|
|
1912
|
+
message: getMessage("maxLength", { maxLength })
|
|
1913
|
+
});
|
|
1914
|
+
return;
|
|
1758
1915
|
}
|
|
1759
1916
|
if (val !== null && startsWith !== void 0 && !val.startsWith(startsWith)) {
|
|
1760
|
-
|
|
1917
|
+
ctx.addIssue({
|
|
1918
|
+
code: "custom",
|
|
1919
|
+
message: getMessage("startsWith", { startsWith })
|
|
1920
|
+
});
|
|
1921
|
+
return;
|
|
1761
1922
|
}
|
|
1762
1923
|
if (val !== null && endsWith !== void 0 && !val.endsWith(endsWith)) {
|
|
1763
|
-
|
|
1924
|
+
ctx.addIssue({
|
|
1925
|
+
code: "custom",
|
|
1926
|
+
message: getMessage("endsWith", { endsWith })
|
|
1927
|
+
});
|
|
1928
|
+
return;
|
|
1764
1929
|
}
|
|
1765
1930
|
if (val !== null && includes !== void 0 && !val.includes(includes)) {
|
|
1766
|
-
|
|
1931
|
+
ctx.addIssue({
|
|
1932
|
+
code: "custom",
|
|
1933
|
+
message: getMessage("includes", { includes })
|
|
1934
|
+
});
|
|
1935
|
+
return;
|
|
1767
1936
|
}
|
|
1768
1937
|
if (val !== null && excludes !== void 0) {
|
|
1769
1938
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
1770
1939
|
for (const exclude of excludeList) {
|
|
1771
1940
|
if (val.includes(exclude)) {
|
|
1772
|
-
|
|
1941
|
+
ctx.addIssue({
|
|
1942
|
+
code: "custom",
|
|
1943
|
+
message: getMessage("excludes", { excludes: exclude })
|
|
1944
|
+
});
|
|
1945
|
+
return;
|
|
1773
1946
|
}
|
|
1774
1947
|
}
|
|
1775
1948
|
}
|
|
1776
1949
|
if (val !== null && regex !== void 0 && !regex.test(val)) {
|
|
1777
|
-
|
|
1950
|
+
ctx.addIssue({
|
|
1951
|
+
code: "custom",
|
|
1952
|
+
message: getMessage("invalid", { regex })
|
|
1953
|
+
});
|
|
1954
|
+
return;
|
|
1778
1955
|
}
|
|
1779
|
-
return true;
|
|
1780
1956
|
});
|
|
1781
1957
|
return schema;
|
|
1782
1958
|
}
|
|
@@ -1929,86 +2105,99 @@ function time(required, options) {
|
|
|
1929
2105
|
return processed;
|
|
1930
2106
|
};
|
|
1931
2107
|
const baseSchema = isRequired ? import_zod10.z.preprocess(preprocessFn, import_zod10.z.string()) : import_zod10.z.preprocess(preprocessFn, import_zod10.z.string().nullable());
|
|
1932
|
-
const schema = baseSchema.
|
|
1933
|
-
if (val === null) return
|
|
2108
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
2109
|
+
if (val === null) return;
|
|
1934
2110
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1935
|
-
|
|
2111
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
2112
|
+
return;
|
|
1936
2113
|
}
|
|
1937
|
-
if (val === null) return
|
|
1938
|
-
if (!isRequired && val === "") return
|
|
2114
|
+
if (val === null) return;
|
|
2115
|
+
if (!isRequired && val === "") return;
|
|
1939
2116
|
if (whitelist && whitelist.length > 0) {
|
|
1940
2117
|
if (whitelist.includes(val)) {
|
|
1941
|
-
return
|
|
2118
|
+
return;
|
|
1942
2119
|
}
|
|
1943
2120
|
if (whitelistOnly) {
|
|
1944
|
-
|
|
2121
|
+
ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
|
|
2122
|
+
return;
|
|
1945
2123
|
}
|
|
1946
2124
|
}
|
|
1947
2125
|
if (regex) {
|
|
1948
2126
|
if (!regex.test(val)) {
|
|
1949
|
-
|
|
2127
|
+
ctx.addIssue({ code: "custom", message: getMessage("customRegex") });
|
|
2128
|
+
return;
|
|
1950
2129
|
}
|
|
1951
2130
|
} else {
|
|
1952
2131
|
if (!validateTimeFormat(val, format)) {
|
|
1953
|
-
|
|
2132
|
+
ctx.addIssue({ code: "custom", message: getMessage("format", { format }) });
|
|
2133
|
+
return;
|
|
1954
2134
|
}
|
|
1955
2135
|
}
|
|
1956
2136
|
if (includes && !val.includes(includes)) {
|
|
1957
|
-
|
|
2137
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
2138
|
+
return;
|
|
1958
2139
|
}
|
|
1959
2140
|
if (excludes) {
|
|
1960
2141
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
1961
2142
|
for (const exclude of excludeList) {
|
|
1962
2143
|
if (val.includes(exclude)) {
|
|
1963
|
-
|
|
2144
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
2145
|
+
return;
|
|
1964
2146
|
}
|
|
1965
2147
|
}
|
|
1966
2148
|
}
|
|
1967
2149
|
if (regex) {
|
|
1968
|
-
return
|
|
2150
|
+
return;
|
|
1969
2151
|
}
|
|
1970
2152
|
const timeMinutes = parseTimeToMinutes(val, format);
|
|
1971
2153
|
if (timeMinutes === null) {
|
|
1972
|
-
|
|
2154
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
2155
|
+
return;
|
|
1973
2156
|
}
|
|
1974
2157
|
const hour = Math.floor(timeMinutes / 60);
|
|
1975
2158
|
if (minHour !== void 0 && hour < minHour) {
|
|
1976
|
-
|
|
2159
|
+
ctx.addIssue({ code: "custom", message: getMessage("hour", { minHour, maxHour: maxHour ?? 23 }) });
|
|
2160
|
+
return;
|
|
1977
2161
|
}
|
|
1978
2162
|
if (maxHour !== void 0 && hour > maxHour) {
|
|
1979
|
-
|
|
2163
|
+
ctx.addIssue({ code: "custom", message: getMessage("hour", { minHour: minHour ?? 0, maxHour }) });
|
|
2164
|
+
return;
|
|
1980
2165
|
}
|
|
1981
2166
|
if (allowedHours && allowedHours.length > 0) {
|
|
1982
2167
|
if (!allowedHours.includes(hour)) {
|
|
1983
|
-
|
|
2168
|
+
ctx.addIssue({ code: "custom", message: getMessage("hour", { allowedHours: allowedHours.join(", ") }) });
|
|
2169
|
+
return;
|
|
1984
2170
|
}
|
|
1985
2171
|
}
|
|
1986
2172
|
const minute = timeMinutes % 60;
|
|
1987
2173
|
if (minuteStep !== void 0 && minute % minuteStep !== 0) {
|
|
1988
|
-
|
|
2174
|
+
ctx.addIssue({ code: "custom", message: getMessage("minute", { minuteStep }) });
|
|
2175
|
+
return;
|
|
1989
2176
|
}
|
|
1990
2177
|
if (secondStep !== void 0 && format.includes("ss")) {
|
|
1991
2178
|
const secondMatch = val.match(/:(\d{2})$/);
|
|
1992
2179
|
if (secondMatch) {
|
|
1993
2180
|
const seconds = parseInt(secondMatch[1], 10);
|
|
1994
2181
|
if (seconds % secondStep !== 0) {
|
|
1995
|
-
|
|
2182
|
+
ctx.addIssue({ code: "custom", message: getMessage("second", { secondStep }) });
|
|
2183
|
+
return;
|
|
1996
2184
|
}
|
|
1997
2185
|
}
|
|
1998
2186
|
}
|
|
1999
2187
|
if (min) {
|
|
2000
2188
|
const minMinutes = parseTimeToMinutes(min, format);
|
|
2001
2189
|
if (minMinutes !== null && timeMinutes < minMinutes) {
|
|
2002
|
-
|
|
2190
|
+
ctx.addIssue({ code: "custom", message: getMessage("min", { min }) });
|
|
2191
|
+
return;
|
|
2003
2192
|
}
|
|
2004
2193
|
}
|
|
2005
2194
|
if (max) {
|
|
2006
2195
|
const maxMinutes = parseTimeToMinutes(max, format);
|
|
2007
2196
|
if (maxMinutes !== null && timeMinutes > maxMinutes) {
|
|
2008
|
-
|
|
2197
|
+
ctx.addIssue({ code: "custom", message: getMessage("max", { max }) });
|
|
2198
|
+
return;
|
|
2009
2199
|
}
|
|
2010
2200
|
}
|
|
2011
|
-
return true;
|
|
2012
2201
|
});
|
|
2013
2202
|
return schema;
|
|
2014
2203
|
}
|
|
@@ -2062,78 +2251,96 @@ function url(required, options) {
|
|
|
2062
2251
|
return processed;
|
|
2063
2252
|
};
|
|
2064
2253
|
const baseSchema = isRequired ? import_zod11.z.preprocess(preprocessFn, import_zod11.z.string()) : import_zod11.z.preprocess(preprocessFn, import_zod11.z.string().nullable());
|
|
2065
|
-
const schema = baseSchema.
|
|
2066
|
-
if (val === null) return
|
|
2254
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
2255
|
+
if (val === null) return;
|
|
2067
2256
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2068
|
-
|
|
2257
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
2258
|
+
return;
|
|
2069
2259
|
}
|
|
2070
2260
|
let urlObj;
|
|
2071
2261
|
try {
|
|
2072
2262
|
urlObj = new URL(val);
|
|
2073
2263
|
} catch {
|
|
2074
|
-
|
|
2264
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
2265
|
+
return;
|
|
2075
2266
|
}
|
|
2076
2267
|
if (val !== null && min !== void 0 && val.length < min) {
|
|
2077
|
-
|
|
2268
|
+
ctx.addIssue({ code: "custom", message: getMessage("min", { min }) });
|
|
2269
|
+
return;
|
|
2078
2270
|
}
|
|
2079
2271
|
if (val !== null && max !== void 0 && val.length > max) {
|
|
2080
|
-
|
|
2272
|
+
ctx.addIssue({ code: "custom", message: getMessage("max", { max }) });
|
|
2273
|
+
return;
|
|
2081
2274
|
}
|
|
2082
2275
|
if (val !== null && includes !== void 0 && !val.includes(includes)) {
|
|
2083
|
-
|
|
2276
|
+
ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
|
|
2277
|
+
return;
|
|
2084
2278
|
}
|
|
2085
2279
|
if (val !== null && excludes !== void 0) {
|
|
2086
2280
|
const excludeList = Array.isArray(excludes) ? excludes : [excludes];
|
|
2087
2281
|
for (const exclude of excludeList) {
|
|
2088
2282
|
if (val.includes(exclude)) {
|
|
2089
|
-
|
|
2283
|
+
ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
|
|
2284
|
+
return;
|
|
2090
2285
|
}
|
|
2091
2286
|
}
|
|
2092
2287
|
}
|
|
2093
2288
|
if (protocols && !protocols.includes(urlObj.protocol.slice(0, -1))) {
|
|
2094
|
-
|
|
2289
|
+
ctx.addIssue({ code: "custom", message: getMessage("protocol", { protocols: protocols.join(", ") }) });
|
|
2290
|
+
return;
|
|
2095
2291
|
}
|
|
2096
2292
|
const hostname = urlObj.hostname.toLowerCase();
|
|
2097
2293
|
if (allowedDomains && !allowedDomains.some((domain) => hostname === domain || hostname.endsWith(`.${domain}`))) {
|
|
2098
|
-
|
|
2294
|
+
ctx.addIssue({ code: "custom", message: getMessage("domain", { domains: allowedDomains.join(", ") }) });
|
|
2295
|
+
return;
|
|
2099
2296
|
}
|
|
2100
2297
|
if (blockedDomains && blockedDomains.some((domain) => hostname === domain || hostname.endsWith(`.${domain}`))) {
|
|
2101
2298
|
const blockedDomain = blockedDomains.find((domain) => hostname === domain || hostname.endsWith(`.${domain}`));
|
|
2102
|
-
|
|
2299
|
+
ctx.addIssue({ code: "custom", message: getMessage("domainBlacklist", { domain: blockedDomain }) });
|
|
2300
|
+
return;
|
|
2103
2301
|
}
|
|
2104
2302
|
const port = urlObj.port ? parseInt(urlObj.port) : urlObj.protocol === "https:" ? 443 : 80;
|
|
2105
2303
|
if (allowedPorts && !allowedPorts.includes(port)) {
|
|
2106
|
-
|
|
2304
|
+
ctx.addIssue({ code: "custom", message: getMessage("port", { ports: allowedPorts.join(", ") }) });
|
|
2305
|
+
return;
|
|
2107
2306
|
}
|
|
2108
2307
|
if (blockedPorts && blockedPorts.includes(port)) {
|
|
2109
|
-
|
|
2308
|
+
ctx.addIssue({ code: "custom", message: getMessage("port", { port }) });
|
|
2309
|
+
return;
|
|
2110
2310
|
}
|
|
2111
2311
|
if (pathStartsWith && !urlObj.pathname.startsWith(pathStartsWith)) {
|
|
2112
|
-
|
|
2312
|
+
ctx.addIssue({ code: "custom", message: getMessage("pathStartsWith", { path: pathStartsWith }) });
|
|
2313
|
+
return;
|
|
2113
2314
|
}
|
|
2114
2315
|
if (pathEndsWith && !urlObj.pathname.endsWith(pathEndsWith)) {
|
|
2115
|
-
|
|
2316
|
+
ctx.addIssue({ code: "custom", message: getMessage("pathEndsWith", { path: pathEndsWith }) });
|
|
2317
|
+
return;
|
|
2116
2318
|
}
|
|
2117
2319
|
if (mustHaveQuery && !urlObj.search) {
|
|
2118
|
-
|
|
2320
|
+
ctx.addIssue({ code: "custom", message: getMessage("hasQuery") });
|
|
2321
|
+
return;
|
|
2119
2322
|
}
|
|
2120
2323
|
if (mustNotHaveQuery && urlObj.search) {
|
|
2121
|
-
|
|
2324
|
+
ctx.addIssue({ code: "custom", message: getMessage("noQuery") });
|
|
2325
|
+
return;
|
|
2122
2326
|
}
|
|
2123
2327
|
if (mustHaveFragment && !urlObj.hash) {
|
|
2124
|
-
|
|
2328
|
+
ctx.addIssue({ code: "custom", message: getMessage("hasFragment") });
|
|
2329
|
+
return;
|
|
2125
2330
|
}
|
|
2126
2331
|
if (mustNotHaveFragment && urlObj.hash) {
|
|
2127
|
-
|
|
2332
|
+
ctx.addIssue({ code: "custom", message: getMessage("noFragment") });
|
|
2333
|
+
return;
|
|
2128
2334
|
}
|
|
2129
2335
|
const isLocalhost = hostname === "localhost" || hostname === "127.0.0.1" || hostname.startsWith("192.168.") || hostname.startsWith("10.") || hostname.match(/^172\.(1[6-9]|2[0-9]|3[0-1])\./);
|
|
2130
2336
|
if (blockLocalhost && isLocalhost) {
|
|
2131
|
-
|
|
2337
|
+
ctx.addIssue({ code: "custom", message: getMessage("noLocalhost") });
|
|
2338
|
+
return;
|
|
2132
2339
|
}
|
|
2133
2340
|
if (!allowLocalhost && isLocalhost) {
|
|
2134
|
-
|
|
2341
|
+
ctx.addIssue({ code: "custom", message: getMessage("localhost") });
|
|
2342
|
+
return;
|
|
2135
2343
|
}
|
|
2136
|
-
return true;
|
|
2137
2344
|
});
|
|
2138
2345
|
return schema;
|
|
2139
2346
|
}
|
|
@@ -2171,12 +2378,8 @@ var validateTaiwanBusinessId = (value) => {
|
|
|
2171
2378
|
}
|
|
2172
2379
|
return false;
|
|
2173
2380
|
};
|
|
2174
|
-
function
|
|
2175
|
-
const {
|
|
2176
|
-
transform,
|
|
2177
|
-
defaultValue,
|
|
2178
|
-
i18n
|
|
2179
|
-
} = options ?? {};
|
|
2381
|
+
function twBusinessId(required, options) {
|
|
2382
|
+
const { transform, defaultValue, i18n } = options ?? {};
|
|
2180
2383
|
const isRequired = required ?? false;
|
|
2181
2384
|
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
2182
2385
|
const getMessage = (key, params) => {
|
|
@@ -2204,17 +2407,18 @@ function businessId(required, options) {
|
|
|
2204
2407
|
return processed;
|
|
2205
2408
|
};
|
|
2206
2409
|
const baseSchema = isRequired ? import_zod12.z.preprocess(preprocessFn, import_zod12.z.string()) : import_zod12.z.preprocess(preprocessFn, import_zod12.z.string().nullable());
|
|
2207
|
-
const schema = baseSchema.
|
|
2208
|
-
if (val === null) return
|
|
2410
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
2411
|
+
if (val === null) return;
|
|
2209
2412
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2210
|
-
|
|
2413
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
2414
|
+
return;
|
|
2211
2415
|
}
|
|
2212
|
-
if (val === null) return
|
|
2213
|
-
if (!isRequired && val === "") return
|
|
2416
|
+
if (val === null) return;
|
|
2417
|
+
if (!isRequired && val === "") return;
|
|
2214
2418
|
if (!validateTaiwanBusinessId(val)) {
|
|
2215
|
-
|
|
2419
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
2420
|
+
return;
|
|
2216
2421
|
}
|
|
2217
|
-
return true;
|
|
2218
2422
|
});
|
|
2219
2423
|
return schema;
|
|
2220
2424
|
}
|
|
@@ -2317,7 +2521,7 @@ var validateTaiwanNationalId = (value, type = "both", allowOldResident = true) =
|
|
|
2317
2521
|
return false;
|
|
2318
2522
|
}
|
|
2319
2523
|
};
|
|
2320
|
-
function
|
|
2524
|
+
function twNationalId(required, options) {
|
|
2321
2525
|
const {
|
|
2322
2526
|
type = "both",
|
|
2323
2527
|
allowOldResident = true,
|
|
@@ -2352,17 +2556,18 @@ function nationalId(required, options) {
|
|
|
2352
2556
|
return processed;
|
|
2353
2557
|
};
|
|
2354
2558
|
const baseSchema = isRequired ? import_zod13.z.preprocess(preprocessFn, import_zod13.z.string()) : import_zod13.z.preprocess(preprocessFn, import_zod13.z.string().nullable());
|
|
2355
|
-
const schema = baseSchema.
|
|
2356
|
-
if (val === null) return
|
|
2559
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
2560
|
+
if (val === null) return;
|
|
2357
2561
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2358
|
-
|
|
2562
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
2563
|
+
return;
|
|
2359
2564
|
}
|
|
2360
|
-
if (val === null) return
|
|
2361
|
-
if (!isRequired && val === "") return
|
|
2565
|
+
if (val === null) return;
|
|
2566
|
+
if (!isRequired && val === "") return;
|
|
2362
2567
|
if (!validateTaiwanNationalId(val, type, allowOldResident)) {
|
|
2363
|
-
|
|
2568
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
2569
|
+
return;
|
|
2364
2570
|
}
|
|
2365
|
-
return true;
|
|
2366
2571
|
});
|
|
2367
2572
|
return schema;
|
|
2368
2573
|
}
|
|
@@ -2372,7 +2577,7 @@ var import_zod14 = require("zod");
|
|
|
2372
2577
|
var validateTaiwanMobile = (value) => {
|
|
2373
2578
|
return /^09[0-9]\d{7}$/.test(value);
|
|
2374
2579
|
};
|
|
2375
|
-
function
|
|
2580
|
+
function twMobile(required, options) {
|
|
2376
2581
|
const { whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
2377
2582
|
const isRequired = required ?? false;
|
|
2378
2583
|
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
@@ -2407,23 +2612,25 @@ function mobile(required, options) {
|
|
|
2407
2612
|
return processed;
|
|
2408
2613
|
};
|
|
2409
2614
|
const baseSchema = isRequired ? import_zod14.z.preprocess(preprocessFn, import_zod14.z.string()) : import_zod14.z.preprocess(preprocessFn, import_zod14.z.string().nullable());
|
|
2410
|
-
const schema = baseSchema.
|
|
2411
|
-
if (val === null) return
|
|
2615
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
2616
|
+
if (val === null) return;
|
|
2412
2617
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2413
|
-
|
|
2618
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
2619
|
+
return;
|
|
2414
2620
|
}
|
|
2415
|
-
if (val === null) return
|
|
2416
|
-
if (!isRequired && val === "") return
|
|
2621
|
+
if (val === null) return;
|
|
2622
|
+
if (!isRequired && val === "") return;
|
|
2417
2623
|
if (whitelist && whitelist.length > 0) {
|
|
2418
2624
|
if (whitelist.includes(val)) {
|
|
2419
|
-
return
|
|
2625
|
+
return;
|
|
2420
2626
|
}
|
|
2421
|
-
|
|
2627
|
+
ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
|
|
2628
|
+
return;
|
|
2422
2629
|
}
|
|
2423
2630
|
if (!validateTaiwanMobile(val)) {
|
|
2424
|
-
|
|
2631
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
2632
|
+
return;
|
|
2425
2633
|
}
|
|
2426
|
-
return true;
|
|
2427
2634
|
});
|
|
2428
2635
|
return schema;
|
|
2429
2636
|
}
|
|
@@ -3010,7 +3217,7 @@ var validateTaiwanPostalCode = (value, format = "3+6", strictValidation = true,
|
|
|
3010
3217
|
return false;
|
|
3011
3218
|
}
|
|
3012
3219
|
};
|
|
3013
|
-
function
|
|
3220
|
+
function twPostalCode(required, options) {
|
|
3014
3221
|
const {
|
|
3015
3222
|
format = "3+6",
|
|
3016
3223
|
strictValidation = true,
|
|
@@ -3054,25 +3261,30 @@ function postalCode(required, options) {
|
|
|
3054
3261
|
return processed;
|
|
3055
3262
|
};
|
|
3056
3263
|
const baseSchema = isRequired ? import_zod15.z.preprocess(preprocessFn, import_zod15.z.string()) : import_zod15.z.preprocess(preprocessFn, import_zod15.z.string().nullable());
|
|
3057
|
-
const schema = baseSchema.
|
|
3058
|
-
if (val === null) return
|
|
3264
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
3265
|
+
if (val === null) return;
|
|
3059
3266
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
3060
|
-
|
|
3267
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
3268
|
+
return;
|
|
3061
3269
|
}
|
|
3062
|
-
if (val === null) return
|
|
3063
|
-
if (!isRequired && val === "") return
|
|
3270
|
+
if (val === null) return;
|
|
3271
|
+
if (!isRequired && val === "") return;
|
|
3064
3272
|
const cleanValue = val.replace(/[-\s]/g, "");
|
|
3065
3273
|
if (format === "3" && cleanValue.length !== 3) {
|
|
3066
|
-
|
|
3274
|
+
ctx.addIssue({ code: "custom", message: getMessage("format3Only") });
|
|
3275
|
+
return;
|
|
3067
3276
|
}
|
|
3068
3277
|
if (format === "5" && cleanValue.length !== 5) {
|
|
3069
|
-
|
|
3278
|
+
ctx.addIssue({ code: "custom", message: getMessage("format5Only") });
|
|
3279
|
+
return;
|
|
3070
3280
|
}
|
|
3071
3281
|
if (format === "6" && cleanValue.length !== 6) {
|
|
3072
|
-
|
|
3282
|
+
ctx.addIssue({ code: "custom", message: getMessage("format6Only") });
|
|
3283
|
+
return;
|
|
3073
3284
|
}
|
|
3074
3285
|
if (deprecate5Digit && cleanValue.length === 5) {
|
|
3075
|
-
|
|
3286
|
+
ctx.addIssue({ code: "custom", message: getMessage("deprecated5Digit") });
|
|
3287
|
+
return;
|
|
3076
3288
|
}
|
|
3077
3289
|
if (strictSuffixValidation) {
|
|
3078
3290
|
if (cleanValue.length === 5) {
|
|
@@ -3081,7 +3293,8 @@ function postalCode(required, options) {
|
|
|
3081
3293
|
const suffixNum = parseInt(suffix, 10);
|
|
3082
3294
|
const ranges = getPostalCodeRanges(prefix);
|
|
3083
3295
|
if (suffixNum < ranges.range5[0] || suffixNum > ranges.range5[1]) {
|
|
3084
|
-
|
|
3296
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalidSuffix") });
|
|
3297
|
+
return;
|
|
3085
3298
|
}
|
|
3086
3299
|
} else if (cleanValue.length === 6) {
|
|
3087
3300
|
const prefix = cleanValue.substring(0, 3);
|
|
@@ -3089,17 +3302,18 @@ function postalCode(required, options) {
|
|
|
3089
3302
|
const suffixNum = parseInt(suffix, 10);
|
|
3090
3303
|
const ranges = getPostalCodeRanges(prefix);
|
|
3091
3304
|
if (suffixNum < ranges.range6[0] || suffixNum > ranges.range6[1]) {
|
|
3092
|
-
|
|
3305
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalidSuffix") });
|
|
3306
|
+
return;
|
|
3093
3307
|
}
|
|
3094
3308
|
}
|
|
3095
3309
|
}
|
|
3096
3310
|
if (!validateTaiwanPostalCode(val, format, strictValidation, strictSuffixValidation, allowDashes, allowedPrefixes, blockedPrefixes)) {
|
|
3097
|
-
|
|
3311
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
3312
|
+
return;
|
|
3098
3313
|
}
|
|
3099
3314
|
if (warn5Digit && cleanValue.length === 5 && format !== "5" && !deprecate5Digit) {
|
|
3100
3315
|
console.warn(getMessage("legacy5DigitWarning"));
|
|
3101
3316
|
}
|
|
3102
|
-
return true;
|
|
3103
3317
|
});
|
|
3104
3318
|
return schema;
|
|
3105
3319
|
}
|
|
@@ -3146,7 +3360,7 @@ var validateTaiwanTel = (value) => {
|
|
|
3146
3360
|
}
|
|
3147
3361
|
return false;
|
|
3148
3362
|
};
|
|
3149
|
-
function
|
|
3363
|
+
function twTel(required, options) {
|
|
3150
3364
|
const { whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
3151
3365
|
const isRequired = required ?? false;
|
|
3152
3366
|
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
@@ -3181,23 +3395,25 @@ function tel(required, options) {
|
|
|
3181
3395
|
return processed;
|
|
3182
3396
|
};
|
|
3183
3397
|
const baseSchema = isRequired ? import_zod16.z.preprocess(preprocessFn, import_zod16.z.string()) : import_zod16.z.preprocess(preprocessFn, import_zod16.z.string().nullable());
|
|
3184
|
-
const schema = baseSchema.
|
|
3185
|
-
if (val === null) return
|
|
3398
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
3399
|
+
if (val === null) return;
|
|
3186
3400
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
3187
|
-
|
|
3401
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
3402
|
+
return;
|
|
3188
3403
|
}
|
|
3189
|
-
if (val === null) return
|
|
3190
|
-
if (!isRequired && val === "") return
|
|
3404
|
+
if (val === null) return;
|
|
3405
|
+
if (!isRequired && val === "") return;
|
|
3191
3406
|
if (whitelist && whitelist.length > 0) {
|
|
3192
3407
|
if (whitelist.includes(val)) {
|
|
3193
|
-
return
|
|
3408
|
+
return;
|
|
3194
3409
|
}
|
|
3195
|
-
|
|
3410
|
+
ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
|
|
3411
|
+
return;
|
|
3196
3412
|
}
|
|
3197
3413
|
if (!validateTaiwanTel(val)) {
|
|
3198
|
-
|
|
3414
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
3415
|
+
return;
|
|
3199
3416
|
}
|
|
3200
|
-
return true;
|
|
3201
3417
|
});
|
|
3202
3418
|
return schema;
|
|
3203
3419
|
}
|
|
@@ -3244,7 +3460,7 @@ var validateTaiwanFax = (value) => {
|
|
|
3244
3460
|
}
|
|
3245
3461
|
return false;
|
|
3246
3462
|
};
|
|
3247
|
-
function
|
|
3463
|
+
function twFax(required, options) {
|
|
3248
3464
|
const { whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
3249
3465
|
const isRequired = required ?? false;
|
|
3250
3466
|
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
@@ -3279,23 +3495,25 @@ function fax(required, options) {
|
|
|
3279
3495
|
return processed;
|
|
3280
3496
|
};
|
|
3281
3497
|
const baseSchema = isRequired ? import_zod17.z.preprocess(preprocessFn, import_zod17.z.string()) : import_zod17.z.preprocess(preprocessFn, import_zod17.z.string().nullable());
|
|
3282
|
-
const schema = baseSchema.
|
|
3283
|
-
if (val === null) return
|
|
3498
|
+
const schema = baseSchema.superRefine((val, ctx) => {
|
|
3499
|
+
if (val === null) return;
|
|
3284
3500
|
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
3285
|
-
|
|
3501
|
+
ctx.addIssue({ code: "custom", message: getMessage("required") });
|
|
3502
|
+
return;
|
|
3286
3503
|
}
|
|
3287
|
-
if (val === null) return
|
|
3288
|
-
if (!isRequired && val === "") return
|
|
3504
|
+
if (val === null) return;
|
|
3505
|
+
if (!isRequired && val === "") return;
|
|
3289
3506
|
if (whitelist && whitelist.length > 0) {
|
|
3290
3507
|
if (whitelist.includes(val)) {
|
|
3291
|
-
return
|
|
3508
|
+
return;
|
|
3292
3509
|
}
|
|
3293
|
-
|
|
3510
|
+
ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
|
|
3511
|
+
return;
|
|
3294
3512
|
}
|
|
3295
3513
|
if (!validateTaiwanFax(val)) {
|
|
3296
|
-
|
|
3514
|
+
ctx.addIssue({ code: "custom", message: getMessage("invalid") });
|
|
3515
|
+
return;
|
|
3297
3516
|
}
|
|
3298
|
-
return true;
|
|
3299
3517
|
});
|
|
3300
3518
|
return schema;
|
|
3301
3519
|
}
|
|
@@ -3306,28 +3524,28 @@ function fax(required, options) {
|
|
|
3306
3524
|
TIME_PATTERNS,
|
|
3307
3525
|
VALID_3_DIGIT_PREFIXES,
|
|
3308
3526
|
boolean,
|
|
3309
|
-
businessId,
|
|
3310
3527
|
date,
|
|
3311
3528
|
datetime,
|
|
3312
3529
|
detectIdType,
|
|
3313
3530
|
email,
|
|
3314
|
-
fax,
|
|
3315
3531
|
file,
|
|
3316
3532
|
getLocale,
|
|
3317
3533
|
id,
|
|
3318
|
-
mobile,
|
|
3319
|
-
nationalId,
|
|
3320
3534
|
normalizeDateTimeValue,
|
|
3321
3535
|
normalizeTime,
|
|
3322
3536
|
number,
|
|
3323
3537
|
parseDateTimeValue,
|
|
3324
3538
|
parseTimeToMinutes,
|
|
3325
3539
|
password,
|
|
3326
|
-
postalCode,
|
|
3327
3540
|
setLocale,
|
|
3328
|
-
tel,
|
|
3329
3541
|
text,
|
|
3330
3542
|
time,
|
|
3543
|
+
twBusinessId,
|
|
3544
|
+
twFax,
|
|
3545
|
+
twMobile,
|
|
3546
|
+
twNationalId,
|
|
3547
|
+
twPostalCode,
|
|
3548
|
+
twTel,
|
|
3331
3549
|
url,
|
|
3332
3550
|
validate3DigitPostalCode,
|
|
3333
3551
|
validate5DigitPostalCode,
|