@hy_ong/zod-kit 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/{chunk-MCDESS3T.js → chunk-2JGRV3JO.js} +1 -1
  2. package/dist/{chunk-4LYZAO3P.js → chunk-3QLUXIY2.js} +1 -1
  3. package/dist/chunk-3ZF5JO3F.js +61 -0
  4. package/dist/{chunk-OP4KV3BY.cjs → chunk-4AQB4RSU.cjs} +3 -3
  5. package/dist/{chunk-UFNVCUPQ.cjs → chunk-53EEWALQ.cjs} +3 -3
  6. package/dist/{chunk-R5G4V7C6.cjs → chunk-5ZMTAI4G.cjs} +3 -3
  7. package/dist/{chunk-RKHX3DGH.js → chunk-6DFP7XY2.js} +1 -1
  8. package/dist/{chunk-P2NONIMS.js → chunk-6IAPM7BP.js} +1 -1
  9. package/dist/{chunk-AWV2IT66.js → chunk-7SKH66CM.js} +1 -1
  10. package/dist/chunk-7X3XPK6A.js +92 -0
  11. package/dist/{chunk-FVO4743A.cjs → chunk-A2GAEU4O.cjs} +3 -3
  12. package/dist/{chunk-P364KRO5.js → chunk-AI4U42JV.js} +1 -1
  13. package/dist/{chunk-5ZEKWPSE.cjs → chunk-AYCXAJRA.cjs} +3 -3
  14. package/dist/{chunk-5LS4DSRQ.cjs → chunk-BZSPJJYT.cjs} +3 -3
  15. package/dist/chunk-BZWQPSHO.cjs +92 -0
  16. package/dist/{chunk-KARFFIMP.js → chunk-D55YFP5R.js} +1 -1
  17. package/dist/{chunk-I2RJMDXN.js → chunk-E52GRXYY.js} +1 -1
  18. package/dist/{chunk-VDOAPLA6.cjs → chunk-EDTNS2XL.cjs} +3 -3
  19. package/dist/{chunk-YALLOVNO.cjs → chunk-FEL432I2.cjs} +3 -3
  20. package/dist/chunk-FMPHW7ID.cjs +61 -0
  21. package/dist/{chunk-OMFQ7Z63.cjs → chunk-FP4O2ICM.cjs} +3 -3
  22. package/dist/{chunk-AANSHH2O.cjs → chunk-G747FHUZ.cjs} +3 -3
  23. package/dist/{chunk-JZ2SHRGZ.js → chunk-G7FLGJYD.js} +1 -1
  24. package/dist/{chunk-LKPXHW5N.cjs → chunk-H25N5GP6.cjs} +3 -3
  25. package/dist/{chunk-FC6VDOC7.js → chunk-H6STFX4I.js} +11 -2
  26. package/dist/{chunk-MAQRXYE6.js → chunk-HQ4RAMSD.js} +1 -1
  27. package/dist/{chunk-6X22I6NQ.cjs → chunk-HZ2WESSL.cjs} +3 -3
  28. package/dist/{chunk-W2EWMV3A.cjs → chunk-IWR3H7IH.cjs} +3 -3
  29. package/dist/{chunk-5GAZQDVS.cjs → chunk-JZEF5Q3W.cjs} +13 -4
  30. package/dist/{chunk-77KZUPPN.cjs → chunk-KIUO2HIR.cjs} +3 -3
  31. package/dist/{chunk-OEK7QSQP.js → chunk-LBH5U2DZ.js} +1 -1
  32. package/dist/{chunk-PGSDXR2I.js → chunk-LC4RNKBM.js} +1 -1
  33. package/dist/{chunk-YAU6JCYL.cjs → chunk-LNWEJED7.cjs} +3 -3
  34. package/dist/{chunk-WWRFBLCR.cjs → chunk-LXFRQLH4.cjs} +3 -3
  35. package/dist/{chunk-B3U5G3AA.js → chunk-NWQSOSNF.js} +1 -1
  36. package/dist/{chunk-LIQSVJLS.js → chunk-OGU7AIZF.js} +1 -1
  37. package/dist/{chunk-NKCYXBGX.js → chunk-OKO6WO6M.js} +1 -1
  38. package/dist/{chunk-6OGDPSWT.js → chunk-OSUPJCBA.js} +1 -1
  39. package/dist/{chunk-ZBOQCXD4.js → chunk-POIDES2L.js} +190 -0
  40. package/dist/{chunk-MG25BEV4.cjs → chunk-Q24GYUTO.cjs} +3 -3
  41. package/dist/{chunk-YWV2BBXN.cjs → chunk-Q7TUNJD4.cjs} +190 -0
  42. package/dist/{chunk-DRXPGQM6.cjs → chunk-QQWX3ICK.cjs} +3 -3
  43. package/dist/{chunk-EAU42EVH.js → chunk-RFWCYULE.js} +1 -1
  44. package/dist/{chunk-VCRKYMJM.js → chunk-RHKBT3M2.js} +1 -1
  45. package/dist/{chunk-36NWHESN.js → chunk-RVGCMQ4J.js} +1 -1
  46. package/dist/{chunk-IJEEM3DI.js → chunk-T7PG4JDW.js} +1 -1
  47. package/dist/{chunk-JBNCMS42.cjs → chunk-TDEXEIHH.cjs} +3 -3
  48. package/dist/{chunk-VP5CCP5F.cjs → chunk-TPXRQT2H.cjs} +3 -3
  49. package/dist/{chunk-DPXRMSB2.js → chunk-TRQMRHFM.js} +1 -1
  50. package/dist/{chunk-ZFQQXWNB.js → chunk-U2PB6XEO.js} +1 -1
  51. package/dist/{chunk-G6DV7LX7.cjs → chunk-UCPKW43K.cjs} +3 -3
  52. package/dist/{chunk-PL2GERLG.cjs → chunk-V2KKGSKQ.cjs} +3 -3
  53. package/dist/{chunk-AI72FMOF.cjs → chunk-VKBNKPFO.cjs} +3 -3
  54. package/dist/{chunk-5OGW2ERW.js → chunk-XAN4CAVH.js} +1 -1
  55. package/dist/{chunk-CFFCBWYL.cjs → chunk-ZCX22PY4.cjs} +3 -3
  56. package/dist/{chunk-TSHL7ZO2.js → chunk-ZXPRRNZR.js} +1 -1
  57. package/dist/common/boolean.cjs +3 -3
  58. package/dist/common/boolean.js +2 -2
  59. package/dist/common/color.cjs +3 -3
  60. package/dist/common/color.js +2 -2
  61. package/dist/common/coordinate.cjs +3 -3
  62. package/dist/common/coordinate.js +2 -2
  63. package/dist/common/credit-card.cjs +3 -3
  64. package/dist/common/credit-card.js +2 -2
  65. package/dist/common/date.cjs +3 -3
  66. package/dist/common/date.js +2 -2
  67. package/dist/common/datetime.cjs +3 -3
  68. package/dist/common/datetime.js +2 -2
  69. package/dist/common/email.cjs +3 -3
  70. package/dist/common/email.js +2 -2
  71. package/dist/common/file.cjs +3 -3
  72. package/dist/common/file.js +2 -2
  73. package/dist/common/id.cjs +3 -3
  74. package/dist/common/id.d.cts +34 -8
  75. package/dist/common/id.d.ts +34 -8
  76. package/dist/common/id.js +2 -2
  77. package/dist/common/ip.cjs +3 -3
  78. package/dist/common/ip.js +2 -2
  79. package/dist/common/many-of.cjs +7 -0
  80. package/dist/common/many-of.d.cts +111 -0
  81. package/dist/common/many-of.d.ts +111 -0
  82. package/dist/common/many-of.js +7 -0
  83. package/dist/common/number.cjs +3 -3
  84. package/dist/common/number.js +2 -2
  85. package/dist/common/one-of.cjs +7 -0
  86. package/dist/common/one-of.d.cts +104 -0
  87. package/dist/common/one-of.d.ts +104 -0
  88. package/dist/common/one-of.js +7 -0
  89. package/dist/common/password.cjs +3 -3
  90. package/dist/common/password.js +2 -2
  91. package/dist/common/text.cjs +3 -3
  92. package/dist/common/text.js +2 -2
  93. package/dist/common/time.cjs +3 -3
  94. package/dist/common/time.js +2 -2
  95. package/dist/common/url.cjs +3 -3
  96. package/dist/common/url.js +2 -2
  97. package/dist/index.cjs +35 -27
  98. package/dist/index.d.cts +2 -0
  99. package/dist/index.d.ts +2 -0
  100. package/dist/index.js +46 -38
  101. package/dist/taiwan/bank-account.cjs +3 -3
  102. package/dist/taiwan/bank-account.js +2 -2
  103. package/dist/taiwan/business-id.cjs +3 -3
  104. package/dist/taiwan/business-id.js +2 -2
  105. package/dist/taiwan/fax.cjs +3 -3
  106. package/dist/taiwan/fax.js +2 -2
  107. package/dist/taiwan/invoice.cjs +3 -3
  108. package/dist/taiwan/invoice.js +2 -2
  109. package/dist/taiwan/license-plate.cjs +3 -3
  110. package/dist/taiwan/license-plate.js +2 -2
  111. package/dist/taiwan/mobile.cjs +3 -3
  112. package/dist/taiwan/mobile.js +2 -2
  113. package/dist/taiwan/national-id.cjs +3 -3
  114. package/dist/taiwan/national-id.js +2 -2
  115. package/dist/taiwan/passport.cjs +3 -3
  116. package/dist/taiwan/passport.js +2 -2
  117. package/dist/taiwan/postal-code.cjs +3 -3
  118. package/dist/taiwan/postal-code.js +2 -2
  119. package/dist/taiwan/tel.cjs +3 -3
  120. package/dist/taiwan/tel.js +2 -2
  121. package/package.json +15 -5
  122. package/src/i18n/locales/en-GB.json +19 -0
  123. package/src/i18n/locales/en-US.json +20 -1
  124. package/src/i18n/locales/id-ID.json +19 -0
  125. package/src/i18n/locales/ja-JP.json +19 -0
  126. package/src/i18n/locales/ko-KR.json +19 -0
  127. package/src/i18n/locales/ms-MY.json +19 -0
  128. package/src/i18n/locales/th-TH.json +19 -0
  129. package/src/i18n/locales/vi-VN.json +19 -0
  130. package/src/i18n/locales/zh-CN.json +19 -0
  131. package/src/i18n/locales/zh-TW.json +19 -0
  132. package/src/index.ts +2 -0
  133. package/src/validators/common/id.ts +45 -3
  134. package/src/validators/common/many-of.ts +219 -0
  135. package/src/validators/common/one-of.ts +172 -0
  136. package/tests/common/id.test.ts +68 -3
  137. package/tests/common/many-of.test.ts +198 -0
  138. package/tests/common/one-of.test.ts +136 -0
  139. package/tsup.config.ts +2 -0
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/taiwan/mobile.ts
7
7
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/common/number.ts
7
7
  import { z } from "zod";
