@hy_ong/zod-kit 0.0.6 → 0.1.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/settings.local.json +4 -1
- package/dist/index.cjs +93 -89
- package/dist/index.d.cts +235 -169
- package/dist/index.d.ts +235 -169
- package/dist/index.js +93 -89
- package/package.json +2 -1
- package/src/validators/common/boolean.ts +17 -14
- package/src/validators/common/date.ts +21 -14
- package/src/validators/common/datetime.ts +21 -14
- package/src/validators/common/email.ts +18 -15
- package/src/validators/common/file.ts +20 -13
- package/src/validators/common/id.ts +14 -14
- package/src/validators/common/number.ts +18 -15
- package/src/validators/common/password.ts +21 -14
- package/src/validators/common/text.ts +21 -17
- package/src/validators/common/time.ts +21 -14
- package/src/validators/common/url.ts +22 -15
- package/src/validators/taiwan/business-id.ts +18 -11
- package/src/validators/taiwan/fax.ts +23 -14
- package/src/validators/taiwan/mobile.ts +23 -14
- package/src/validators/taiwan/national-id.ts +11 -12
- package/src/validators/taiwan/postal-code.ts +16 -17
- package/src/validators/taiwan/tel.ts +23 -14
- package/tests/common/boolean.test.ts +38 -38
- package/tests/common/date.test.ts +65 -65
- package/tests/common/datetime.test.ts +100 -118
- package/tests/common/email.test.ts +24 -28
- package/tests/common/file.test.ts +47 -51
- package/tests/common/id.test.ts +80 -113
- package/tests/common/number.test.ts +24 -25
- package/tests/common/password.test.ts +28 -35
- package/tests/common/text.test.ts +36 -37
- package/tests/common/time.test.ts +64 -82
- package/tests/common/url.test.ts +67 -67
- package/tests/taiwan/business-id.test.ts +22 -22
- package/tests/taiwan/fax.test.ts +33 -42
- package/tests/taiwan/mobile.test.ts +32 -41
- package/tests/taiwan/national-id.test.ts +31 -31
- package/tests/taiwan/postal-code.test.ts +142 -96
- package/tests/taiwan/tel.test.ts +33 -42
- package/debug.js +0 -21
- package/debug.ts +0 -16
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"WebFetch(domain:foundi.tw)",
|
|
21
21
|
"WebFetch(domain:data.gov.tw)",
|
|
22
22
|
"WebFetch(domain:gist.github.com)",
|
|
23
|
-
"WebFetch(domain:zip5.5432.tw)"
|
|
23
|
+
"WebFetch(domain:zip5.5432.tw)",
|
|
24
|
+
"Bash(npm install:*)",
|
|
25
|
+
"Bash(find:*)",
|
|
26
|
+
"Bash(python3:*)"
|
|
24
27
|
],
|
|
25
28
|
"deny": [],
|
|
26
29
|
"ask": []
|
package/dist/index.cjs
CHANGED
|
@@ -515,9 +515,8 @@ function getNestedValue(obj, path) {
|
|
|
515
515
|
}
|
|
516
516
|
|
|
517
517
|
// src/validators/common/boolean.ts
|
|
518
|
-
function boolean(options) {
|
|
518
|
+
function boolean(required, options) {
|
|
519
519
|
const {
|
|
520
|
-
required = true,
|
|
521
520
|
defaultValue = null,
|
|
522
521
|
shouldBe,
|
|
523
522
|
truthyValues = [true, "true", 1, "1", "yes", "on"],
|
|
@@ -526,6 +525,7 @@ function boolean(options) {
|
|
|
526
525
|
transform,
|
|
527
526
|
i18n
|
|
528
527
|
} = options ?? {};
|
|
528
|
+
const isRequired = required ?? false;
|
|
529
529
|
const getMessage = (key, params) => {
|
|
530
530
|
if (i18n) {
|
|
531
531
|
const currentLocale2 = getLocale();
|
|
@@ -557,7 +557,7 @@ function boolean(options) {
|
|
|
557
557
|
},
|
|
558
558
|
import_zod.z.union([import_zod.z.literal(true), import_zod.z.literal(false), import_zod.z.literal(null)])
|
|
559
559
|
);
|
|
560
|
-
if (
|
|
560
|
+
if (isRequired && defaultValue === null) {
|
|
561
561
|
result = result.refine((val) => val !== null, { message: getMessage("required") });
|
|
562
562
|
}
|
|
563
563
|
if (shouldBe === true) {
|
|
@@ -589,9 +589,8 @@ import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
|
589
589
|
import_dayjs.default.extend(import_customParseFormat.default);
|
|
590
590
|
import_dayjs.default.extend(import_isToday.default);
|
|
591
591
|
import_dayjs.default.extend(import_weekday.default);
|
|
592
|
-
function date(options) {
|
|
592
|
+
function date(required, options) {
|
|
593
593
|
const {
|
|
594
|
-
required = true,
|
|
595
594
|
min,
|
|
596
595
|
max,
|
|
597
596
|
format = "YYYY-MM-DD",
|
|
@@ -607,7 +606,8 @@ function date(options) {
|
|
|
607
606
|
defaultValue = null,
|
|
608
607
|
i18n
|
|
609
608
|
} = options ?? {};
|
|
610
|
-
const
|
|
609
|
+
const isRequired = required ?? false;
|
|
610
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
611
611
|
const getMessage = (key, params) => {
|
|
612
612
|
if (i18n) {
|
|
613
613
|
const currentLocale2 = getLocale();
|
|
@@ -629,10 +629,10 @@ function date(options) {
|
|
|
629
629
|
}
|
|
630
630
|
return processed;
|
|
631
631
|
};
|
|
632
|
-
const baseSchema =
|
|
632
|
+
const baseSchema = isRequired ? import_zod2.z.preprocess(preprocessFn, import_zod2.z.string()) : import_zod2.z.preprocess(preprocessFn, import_zod2.z.string().nullable());
|
|
633
633
|
const schema = baseSchema.refine((val) => {
|
|
634
634
|
if (val === null) return true;
|
|
635
|
-
if (
|
|
635
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
636
636
|
throw new import_zod2.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
637
637
|
}
|
|
638
638
|
if (val !== null && !(0, import_dayjs.default)(val, format, true).isValid()) {
|
|
@@ -766,9 +766,8 @@ var normalizeDateTimeValue = (value, format, timezone2) => {
|
|
|
766
766
|
return parsed.format(format);
|
|
767
767
|
}
|
|
768
768
|
};
|
|
769
|
-
function datetime(options) {
|
|
769
|
+
function datetime(required, options) {
|
|
770
770
|
const {
|
|
771
|
-
required = true,
|
|
772
771
|
format = "YYYY-MM-DD HH:mm",
|
|
773
772
|
min,
|
|
774
773
|
max,
|
|
@@ -794,7 +793,8 @@ function datetime(options) {
|
|
|
794
793
|
defaultValue,
|
|
795
794
|
i18n
|
|
796
795
|
} = options ?? {};
|
|
797
|
-
const
|
|
796
|
+
const isRequired = required ?? false;
|
|
797
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
798
798
|
const getMessage = (key, params) => {
|
|
799
799
|
if (i18n) {
|
|
800
800
|
const currentLocale2 = getLocale();
|
|
@@ -828,7 +828,7 @@ function datetime(options) {
|
|
|
828
828
|
if (whitelist && whitelist.includes("")) {
|
|
829
829
|
return "";
|
|
830
830
|
}
|
|
831
|
-
if (!
|
|
831
|
+
if (!isRequired) {
|
|
832
832
|
return actualDefaultValue;
|
|
833
833
|
}
|
|
834
834
|
return actualDefaultValue;
|
|
@@ -848,14 +848,14 @@ function datetime(options) {
|
|
|
848
848
|
}
|
|
849
849
|
return processed;
|
|
850
850
|
};
|
|
851
|
-
const baseSchema =
|
|
851
|
+
const baseSchema = isRequired ? import_zod3.z.preprocess(preprocessFn, import_zod3.z.string()) : import_zod3.z.preprocess(preprocessFn, import_zod3.z.string().nullable());
|
|
852
852
|
const schema = baseSchema.refine((val) => {
|
|
853
853
|
if (val === null) return true;
|
|
854
|
-
if (
|
|
854
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
855
855
|
throw new import_zod3.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
856
856
|
}
|
|
857
857
|
if (val === null) return true;
|
|
858
|
-
if (!
|
|
858
|
+
if (!isRequired && val === "") return true;
|
|
859
859
|
if (whitelist && whitelist.length > 0) {
|
|
860
860
|
if (whitelist.includes(val)) {
|
|
861
861
|
return true;
|
|
@@ -953,9 +953,8 @@ function datetime(options) {
|
|
|
953
953
|
|
|
954
954
|
// src/validators/common/email.ts
|
|
955
955
|
var import_zod4 = require("zod");
|
|
956
|
-
function email(options) {
|
|
956
|
+
function email(required, options) {
|
|
957
957
|
const {
|
|
958
|
-
required = true,
|
|
959
958
|
domain,
|
|
960
959
|
domainBlacklist,
|
|
961
960
|
minLength,
|
|
@@ -970,6 +969,7 @@ function email(options) {
|
|
|
970
969
|
defaultValue,
|
|
971
970
|
i18n
|
|
972
971
|
} = options ?? {};
|
|
972
|
+
const isRequired = required ?? false;
|
|
973
973
|
const getMessage = (key, params) => {
|
|
974
974
|
if (i18n) {
|
|
975
975
|
const currentLocale2 = getLocale();
|
|
@@ -1001,7 +1001,7 @@ function email(options) {
|
|
|
1001
1001
|
import_zod4.z.union([import_zod4.z.string().email(), import_zod4.z.null()])
|
|
1002
1002
|
);
|
|
1003
1003
|
const schema = baseSchema.refine((val) => {
|
|
1004
|
-
if (
|
|
1004
|
+
if (isRequired && val === null) {
|
|
1005
1005
|
throw new import_zod4.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
1006
1006
|
}
|
|
1007
1007
|
if (val === null) return true;
|
|
@@ -1083,9 +1083,8 @@ function email(options) {
|
|
|
1083
1083
|
|
|
1084
1084
|
// src/validators/common/file.ts
|
|
1085
1085
|
var import_zod5 = require("zod");
|
|
1086
|
-
function file(options) {
|
|
1086
|
+
function file(required, options) {
|
|
1087
1087
|
const {
|
|
1088
|
-
required = true,
|
|
1089
1088
|
maxSize,
|
|
1090
1089
|
minSize,
|
|
1091
1090
|
type,
|
|
@@ -1104,6 +1103,7 @@ function file(options) {
|
|
|
1104
1103
|
defaultValue,
|
|
1105
1104
|
i18n
|
|
1106
1105
|
} = options ?? {};
|
|
1106
|
+
const isRequired = required ?? false;
|
|
1107
1107
|
const getMessage = (key, params) => {
|
|
1108
1108
|
if (i18n) {
|
|
1109
1109
|
const currentLocale2 = getLocale();
|
|
@@ -1290,9 +1290,8 @@ var validateIdType = (value, type) => {
|
|
|
1290
1290
|
const pattern = ID_PATTERNS[type];
|
|
1291
1291
|
return pattern ? pattern.test(value) : false;
|
|
1292
1292
|
};
|
|
1293
|
-
function id(options) {
|
|
1293
|
+
function id(required, options) {
|
|
1294
1294
|
const {
|
|
1295
|
-
required = true,
|
|
1296
1295
|
type = "auto",
|
|
1297
1296
|
minLength,
|
|
1298
1297
|
maxLength,
|
|
@@ -1307,7 +1306,8 @@ function id(options) {
|
|
|
1307
1306
|
defaultValue,
|
|
1308
1307
|
i18n
|
|
1309
1308
|
} = options ?? {};
|
|
1310
|
-
const
|
|
1309
|
+
const isRequired = required ?? false;
|
|
1310
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
1311
1311
|
const getMessage = (key, params) => {
|
|
1312
1312
|
if (i18n) {
|
|
1313
1313
|
const currentLocale2 = getLocale();
|
|
@@ -1329,10 +1329,10 @@ function id(options) {
|
|
|
1329
1329
|
}
|
|
1330
1330
|
return processed;
|
|
1331
1331
|
};
|
|
1332
|
-
const baseSchema =
|
|
1332
|
+
const baseSchema = isRequired ? import_zod6.z.preprocess(preprocessFn, import_zod6.z.string()) : import_zod6.z.preprocess(preprocessFn, import_zod6.z.string().nullable());
|
|
1333
1333
|
const schema = baseSchema.refine((val) => {
|
|
1334
1334
|
if (val === null) return true;
|
|
1335
|
-
if (
|
|
1335
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1336
1336
|
throw new import_zod6.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
1337
1337
|
}
|
|
1338
1338
|
const comparisonVal = !caseSensitive ? val.toLowerCase() : val;
|
|
@@ -1414,9 +1414,8 @@ function id(options) {
|
|
|
1414
1414
|
|
|
1415
1415
|
// src/validators/common/number.ts
|
|
1416
1416
|
var import_zod7 = require("zod");
|
|
1417
|
-
function number(options) {
|
|
1417
|
+
function number(required, options) {
|
|
1418
1418
|
const {
|
|
1419
|
-
required = true,
|
|
1420
1419
|
min,
|
|
1421
1420
|
max,
|
|
1422
1421
|
defaultValue,
|
|
@@ -1432,6 +1431,7 @@ function number(options) {
|
|
|
1432
1431
|
parseCommas = false,
|
|
1433
1432
|
i18n
|
|
1434
1433
|
} = options ?? {};
|
|
1434
|
+
const isRequired = required ?? false;
|
|
1435
1435
|
const getMessage = (key, params) => {
|
|
1436
1436
|
if (i18n) {
|
|
1437
1437
|
const currentLocale2 = getLocale();
|
|
@@ -1473,7 +1473,7 @@ function number(options) {
|
|
|
1473
1473
|
},
|
|
1474
1474
|
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)])
|
|
1475
1475
|
).refine((val) => {
|
|
1476
|
-
if (
|
|
1476
|
+
if (isRequired && val === null) {
|
|
1477
1477
|
throw new import_zod7.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
1478
1478
|
}
|
|
1479
1479
|
if (val === null) return true;
|
|
@@ -1566,9 +1566,8 @@ var calculatePasswordStrength = (password2) => {
|
|
|
1566
1566
|
if (score <= 6) return "strong";
|
|
1567
1567
|
return "very-strong";
|
|
1568
1568
|
};
|
|
1569
|
-
function password(options) {
|
|
1569
|
+
function password(required, options) {
|
|
1570
1570
|
const {
|
|
1571
|
-
required = true,
|
|
1572
1571
|
min,
|
|
1573
1572
|
max,
|
|
1574
1573
|
uppercase,
|
|
@@ -1586,7 +1585,8 @@ function password(options) {
|
|
|
1586
1585
|
defaultValue,
|
|
1587
1586
|
i18n
|
|
1588
1587
|
} = options ?? {};
|
|
1589
|
-
const
|
|
1588
|
+
const isRequired = required ?? false;
|
|
1589
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
1590
1590
|
const getMessage = (key, params) => {
|
|
1591
1591
|
if (i18n) {
|
|
1592
1592
|
const currentLocale2 = getLocale();
|
|
@@ -1608,10 +1608,10 @@ function password(options) {
|
|
|
1608
1608
|
}
|
|
1609
1609
|
return processed;
|
|
1610
1610
|
};
|
|
1611
|
-
const baseSchema =
|
|
1611
|
+
const baseSchema = isRequired ? import_zod8.z.preprocess(preprocessFn, import_zod8.z.string()) : import_zod8.z.preprocess(preprocessFn, import_zod8.z.string().nullable());
|
|
1612
1612
|
const schema = baseSchema.refine((val) => {
|
|
1613
1613
|
if (val === null) return true;
|
|
1614
|
-
if (
|
|
1614
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1615
1615
|
throw new import_zod8.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
1616
1616
|
}
|
|
1617
1617
|
if (val !== null && min !== void 0 && val.length < min) {
|
|
@@ -1671,9 +1671,10 @@ function password(options) {
|
|
|
1671
1671
|
|
|
1672
1672
|
// src/validators/common/text.ts
|
|
1673
1673
|
var import_zod9 = require("zod");
|
|
1674
|
-
function text(options) {
|
|
1675
|
-
const {
|
|
1676
|
-
const
|
|
1674
|
+
function text(required, options) {
|
|
1675
|
+
const { minLength, maxLength, startsWith, endsWith, includes, excludes, regex, trimMode = "trim", casing = "none", transform, notEmpty, defaultValue, i18n } = options ?? {};
|
|
1676
|
+
const isRequired = required ?? false;
|
|
1677
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
1677
1678
|
const getMessage = (key, params) => {
|
|
1678
1679
|
if (i18n) {
|
|
1679
1680
|
const currentLocale2 = getLocale();
|
|
@@ -1721,10 +1722,10 @@ function text(options) {
|
|
|
1721
1722
|
}
|
|
1722
1723
|
return processed;
|
|
1723
1724
|
};
|
|
1724
|
-
const baseSchema =
|
|
1725
|
+
const baseSchema = isRequired ? import_zod9.z.preprocess(preprocessFn, import_zod9.z.string()) : import_zod9.z.preprocess(preprocessFn, import_zod9.z.string().nullable());
|
|
1725
1726
|
const schema = baseSchema.refine((val) => {
|
|
1726
1727
|
if (val === null) return true;
|
|
1727
|
-
if (
|
|
1728
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1728
1729
|
throw new import_zod9.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
1729
1730
|
}
|
|
1730
1731
|
if (notEmpty && val !== null && val.trim() === "") {
|
|
@@ -1832,9 +1833,8 @@ var normalizeTime = (timeStr, format) => {
|
|
|
1832
1833
|
}
|
|
1833
1834
|
return cleanTime;
|
|
1834
1835
|
};
|
|
1835
|
-
function time(options) {
|
|
1836
|
+
function time(required, options) {
|
|
1836
1837
|
const {
|
|
1837
|
-
required = true,
|
|
1838
1838
|
format = "HH:mm",
|
|
1839
1839
|
min,
|
|
1840
1840
|
max,
|
|
@@ -1854,7 +1854,8 @@ function time(options) {
|
|
|
1854
1854
|
defaultValue,
|
|
1855
1855
|
i18n
|
|
1856
1856
|
} = options ?? {};
|
|
1857
|
-
const
|
|
1857
|
+
const isRequired = required ?? false;
|
|
1858
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
1858
1859
|
const getMessage = (key, params) => {
|
|
1859
1860
|
if (i18n) {
|
|
1860
1861
|
const currentLocale2 = getLocale();
|
|
@@ -1888,7 +1889,7 @@ function time(options) {
|
|
|
1888
1889
|
if (whitelist && whitelist.includes("")) {
|
|
1889
1890
|
return "";
|
|
1890
1891
|
}
|
|
1891
|
-
if (!
|
|
1892
|
+
if (!isRequired) {
|
|
1892
1893
|
return actualDefaultValue;
|
|
1893
1894
|
}
|
|
1894
1895
|
return actualDefaultValue;
|
|
@@ -1908,14 +1909,14 @@ function time(options) {
|
|
|
1908
1909
|
}
|
|
1909
1910
|
return processed;
|
|
1910
1911
|
};
|
|
1911
|
-
const baseSchema =
|
|
1912
|
+
const baseSchema = isRequired ? import_zod10.z.preprocess(preprocessFn, import_zod10.z.string()) : import_zod10.z.preprocess(preprocessFn, import_zod10.z.string().nullable());
|
|
1912
1913
|
const schema = baseSchema.refine((val) => {
|
|
1913
1914
|
if (val === null) return true;
|
|
1914
|
-
if (
|
|
1915
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
1915
1916
|
throw new import_zod10.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
1916
1917
|
}
|
|
1917
1918
|
if (val === null) return true;
|
|
1918
|
-
if (!
|
|
1919
|
+
if (!isRequired && val === "") return true;
|
|
1919
1920
|
if (whitelist && whitelist.length > 0) {
|
|
1920
1921
|
if (whitelist.includes(val)) {
|
|
1921
1922
|
return true;
|
|
@@ -1995,9 +1996,8 @@ function time(options) {
|
|
|
1995
1996
|
|
|
1996
1997
|
// src/validators/common/url.ts
|
|
1997
1998
|
var import_zod11 = require("zod");
|
|
1998
|
-
function url(options) {
|
|
1999
|
+
function url(required, options) {
|
|
1999
2000
|
const {
|
|
2000
|
-
required = true,
|
|
2001
2001
|
min,
|
|
2002
2002
|
max,
|
|
2003
2003
|
includes,
|
|
@@ -2019,7 +2019,8 @@ function url(options) {
|
|
|
2019
2019
|
defaultValue = null,
|
|
2020
2020
|
i18n
|
|
2021
2021
|
} = options ?? {};
|
|
2022
|
-
const
|
|
2022
|
+
const isRequired = required ?? false;
|
|
2023
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
2023
2024
|
const getMessage = (key, params) => {
|
|
2024
2025
|
if (i18n) {
|
|
2025
2026
|
const currentLocale2 = getLocale();
|
|
@@ -2041,10 +2042,10 @@ function url(options) {
|
|
|
2041
2042
|
}
|
|
2042
2043
|
return processed;
|
|
2043
2044
|
};
|
|
2044
|
-
const baseSchema =
|
|
2045
|
+
const baseSchema = isRequired ? import_zod11.z.preprocess(preprocessFn, import_zod11.z.string()) : import_zod11.z.preprocess(preprocessFn, import_zod11.z.string().nullable());
|
|
2045
2046
|
const schema = baseSchema.refine((val) => {
|
|
2046
2047
|
if (val === null) return true;
|
|
2047
|
-
if (
|
|
2048
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2048
2049
|
throw new import_zod11.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
2049
2050
|
}
|
|
2050
2051
|
let urlObj;
|
|
@@ -2151,14 +2152,14 @@ var validateTaiwanBusinessId = (value) => {
|
|
|
2151
2152
|
}
|
|
2152
2153
|
return false;
|
|
2153
2154
|
};
|
|
2154
|
-
function businessId(options) {
|
|
2155
|
+
function businessId(required, options) {
|
|
2155
2156
|
const {
|
|
2156
|
-
required = true,
|
|
2157
2157
|
transform,
|
|
2158
2158
|
defaultValue,
|
|
2159
2159
|
i18n
|
|
2160
2160
|
} = options ?? {};
|
|
2161
|
-
const
|
|
2161
|
+
const isRequired = required ?? false;
|
|
2162
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
2162
2163
|
const getMessage = (key, params) => {
|
|
2163
2164
|
if (i18n) {
|
|
2164
2165
|
const currentLocale2 = getLocale();
|
|
@@ -2183,14 +2184,14 @@ function businessId(options) {
|
|
|
2183
2184
|
}
|
|
2184
2185
|
return processed;
|
|
2185
2186
|
};
|
|
2186
|
-
const baseSchema =
|
|
2187
|
+
const baseSchema = isRequired ? import_zod12.z.preprocess(preprocessFn, import_zod12.z.string()) : import_zod12.z.preprocess(preprocessFn, import_zod12.z.string().nullable());
|
|
2187
2188
|
const schema = baseSchema.refine((val) => {
|
|
2188
2189
|
if (val === null) return true;
|
|
2189
|
-
if (
|
|
2190
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2190
2191
|
throw new import_zod12.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
2191
2192
|
}
|
|
2192
2193
|
if (val === null) return true;
|
|
2193
|
-
if (!
|
|
2194
|
+
if (!isRequired && val === "") return true;
|
|
2194
2195
|
if (!validateTaiwanBusinessId(val)) {
|
|
2195
2196
|
throw new import_zod12.z.ZodError([{ code: "custom", message: getMessage("invalid"), path: [] }]);
|
|
2196
2197
|
}
|
|
@@ -2297,16 +2298,16 @@ var validateTaiwanNationalId = (value, type = "both", allowOldResident = true) =
|
|
|
2297
2298
|
return false;
|
|
2298
2299
|
}
|
|
2299
2300
|
};
|
|
2300
|
-
function nationalId(options) {
|
|
2301
|
+
function nationalId(required, options) {
|
|
2301
2302
|
const {
|
|
2302
|
-
required = true,
|
|
2303
2303
|
type = "both",
|
|
2304
2304
|
allowOldResident = true,
|
|
2305
2305
|
transform,
|
|
2306
2306
|
defaultValue,
|
|
2307
2307
|
i18n
|
|
2308
2308
|
} = options ?? {};
|
|
2309
|
-
const
|
|
2309
|
+
const isRequired = required ?? false;
|
|
2310
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
2310
2311
|
const getMessage = (key, params) => {
|
|
2311
2312
|
if (i18n) {
|
|
2312
2313
|
const currentLocale2 = getLocale();
|
|
@@ -2331,14 +2332,14 @@ function nationalId(options) {
|
|
|
2331
2332
|
}
|
|
2332
2333
|
return processed;
|
|
2333
2334
|
};
|
|
2334
|
-
const baseSchema =
|
|
2335
|
+
const baseSchema = isRequired ? import_zod13.z.preprocess(preprocessFn, import_zod13.z.string()) : import_zod13.z.preprocess(preprocessFn, import_zod13.z.string().nullable());
|
|
2335
2336
|
const schema = baseSchema.refine((val) => {
|
|
2336
2337
|
if (val === null) return true;
|
|
2337
|
-
if (
|
|
2338
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2338
2339
|
throw new import_zod13.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
2339
2340
|
}
|
|
2340
2341
|
if (val === null) return true;
|
|
2341
|
-
if (!
|
|
2342
|
+
if (!isRequired && val === "") return true;
|
|
2342
2343
|
if (!validateTaiwanNationalId(val, type, allowOldResident)) {
|
|
2343
2344
|
throw new import_zod13.z.ZodError([{ code: "custom", message: getMessage("invalid"), path: [] }]);
|
|
2344
2345
|
}
|
|
@@ -2352,9 +2353,10 @@ var import_zod14 = require("zod");
|
|
|
2352
2353
|
var validateTaiwanMobile = (value) => {
|
|
2353
2354
|
return /^09[0-9]\d{7}$/.test(value);
|
|
2354
2355
|
};
|
|
2355
|
-
function mobile(options) {
|
|
2356
|
-
const {
|
|
2357
|
-
const
|
|
2356
|
+
function mobile(required, options) {
|
|
2357
|
+
const { whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
2358
|
+
const isRequired = required ?? false;
|
|
2359
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
2358
2360
|
const getMessage = (key, params) => {
|
|
2359
2361
|
if (i18n) {
|
|
2360
2362
|
const currentLocale2 = getLocale();
|
|
@@ -2375,7 +2377,7 @@ function mobile(options) {
|
|
|
2375
2377
|
if (whitelist && whitelist.includes("")) {
|
|
2376
2378
|
return "";
|
|
2377
2379
|
}
|
|
2378
|
-
if (!
|
|
2380
|
+
if (!isRequired) {
|
|
2379
2381
|
return actualDefaultValue;
|
|
2380
2382
|
}
|
|
2381
2383
|
return actualDefaultValue;
|
|
@@ -2385,14 +2387,14 @@ function mobile(options) {
|
|
|
2385
2387
|
}
|
|
2386
2388
|
return processed;
|
|
2387
2389
|
};
|
|
2388
|
-
const baseSchema =
|
|
2390
|
+
const baseSchema = isRequired ? import_zod14.z.preprocess(preprocessFn, import_zod14.z.string()) : import_zod14.z.preprocess(preprocessFn, import_zod14.z.string().nullable());
|
|
2389
2391
|
const schema = baseSchema.refine((val) => {
|
|
2390
2392
|
if (val === null) return true;
|
|
2391
|
-
if (
|
|
2393
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
2392
2394
|
throw new import_zod14.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
2393
2395
|
}
|
|
2394
2396
|
if (val === null) return true;
|
|
2395
|
-
if (!
|
|
2397
|
+
if (!isRequired && val === "") return true;
|
|
2396
2398
|
if (whitelist && whitelist.length > 0) {
|
|
2397
2399
|
if (whitelist.includes(val)) {
|
|
2398
2400
|
return true;
|
|
@@ -2989,9 +2991,8 @@ var validateTaiwanPostalCode = (value, format = "3+6", strictValidation = true,
|
|
|
2989
2991
|
return false;
|
|
2990
2992
|
}
|
|
2991
2993
|
};
|
|
2992
|
-
function postalCode(options) {
|
|
2994
|
+
function postalCode(required, options) {
|
|
2993
2995
|
const {
|
|
2994
|
-
required = true,
|
|
2995
2996
|
format = "3+6",
|
|
2996
2997
|
strictValidation = true,
|
|
2997
2998
|
allowDashes = true,
|
|
@@ -3004,7 +3005,8 @@ function postalCode(options) {
|
|
|
3004
3005
|
strictSuffixValidation = false,
|
|
3005
3006
|
deprecate5Digit = false
|
|
3006
3007
|
} = options ?? {};
|
|
3007
|
-
const
|
|
3008
|
+
const isRequired = required ?? false;
|
|
3009
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
3008
3010
|
const getMessage = (key, params) => {
|
|
3009
3011
|
if (i18n) {
|
|
3010
3012
|
const currentLocale2 = getLocale();
|
|
@@ -3032,14 +3034,14 @@ function postalCode(options) {
|
|
|
3032
3034
|
}
|
|
3033
3035
|
return processed;
|
|
3034
3036
|
};
|
|
3035
|
-
const baseSchema =
|
|
3037
|
+
const baseSchema = isRequired ? import_zod15.z.preprocess(preprocessFn, import_zod15.z.string()) : import_zod15.z.preprocess(preprocessFn, import_zod15.z.string().nullable());
|
|
3036
3038
|
const schema = baseSchema.refine((val) => {
|
|
3037
3039
|
if (val === null) return true;
|
|
3038
|
-
if (
|
|
3040
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
3039
3041
|
throw new import_zod15.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
3040
3042
|
}
|
|
3041
3043
|
if (val === null) return true;
|
|
3042
|
-
if (!
|
|
3044
|
+
if (!isRequired && val === "") return true;
|
|
3043
3045
|
const cleanValue = val.replace(/[-\s]/g, "");
|
|
3044
3046
|
if (format === "3" && cleanValue.length !== 3) {
|
|
3045
3047
|
throw new import_zod15.z.ZodError([{ code: "custom", message: getMessage("format3Only"), path: [] }]);
|
|
@@ -3125,9 +3127,10 @@ var validateTaiwanTel = (value) => {
|
|
|
3125
3127
|
}
|
|
3126
3128
|
return false;
|
|
3127
3129
|
};
|
|
3128
|
-
function tel(options) {
|
|
3129
|
-
const {
|
|
3130
|
-
const
|
|
3130
|
+
function tel(required, options) {
|
|
3131
|
+
const { whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
3132
|
+
const isRequired = required ?? false;
|
|
3133
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
3131
3134
|
const getMessage = (key, params) => {
|
|
3132
3135
|
if (i18n) {
|
|
3133
3136
|
const currentLocale2 = getLocale();
|
|
@@ -3148,7 +3151,7 @@ function tel(options) {
|
|
|
3148
3151
|
if (whitelist && whitelist.includes("")) {
|
|
3149
3152
|
return "";
|
|
3150
3153
|
}
|
|
3151
|
-
if (!
|
|
3154
|
+
if (!isRequired) {
|
|
3152
3155
|
return actualDefaultValue;
|
|
3153
3156
|
}
|
|
3154
3157
|
return actualDefaultValue;
|
|
@@ -3158,14 +3161,14 @@ function tel(options) {
|
|
|
3158
3161
|
}
|
|
3159
3162
|
return processed;
|
|
3160
3163
|
};
|
|
3161
|
-
const baseSchema =
|
|
3164
|
+
const baseSchema = isRequired ? import_zod16.z.preprocess(preprocessFn, import_zod16.z.string()) : import_zod16.z.preprocess(preprocessFn, import_zod16.z.string().nullable());
|
|
3162
3165
|
const schema = baseSchema.refine((val) => {
|
|
3163
3166
|
if (val === null) return true;
|
|
3164
|
-
if (
|
|
3167
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
3165
3168
|
throw new import_zod16.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
3166
3169
|
}
|
|
3167
3170
|
if (val === null) return true;
|
|
3168
|
-
if (!
|
|
3171
|
+
if (!isRequired && val === "") return true;
|
|
3169
3172
|
if (whitelist && whitelist.length > 0) {
|
|
3170
3173
|
if (whitelist.includes(val)) {
|
|
3171
3174
|
return true;
|
|
@@ -3222,9 +3225,10 @@ var validateTaiwanFax = (value) => {
|
|
|
3222
3225
|
}
|
|
3223
3226
|
return false;
|
|
3224
3227
|
};
|
|
3225
|
-
function fax(options) {
|
|
3226
|
-
const {
|
|
3227
|
-
const
|
|
3228
|
+
function fax(required, options) {
|
|
3229
|
+
const { whitelist, transform, defaultValue, i18n } = options ?? {};
|
|
3230
|
+
const isRequired = required ?? false;
|
|
3231
|
+
const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
|
|
3228
3232
|
const getMessage = (key, params) => {
|
|
3229
3233
|
if (i18n) {
|
|
3230
3234
|
const currentLocale2 = getLocale();
|
|
@@ -3245,7 +3249,7 @@ function fax(options) {
|
|
|
3245
3249
|
if (whitelist && whitelist.includes("")) {
|
|
3246
3250
|
return "";
|
|
3247
3251
|
}
|
|
3248
|
-
if (!
|
|
3252
|
+
if (!isRequired) {
|
|
3249
3253
|
return actualDefaultValue;
|
|
3250
3254
|
}
|
|
3251
3255
|
return actualDefaultValue;
|
|
@@ -3255,14 +3259,14 @@ function fax(options) {
|
|
|
3255
3259
|
}
|
|
3256
3260
|
return processed;
|
|
3257
3261
|
};
|
|
3258
|
-
const baseSchema =
|
|
3262
|
+
const baseSchema = isRequired ? import_zod17.z.preprocess(preprocessFn, import_zod17.z.string()) : import_zod17.z.preprocess(preprocessFn, import_zod17.z.string().nullable());
|
|
3259
3263
|
const schema = baseSchema.refine((val) => {
|
|
3260
3264
|
if (val === null) return true;
|
|
3261
|
-
if (
|
|
3265
|
+
if (isRequired && (val === "" || val === "null" || val === "undefined")) {
|
|
3262
3266
|
throw new import_zod17.z.ZodError([{ code: "custom", message: getMessage("required"), path: [] }]);
|
|
3263
3267
|
}
|
|
3264
3268
|
if (val === null) return true;
|
|
3265
|
-
if (!
|
|
3269
|
+
if (!isRequired && val === "") return true;
|
|
3266
3270
|
if (whitelist && whitelist.length > 0) {
|
|
3267
3271
|
if (whitelist.includes(val)) {
|
|
3268
3272
|
return true;
|