@@ -0,0 +1,61 @@
1
+ import {
2
+ getLocale,
3
+ t
4
+ } from "./chunk-POIDES2L.js";
5
+
6
+ // src/validators/common/one-of.ts
7
+ import { z } from "zod";
8
+ function oneOf(required, options) {
9
+ const { values = [], defaultValue = null, caseSensitive = true, transform, i18n } = options ?? {};
10
+ const isRequired = required ?? false;
11
+ const getMessage = (key, params) => {
12
+ if (i18n) {
13
+ const currentLocale = getLocale();
14
+ const customMessages = i18n[currentLocale];
15
+ if (customMessages && customMessages[key]) {
16
+ const template = customMessages[key];
17
+ return template.replace(/\$\{(\w+)}/g, (_, k) => params?.[k] ?? "");
18
+ }
19
+ }
20
+ return t(`common.oneOf.${key}`, params);
21
+ };
22
+ const preprocessFn = (val) => {
23
+ if (val === "" || val === null || val === void 0) {
24
+ return defaultValue;
25
+ }
26
+ const hasNumbers = values.some((v) => typeof v === "number");
27
+ if (hasNumbers && typeof val === "string" && !isNaN(Number(val)) && val.trim() !== "") {
28
+ const numVal = Number(val);
29
+ if (values.includes(numVal)) return numVal;
30
+ }
31
+ if (!caseSensitive && typeof val === "string") {
32
+ const match = values.find((v) => typeof v === "string" && v.toLowerCase() === val.toLowerCase());
33
+ if (match !== void 0) return match;
34
+ return val;
35
+ }
36
+ return val;
37
+ };
38
+ const baseSchema = z.preprocess(preprocessFn, z.any());
39
+ const schema = baseSchema.superRefine((val, ctx) => {
40
+ if (val === null) {
41
+ if (isRequired) {
42
+ ctx.addIssue({ code: "custom", message: getMessage("required") });
43
+ }
44
+ return;
45
+ }
46
+ if (!values.includes(val)) {
47
+ ctx.addIssue({
48
+ code: "custom",
49
+ message: getMessage("invalid", { values: values.join(", ") })
50
+ });
51
+ }
52
+ }).transform((val) => {
53
+ if (val === null || !transform) return val;
54
+ return transform(val);
55
+ });
56
+ return schema;
57
+ }
58
+
59
+ export {
60
+ oneOf
61
+ };
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/common/date.ts
7
7
  var _zod = require('zod');
@@ -37,14 +37,14 @@ function date(required, options) {
37
37
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
38
38
  const getMessage = (key, params) => {
39
39
  if (i18n) {
40
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
40
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
41
41
  const customMessages = i18n[currentLocale];
42
42
  if (customMessages && customMessages[key]) {
43
43
  const template = customMessages[key];
44
44
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
45
45
  }
46
46
  }
47
- return _chunkYWV2BBXNcjs.t.call(void 0, `common.date.${key}`, params);
47
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.date.${key}`, params);
48
48
  };
49
49
  const preprocessFn = (val) => {
50
50
  if (val === "" || val === null || val === void 0) {
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/common/datetime.ts
7
7
  var _zod = require('zod');
@@ -119,14 +119,14 @@ function datetime(required, options) {
119
119
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
120
120
  const getMessage = (key, params) => {
121
121
  if (i18n) {
122
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
122
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
123
123
  const customMessages = i18n[currentLocale];
124
124
  if (customMessages && customMessages[key]) {
125
125
  const template = customMessages[key];
126
126
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
127
127
  }
128
128
  }
129
- return _chunkYWV2BBXNcjs.t.call(void 0, `common.datetime.${key}`, params);
129
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.datetime.${key}`, params);
130
130
  };
131
131
  const preprocessFn = (val) => {
132
132
  if (val === null || val === void 0) {
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/taiwan/passport.ts
7
7
  var _zod = require('zod');
@@ -24,14 +24,14 @@ function twPassport(required, options) {
24
24
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
25
25
  const getMessage = (key, params) => {
26
26
  if (i18n) {
27
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
27
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
28
28
  const customMessages = i18n[currentLocale];
29
29
  if (customMessages && customMessages[key]) {
30
30
  const template = customMessages[key];
31
31
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
32
32
  }
33
33
  }
34
- return _chunkYWV2BBXNcjs.t.call(void 0, `taiwan.passport.${key}`, params);
34
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `taiwan.passport.${key}`, params);
35
35
  };
36
36
  const preprocessFn = (val) => {
37
37
  if (val === "" || val === null || val === void 0) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/taiwan/fax.ts
7
7
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/common/time.ts
7
7
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/common/ip.ts
7
7
  import { z } from "zod";
@@ -0,0 +1,92 @@
1
+ import {
2
+ getLocale,
3
+ t
4
+ } from "./chunk-POIDES2L.js";
5
+
6
+ // src/validators/common/many-of.ts
7
+ import { z } from "zod";
8
+ function manyOf(required, options) {
9
+ const { values = [], defaultValue = null, min, max, allowDuplicates = false, caseSensitive = true, transform, i18n } = options ?? {};
10
+ const isRequired = required ?? false;
11
+ const getMessage = (key, params) => {
12
+ if (i18n) {
13
+ const currentLocale = getLocale();
14
+ const customMessages = i18n[currentLocale];
15
+ if (customMessages && customMessages[key]) {
16
+ const template = customMessages[key];
17
+ return template.replace(/\$\{(\w+)}/g, (_, k) => params?.[k] ?? "");
18
+ }
19
+ }
20
+ return t(`common.manyOf.${key}`, params);
21
+ };
22
+ const normalizeItem = (item) => {
23
+ const hasNumbers = values.some((v) => typeof v === "number");
24
+ if (hasNumbers && typeof item === "string" && !isNaN(Number(item)) && item.trim() !== "") {
25
+ const numVal = Number(item);
26
+ if (values.includes(numVal)) return numVal;
27
+ }
28
+ if (!caseSensitive && typeof item === "string") {
29
+ const match = values.find((v) => typeof v === "string" && v.toLowerCase() === item.toLowerCase());
30
+ if (match !== void 0) return match;
31
+ return item;
32
+ }
33
+ return item;
34
+ };
35
+ const preprocessFn = (val) => {
36
+ if (val === null || val === void 0 || val === "") {
37
+ return defaultValue;
38
+ }
39
+ if (!Array.isArray(val)) {
40
+ return [normalizeItem(val)];
41
+ }
42
+ return val.map(normalizeItem);
43
+ };
44
+ const baseSchema = z.preprocess(preprocessFn, z.any());
45
+ const schema = baseSchema.superRefine((val, ctx) => {
46
+ if (val === null) {
47
+ if (isRequired) {
48
+ ctx.addIssue({ code: "custom", message: getMessage("required") });
49
+ }
50
+ return;
51
+ }
52
+ if (!Array.isArray(val)) {
53
+ ctx.addIssue({ code: "custom", message: getMessage("invalid", { values: values.join(", ") }) });
54
+ return;
55
+ }
56
+ for (const item of val) {
57
+ if (!values.includes(item)) {
58
+ ctx.addIssue({
59
+ code: "custom",
60
+ message: getMessage("invalid", { values: values.join(", ") })
61
+ });
62
+ return;
63
+ }
64
+ }
65
+ if (!allowDuplicates) {
66
+ const seen = /* @__PURE__ */ new Set();
67
+ for (const item of val) {
68
+ if (seen.has(item)) {
69
+ ctx.addIssue({ code: "custom", message: getMessage("duplicate") });
70
+ return;
71
+ }
72
+ seen.add(item);
73
+ }
74
+ }
75
+ if (min !== void 0 && val.length < min) {
76
+ ctx.addIssue({ code: "custom", message: getMessage("minSelect", { min }) });
77
+ return;
78
+ }
79
+ if (max !== void 0 && val.length > max) {
80
+ ctx.addIssue({ code: "custom", message: getMessage("maxSelect", { max }) });
81
+ return;
82
+ }
83
+ }).transform((val) => {
84
+ if (val === null || !Array.isArray(val) || !transform) return val;
85
+ return transform(val);
86
+ });
87
+ return schema;
88
+ }
89
+
90
+ export {
91
+ manyOf
92
+ };
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/common/color.ts
7
7
  var _zod = require('zod');
@@ -82,14 +82,14 @@ function color(required, options) {
82
82
  const formats = Array.isArray(format) ? format : [format];
83
83
  const getMessage = (key, params) => {
84
84
  if (i18n) {
85
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
85
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
86
86
  const customMessages = i18n[currentLocale];
87
87
  if (customMessages && customMessages[key]) {
88
88
  const template = customMessages[key];
89
89
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
90
90
  }
91
91
  }
92
- return _chunkYWV2BBXNcjs.t.call(void 0, `common.color.${key}`, params);
92
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.color.${key}`, params);
93
93
  };
94
94
  const preprocessFn = (val) => {
95
95
  if (val === "" || val === null || val === void 0) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/taiwan/invoice.ts
7
7
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/taiwan/mobile.ts
7
7
  var _zod = require('zod');
@@ -15,14 +15,14 @@ function twMobile(required, options) {
15
15
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
16
16
  const getMessage = (key, params) => {
17
17
  if (i18n) {
18
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
18
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
19
19
  const customMessages = i18n[currentLocale];
20
20
  if (customMessages && customMessages[key]) {
21
21
  const template = customMessages[key];
22
22
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
23
23
  }
24
24
  }
25
- return _chunkYWV2BBXNcjs.t.call(void 0, `taiwan.mobile.${key}`, params);
25
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `taiwan.mobile.${key}`, params);
26
26
  };
27
27
  const preprocessFn = (val) => {
28
28
  if (val === null || val === void 0) {
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/taiwan/fax.ts
7
7
  var _zod = require('zod');
@@ -73,14 +73,14 @@ function twFax(required, options) {
73
73
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
74
74
  const getMessage = (key, params) => {
75
75
  if (i18n) {
76
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
76
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
77
77
  const customMessages = i18n[currentLocale];
78
78
  if (customMessages && customMessages[key]) {
79
79
  const template = customMessages[key];
80
80
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
81
81
  }
82
82
  }
83
- return _chunkYWV2BBXNcjs.t.call(void 0, `taiwan.fax.${key}`, params);
83
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `taiwan.fax.${key}`, params);
84
84
  };
85
85
  const preprocessFn = (val) => {
86
86
  if (val === null || val === void 0) {
@@ -0,0 +1,92 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
+
6
+ // src/validators/common/many-of.ts
7
+ var _zod = require('zod');
8
+ function manyOf(required, options) {
9
+ const { values = [], defaultValue = null, min, max, allowDuplicates = false, caseSensitive = true, transform, i18n } = _nullishCoalesce(options, () => ( {}));
10
+ const isRequired = _nullishCoalesce(required, () => ( false));
11
+ const getMessage = (key, params) => {
12
+ if (i18n) {
13
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
14
+ const customMessages = i18n[currentLocale];
15
+ if (customMessages && customMessages[key]) {
16
+ const template = customMessages[key];
17
+ return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
18
+ }
19
+ }
20
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.manyOf.${key}`, params);
21
+ };
22
+ const normalizeItem = (item) => {
23
+ const hasNumbers = values.some((v) => typeof v === "number");
24
+ if (hasNumbers && typeof item === "string" && !isNaN(Number(item)) && item.trim() !== "") {
25
+ const numVal = Number(item);
26
+ if (values.includes(numVal)) return numVal;
27
+ }
28
+ if (!caseSensitive && typeof item === "string") {
29
+ const match = values.find((v) => typeof v === "string" && v.toLowerCase() === item.toLowerCase());
30
+ if (match !== void 0) return match;
31
+ return item;
32
+ }
33
+ return item;
34
+ };
35
+ const preprocessFn = (val) => {
36
+ if (val === null || val === void 0 || val === "") {
37
+ return defaultValue;
38
+ }
39
+ if (!Array.isArray(val)) {
40
+ return [normalizeItem(val)];
41
+ }
42
+ return val.map(normalizeItem);
43
+ };
44
+ const baseSchema = _zod.z.preprocess(preprocessFn, _zod.z.any());
45
+ const schema = baseSchema.superRefine((val, ctx) => {
46
+ if (val === null) {
47
+ if (isRequired) {
48
+ ctx.addIssue({ code: "custom", message: getMessage("required") });
49
+ }
50
+ return;
51
+ }
52
+ if (!Array.isArray(val)) {
53
+ ctx.addIssue({ code: "custom", message: getMessage("invalid", { values: values.join(", ") }) });
54
+ return;
55
+ }
56
+ for (const item of val) {
57
+ if (!values.includes(item)) {
58
+ ctx.addIssue({
59
+ code: "custom",
60
+ message: getMessage("invalid", { values: values.join(", ") })
61
+ });
62
+ return;
63
+ }
64
+ }
65
+ if (!allowDuplicates) {
66
+ const seen = /* @__PURE__ */ new Set();
67
+ for (const item of val) {
68
+ if (seen.has(item)) {
69
+ ctx.addIssue({ code: "custom", message: getMessage("duplicate") });
70
+ return;
71
+ }
72
+ seen.add(item);
73
+ }
74
+ }
75
+ if (min !== void 0 && val.length < min) {
76
+ ctx.addIssue({ code: "custom", message: getMessage("minSelect", { min }) });
77
+ return;
78
+ }
79
+ if (max !== void 0 && val.length > max) {
80
+ ctx.addIssue({ code: "custom", message: getMessage("maxSelect", { max }) });
81
+ return;
82
+ }
83
+ }).transform((val) => {
84
+ if (val === null || !Array.isArray(val) || !transform) return val;
85
+ return transform(val);
86
+ });
87
+ return schema;
88
+ }
89
+
90
+
91
+
92
+ exports.manyOf = manyOf;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/taiwan/postal-code.ts
7
7
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getLocale,
3
3
  t
4
- } from "./chunk-ZBOQCXD4.js";
4
+ } from "./chunk-POIDES2L.js";
5
5
 
6
6
  // src/validators/taiwan/license-plate.ts
7
7
  import { z } from "zod";
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/common/time.ts
7
7
  var _zod = require('zod');
@@ -99,14 +99,14 @@ function time(required, options) {
99
99
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
100
100
  const getMessage = (key, params) => {
101
101
  if (i18n) {
102
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
102
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
103
103
  const customMessages = i18n[currentLocale];
104
104
  if (customMessages && customMessages[key]) {
105
105
  const template = customMessages[key];
106
106
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
107
107
  }
108
108
  }
109
- return _chunkYWV2BBXNcjs.t.call(void 0, `common.time.${key}`, params);
109
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.time.${key}`, params);
110
110
  };
111
111
  const preprocessFn = (val) => {
112
112
  if (val === null || val === void 0) {
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/common/coordinate.ts
7
7
  var _zod = require('zod');
@@ -22,14 +22,14 @@ function coordinate(required, options) {
22
22
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
23
23
  const getMessage = (key, params) => {
24
24
  if (i18n) {
25
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
25
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
26
26
  const customMessages = i18n[currentLocale];
27
27
  if (customMessages && customMessages[key]) {
28
28
  const template = customMessages[key];
29
29
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
30
30
  }
31
31
  }
32
- return _chunkYWV2BBXNcjs.t.call(void 0, `common.coordinate.${key}`, params);
32
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.coordinate.${key}`, params);
33
33
  };
34
34
  const preprocessFn = (val) => {
35
35
  if (val === "" || val === null || val === void 0) {
@@ -0,0 +1,61 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
+
6
+ // src/validators/common/one-of.ts
7
+ var _zod = require('zod');
8
+ function oneOf(required, options) {
9
+ const { values = [], defaultValue = null, caseSensitive = true, transform, i18n } = _nullishCoalesce(options, () => ( {}));
10
+ const isRequired = _nullishCoalesce(required, () => ( false));
11
+ const getMessage = (key, params) => {
12
+ if (i18n) {
13
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
14
+ const customMessages = i18n[currentLocale];
15
+ if (customMessages && customMessages[key]) {
16
+ const template = customMessages[key];
17
+ return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
18
+ }
19
+ }
20
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `common.oneOf.${key}`, params);
21
+ };
22
+ const preprocessFn = (val) => {
23
+ if (val === "" || val === null || val === void 0) {
24
+ return defaultValue;
25
+ }
26
+ const hasNumbers = values.some((v) => typeof v === "number");
27
+ if (hasNumbers && typeof val === "string" && !isNaN(Number(val)) && val.trim() !== "") {
28
+ const numVal = Number(val);
29
+ if (values.includes(numVal)) return numVal;
30
+ }
31
+ if (!caseSensitive && typeof val === "string") {
32
+ const match = values.find((v) => typeof v === "string" && v.toLowerCase() === val.toLowerCase());
33
+ if (match !== void 0) return match;
34
+ return val;
35
+ }
36
+ return val;
37
+ };
38
+ const baseSchema = _zod.z.preprocess(preprocessFn, _zod.z.any());
39
+ const schema = baseSchema.superRefine((val, ctx) => {
40
+ if (val === null) {
41
+ if (isRequired) {
42
+ ctx.addIssue({ code: "custom", message: getMessage("required") });
43
+ }
44
+ return;
45
+ }
46
+ if (!values.includes(val)) {
47
+ ctx.addIssue({
48
+ code: "custom",
49
+ message: getMessage("invalid", { values: values.join(", ") })
50
+ });
51
+ }
52
+ }).transform((val) => {
53
+ if (val === null || !transform) return val;
54
+ return transform(val);
55
+ });
56
+ return schema;
57
+ }
58
+
59
+
60
+
61
+ exports.oneOf = oneOf;
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkYWV2BBXNcjs = require('./chunk-YWV2BBXN.cjs');
4
+ var _chunkQ7TUNJD4cjs = require('./chunk-Q7TUNJD4.cjs');
5
5
 
6
6
  // src/validators/taiwan/postal-code.ts
7
7
  var _zod = require('zod');
@@ -603,14 +603,14 @@ function twPostalCode(required, options) {
603
603
  const actualDefaultValue = _nullishCoalesce(defaultValue, () => ( (isRequired ? "" : null)));
604
604
  const getMessage = (key, params) => {
605
605
  if (i18n) {
606
- const currentLocale = _chunkYWV2BBXNcjs.getLocale.call(void 0, );
606
+ const currentLocale = _chunkQ7TUNJD4cjs.getLocale.call(void 0, );
607
607
  const customMessages = i18n[currentLocale];
608
608
  if (customMessages && customMessages[key]) {
609
609
  const template = customMessages[key];
610
610
  return template.replace(/\$\{(\w+)}/g, (_, k) => _nullishCoalesce(_optionalChain([params, 'optionalAccess', _2 => _2[k]]), () => ( "")));
611
611
  }
612
612
  }
613
- return _chunkYWV2BBXNcjs.t.call(void 0, `taiwan.postalCode.${key}`, params);
613
+ return _chunkQ7TUNJD4cjs.t.call(void 0, `taiwan.postalCode.${key}`, params);
614
614
  };
615
615
  const preprocessFn = (val) => {
616
616
  if (val === "" || val === null || val === void 0) {