@hy_ong/zod-kit 0.2.0 → 0.2.2

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 (191) hide show
  1. package/.github/workflows/ci.yml +24 -0
  2. package/CLAUDE.md +64 -22
  3. package/dist/chunk-2SWEVDFZ.js +134 -0
  4. package/dist/chunk-32JI34CV.cjs +146 -0
  5. package/dist/chunk-42C5OHRK.js +71 -0
  6. package/dist/chunk-46VAH2BJ.js +160 -0
  7. package/dist/chunk-5JGTDL3Y.js +87 -0
  8. package/dist/chunk-5LEXCVLX.js +257 -0
  9. package/dist/chunk-6AAP4LPF.js +2606 -0
  10. package/dist/chunk-B4EZYZOK.cjs +215 -0
  11. package/dist/chunk-COYKBWTI.js +161 -0
  12. package/dist/chunk-DFJZ3NS2.cjs +151 -0
  13. package/dist/chunk-EDHT4LPO.js +118 -0
  14. package/dist/chunk-EGHL277K.cjs +165 -0
  15. package/dist/chunk-ERH4NIMU.cjs +69 -0
  16. package/dist/chunk-FM3EZ72O.js +165 -0
  17. package/dist/chunk-GJIRDBZJ.cjs +90 -0
  18. package/dist/chunk-H2XTEM4M.js +696 -0
  19. package/dist/chunk-HMSM6FFA.cjs +181 -0
  20. package/dist/chunk-HTEHINI7.cjs +177 -0
  21. package/dist/chunk-JOLSGZGN.cjs +696 -0
  22. package/dist/chunk-JXY7APBU.js +69 -0
  23. package/dist/chunk-K2UOY6TB.js +136 -0
  24. package/dist/chunk-KFOHKTFD.js +61 -0
  25. package/dist/chunk-L4HSIKTU.cjs +135 -0
  26. package/dist/chunk-LH7ZB4BK.js +124 -0
  27. package/dist/chunk-LL4ZWLGO.js +90 -0
  28. package/dist/chunk-M6MTP3NY.cjs +99 -0
  29. package/dist/chunk-MHJFYYGV.js +215 -0
  30. package/dist/chunk-MINMXGW3.js +135 -0
  31. package/dist/chunk-MM7IL2RG.js +181 -0
  32. package/dist/chunk-OPQJWHXN.cjs +301 -0
  33. package/dist/chunk-ORFHDJII.cjs +136 -0
  34. package/dist/chunk-ORVV4MCF.cjs +87 -0
  35. package/dist/chunk-QICQ6YEY.js +75 -0
  36. package/dist/chunk-RKUQREMW.js +127 -0
  37. package/dist/chunk-RO47DKQG.js +146 -0
  38. package/dist/chunk-RRPXIRTQ.cjs +257 -0
  39. package/dist/chunk-RYFG2GKM.cjs +118 -0
  40. package/dist/chunk-STNHTRG7.cjs +124 -0
  41. package/dist/chunk-TFGS34VD.cjs +71 -0
  42. package/dist/chunk-TQXDUMML.cjs +61 -0
  43. package/dist/chunk-UBK3VCVH.cjs +134 -0
  44. package/dist/chunk-UCOXAZJF.cjs +2606 -0
  45. package/dist/chunk-UQZKFAFX.js +130 -0
  46. package/dist/chunk-VB2KV2ZM.cjs +130 -0
  47. package/dist/chunk-WABKPFPK.js +151 -0
  48. package/dist/chunk-WDI4QJMQ.js +177 -0
  49. package/dist/chunk-YDH3L27K.cjs +127 -0
  50. package/dist/chunk-YIM3D2AD.js +99 -0
  51. package/dist/chunk-YPSEIDUR.cjs +160 -0
  52. package/dist/chunk-ZNJLWJX3.cjs +75 -0
  53. package/dist/chunk-ZTFCJCPO.cjs +161 -0
  54. package/dist/chunk-ZXUMK2RR.js +301 -0
  55. package/dist/common/boolean.cjs +7 -0
  56. package/dist/common/boolean.d.cts +119 -0
  57. package/dist/common/boolean.d.ts +119 -0
  58. package/dist/common/boolean.js +7 -0
  59. package/dist/common/color.cjs +9 -0
  60. package/dist/common/color.d.cts +26 -0
  61. package/dist/common/color.d.ts +26 -0
  62. package/dist/common/color.js +9 -0
  63. package/dist/common/coordinate.cjs +11 -0
  64. package/dist/common/coordinate.d.cts +23 -0
  65. package/dist/common/coordinate.d.ts +23 -0
  66. package/dist/common/coordinate.js +11 -0
  67. package/dist/common/credit-card.cjs +11 -0
  68. package/dist/common/credit-card.d.cts +22 -0
  69. package/dist/common/credit-card.d.ts +22 -0
  70. package/dist/common/credit-card.js +11 -0
  71. package/dist/common/date.cjs +7 -0
  72. package/dist/common/date.d.cts +174 -0
  73. package/dist/common/date.d.ts +174 -0
  74. package/dist/common/date.js +7 -0
  75. package/dist/common/datetime.cjs +15 -0
  76. package/dist/common/datetime.d.cts +301 -0
  77. package/dist/common/datetime.d.ts +301 -0
  78. package/dist/common/datetime.js +15 -0
  79. package/dist/common/email.cjs +7 -0
  80. package/dist/common/email.d.cts +149 -0
  81. package/dist/common/email.d.ts +149 -0
  82. package/dist/common/email.js +7 -0
  83. package/dist/common/file.cjs +7 -0
  84. package/dist/common/file.d.cts +178 -0
  85. package/dist/common/file.d.ts +178 -0
  86. package/dist/common/file.js +7 -0
  87. package/dist/common/id.cjs +13 -0
  88. package/dist/common/id.d.cts +288 -0
  89. package/dist/common/id.d.ts +288 -0
  90. package/dist/common/id.js +13 -0
  91. package/dist/common/ip.cjs +11 -0
  92. package/dist/common/ip.d.cts +25 -0
  93. package/dist/common/ip.d.ts +25 -0
  94. package/dist/common/ip.js +11 -0
  95. package/dist/common/number.cjs +7 -0
  96. package/dist/common/number.d.cts +167 -0
  97. package/dist/common/number.d.ts +167 -0
  98. package/dist/common/number.js +7 -0
  99. package/dist/common/password.cjs +7 -0
  100. package/dist/common/password.d.cts +192 -0
  101. package/dist/common/password.d.ts +192 -0
  102. package/dist/common/password.js +7 -0
  103. package/dist/common/text.cjs +7 -0
  104. package/dist/common/text.d.cts +156 -0
  105. package/dist/common/text.d.ts +156 -0
  106. package/dist/common/text.js +7 -0
  107. package/dist/common/time.cjs +15 -0
  108. package/dist/common/time.d.cts +268 -0
  109. package/dist/common/time.d.ts +268 -0
  110. package/dist/common/time.js +15 -0
  111. package/dist/common/url.cjs +7 -0
  112. package/dist/common/url.d.cts +196 -0
  113. package/dist/common/url.d.ts +196 -0
  114. package/dist/common/url.js +7 -0
  115. package/dist/config-CABSSvAp.d.cts +5 -0
  116. package/dist/config-CABSSvAp.d.ts +5 -0
  117. package/dist/index.cjs +180 -5255
  118. package/dist/index.d.cts +28 -3150
  119. package/dist/index.d.ts +28 -3150
  120. package/dist/index.js +135 -5131
  121. package/dist/taiwan/bank-account.cjs +11 -0
  122. package/dist/taiwan/bank-account.d.cts +22 -0
  123. package/dist/taiwan/bank-account.d.ts +22 -0
  124. package/dist/taiwan/bank-account.js +11 -0
  125. package/dist/taiwan/business-id.cjs +9 -0
  126. package/dist/taiwan/business-id.d.cts +133 -0
  127. package/dist/taiwan/business-id.d.ts +133 -0
  128. package/dist/taiwan/business-id.js +9 -0
  129. package/dist/taiwan/fax.cjs +9 -0
  130. package/dist/taiwan/fax.d.cts +157 -0
  131. package/dist/taiwan/fax.d.ts +157 -0
  132. package/dist/taiwan/fax.js +9 -0
  133. package/dist/taiwan/invoice.cjs +9 -0
  134. package/dist/taiwan/invoice.d.cts +17 -0
  135. package/dist/taiwan/invoice.d.ts +17 -0
  136. package/dist/taiwan/invoice.js +9 -0
  137. package/dist/taiwan/license-plate.cjs +9 -0
  138. package/dist/taiwan/license-plate.d.cts +19 -0
  139. package/dist/taiwan/license-plate.d.ts +19 -0
  140. package/dist/taiwan/license-plate.js +9 -0
  141. package/dist/taiwan/mobile.cjs +9 -0
  142. package/dist/taiwan/mobile.d.cts +146 -0
  143. package/dist/taiwan/mobile.d.ts +146 -0
  144. package/dist/taiwan/mobile.js +9 -0
  145. package/dist/taiwan/national-id.cjs +15 -0
  146. package/dist/taiwan/national-id.d.cts +214 -0
  147. package/dist/taiwan/national-id.d.ts +214 -0
  148. package/dist/taiwan/national-id.js +15 -0
  149. package/dist/taiwan/passport.cjs +9 -0
  150. package/dist/taiwan/passport.d.cts +19 -0
  151. package/dist/taiwan/passport.d.ts +19 -0
  152. package/dist/taiwan/passport.js +9 -0
  153. package/dist/taiwan/postal-code.cjs +17 -0
  154. package/dist/taiwan/postal-code.d.cts +237 -0
  155. package/dist/taiwan/postal-code.d.ts +237 -0
  156. package/dist/taiwan/postal-code.js +17 -0
  157. package/dist/taiwan/tel.cjs +9 -0
  158. package/dist/taiwan/tel.d.cts +162 -0
  159. package/dist/taiwan/tel.d.ts +162 -0
  160. package/dist/taiwan/tel.js +9 -0
  161. package/package.json +132 -6
  162. package/src/i18n/locales/en-GB.json +51 -0
  163. package/src/i18n/locales/en-US.json +52 -1
  164. package/src/i18n/locales/id-ID.json +51 -0
  165. package/src/i18n/locales/ja-JP.json +51 -0
  166. package/src/i18n/locales/ko-KR.json +51 -0
  167. package/src/i18n/locales/ms-MY.json +51 -0
  168. package/src/i18n/locales/th-TH.json +51 -0
  169. package/src/i18n/locales/vi-VN.json +51 -0
  170. package/src/i18n/locales/zh-CN.json +51 -0
  171. package/src/i18n/locales/zh-TW.json +51 -0
  172. package/src/index.ts +10 -2
  173. package/src/validators/common/color.ts +192 -0
  174. package/src/validators/common/coordinate.ts +159 -0
  175. package/src/validators/common/credit-card.ts +134 -0
  176. package/src/validators/common/id.ts +45 -3
  177. package/src/validators/common/ip.ts +210 -0
  178. package/src/validators/taiwan/bank-account.ts +176 -0
  179. package/src/validators/taiwan/invoice.ts +84 -0
  180. package/src/validators/taiwan/license-plate.ts +110 -0
  181. package/src/validators/taiwan/passport.ts +103 -0
  182. package/tests/common/color.test.ts +587 -0
  183. package/tests/common/coordinate.test.ts +345 -0
  184. package/tests/common/credit-card.test.ts +378 -0
  185. package/tests/common/id.test.ts +68 -3
  186. package/tests/common/ip.test.ts +419 -0
  187. package/tests/taiwan/bank-account.test.ts +286 -0
  188. package/tests/taiwan/invoice.test.ts +227 -0
  189. package/tests/taiwan/license-plate.test.ts +280 -0
  190. package/tests/taiwan/passport.test.ts +277 -0
  191. package/tsup.config.ts +36 -0
@@ -0,0 +1,301 @@
1
+ import {
2
+ getLocale,
3
+ t
4
+ } from "./chunk-6AAP4LPF.js";
5
+
6
+ // src/validators/common/datetime.ts
7
+ import { z } from "zod";
8
+ import dayjs from "dayjs";
9
+ import customParseFormat from "dayjs/plugin/customParseFormat";
10
+ import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
11
+ import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
12
+ import isToday from "dayjs/plugin/isToday";
13
+ import weekday from "dayjs/plugin/weekday";
14
+ import timezone from "dayjs/plugin/timezone";
15
+ import utc from "dayjs/plugin/utc";
16
+ dayjs.extend(isSameOrAfter);
17
+ dayjs.extend(isSameOrBefore);
18
+ dayjs.extend(customParseFormat);
19
+ dayjs.extend(isToday);
20
+ dayjs.extend(weekday);
21
+ dayjs.extend(timezone);
22
+ dayjs.extend(utc);
23
+ var DATETIME_PATTERNS = {
24
+ "YYYY-MM-DD HH:mm": /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/,
25
+ "YYYY-MM-DD HH:mm:ss": /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/,
26
+ "YYYY-MM-DD hh:mm A": /^\d{4}-\d{2}-\d{2} \d{1,2}:\d{2} (AM|PM)$/i,
27
+ "YYYY-MM-DD hh:mm:ss A": /^\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}:\d{2} (AM|PM)$/i,
28
+ "DD/MM/YYYY HH:mm": /^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}$/,
29
+ "DD/MM/YYYY HH:mm:ss": /^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}:\d{2}$/,
30
+ "DD/MM/YYYY hh:mm A": /^\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{2} (AM|PM)$/i,
31
+ "MM/DD/YYYY HH:mm": /^\d{1,2}\/\d{1,2}\/\d{4} \d{2}:\d{2}$/,
32
+ "MM/DD/YYYY hh:mm A": /^\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{2} (AM|PM)$/i,
33
+ "YYYY/MM/DD HH:mm": /^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}$/,
34
+ "DD-MM-YYYY HH:mm": /^\d{1,2}-\d{1,2}-\d{4} \d{2}:\d{2}$/,
35
+ "MM-DD-YYYY HH:mm": /^\d{1,2}-\d{1,2}-\d{4} \d{2}:\d{2}$/,
36
+ ISO: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/,
37
+ RFC: /^[A-Za-z]{3}, \d{1,2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} [A-Z]{3}$/,
38
+ UNIX: /^\d{10}$/
39
+ };
40
+ var validateDateTimeFormat = (value, format) => {
41
+ const pattern = DATETIME_PATTERNS[format];
42
+ if (!pattern.test(value.trim())) {
43
+ return false;
44
+ }
45
+ const parsed = parseDateTimeValue(value, format);
46
+ return parsed !== null;
47
+ };
48
+ var parseDateTimeValue = (value, format, timezone2) => {
49
+ try {
50
+ const cleanValue = value.trim();
51
+ let parsed;
52
+ switch (format) {
53
+ case "ISO":
54
+ parsed = dayjs(cleanValue);
55
+ break;
56
+ case "RFC":
57
+ parsed = dayjs(cleanValue);
58
+ break;
59
+ case "UNIX":
60
+ parsed = dayjs.unix(parseInt(cleanValue, 10));
61
+ break;
62
+ default:
63
+ parsed = dayjs(cleanValue, format, true);
64
+ break;
65
+ }
66
+ if (!parsed.isValid()) {
67
+ return null;
68
+ }
69
+ if (timezone2) {
70
+ parsed = parsed.tz(timezone2);
71
+ }
72
+ return parsed;
73
+ } catch {
74
+ return null;
75
+ }
76
+ };
77
+ var normalizeDateTimeValue = (value, format, timezone2) => {
78
+ const parsed = parseDateTimeValue(value, format, timezone2);
79
+ if (!parsed) return null;
80
+ switch (format) {
81
+ case "ISO":
82
+ return parsed.toISOString();
83
+ case "RFC":
84
+ return parsed.format("ddd, DD MMM YYYY HH:mm:ss [GMT]");
85
+ case "UNIX":
86
+ return parsed.unix().toString();
87
+ default:
88
+ return parsed.format(format);
89
+ }
90
+ };
91
+ function datetime(required, options) {
92
+ const {
93
+ format = "YYYY-MM-DD HH:mm",
94
+ min,
95
+ max,
96
+ minHour,
97
+ maxHour,
98
+ allowedHours,
99
+ minuteStep,
100
+ timezone: timezone2,
101
+ includes,
102
+ excludes,
103
+ regex,
104
+ trimMode = "trim",
105
+ casing = "none",
106
+ mustBePast,
107
+ mustBeFuture,
108
+ mustBeToday,
109
+ mustNotBeToday,
110
+ weekdaysOnly,
111
+ weekendsOnly,
112
+ whitelist,
113
+ whitelistOnly = false,
114
+ transform,
115
+ defaultValue,
116
+ i18n
117
+ } = options ?? {};
118
+ const isRequired = required ?? false;
119
+ const actualDefaultValue = defaultValue ?? (isRequired ? "" : null);
120
+ const getMessage = (key, params) => {
121
+ if (i18n) {
122
+ const currentLocale = getLocale();
123
+ const customMessages = i18n[currentLocale];
124
+ if (customMessages && customMessages[key]) {
125
+ const template = customMessages[key];
126
+ return template.replace(/\$\{(\w+)}/g, (_, k) => params?.[k] ?? "");
127
+ }
128
+ }
129
+ return t(`common.datetime.${key}`, params);
130
+ };
131
+ const preprocessFn = (val) => {
132
+ if (val === null || val === void 0) {
133
+ return actualDefaultValue;
134
+ }
135
+ let processed = String(val);
136
+ switch (trimMode) {
137
+ case "trim":
138
+ processed = processed.trim();
139
+ break;
140
+ case "trimStart":
141
+ processed = processed.trimStart();
142
+ break;
143
+ case "trimEnd":
144
+ processed = processed.trimEnd();
145
+ break;
146
+ case "none":
147
+ break;
148
+ }
149
+ if (processed === "") {
150
+ if (whitelist && whitelist.includes("")) {
151
+ return "";
152
+ }
153
+ if (!isRequired) {
154
+ return actualDefaultValue;
155
+ }
156
+ return actualDefaultValue;
157
+ }
158
+ switch (casing) {
159
+ case "upper":
160
+ processed = processed.toUpperCase();
161
+ break;
162
+ case "lower":
163
+ processed = processed.toLowerCase();
164
+ break;
165
+ case "none":
166
+ break;
167
+ }
168
+ if (transform) {
169
+ processed = transform(processed);
170
+ }
171
+ return processed;
172
+ };
173
+ const baseSchema = isRequired ? z.preprocess(preprocessFn, z.string()) : z.preprocess(preprocessFn, z.string().nullable());
174
+ const schema = baseSchema.superRefine((val, ctx) => {
175
+ if (val === null) return;
176
+ if (isRequired && (val === "" || val === "null" || val === "undefined")) {
177
+ ctx.addIssue({ code: "custom", message: getMessage("required") });
178
+ return;
179
+ }
180
+ if (val === null) return;
181
+ if (!isRequired && val === "") return;
182
+ if (whitelist && whitelist.length > 0) {
183
+ if (whitelist.includes(val)) {
184
+ return;
185
+ }
186
+ if (whitelistOnly) {
187
+ ctx.addIssue({ code: "custom", message: getMessage("notInWhitelist") });
188
+ return;
189
+ }
190
+ }
191
+ if (regex) {
192
+ if (!regex.test(val)) {
193
+ ctx.addIssue({ code: "custom", message: getMessage("customRegex") });
194
+ return;
195
+ }
196
+ } else {
197
+ if (!validateDateTimeFormat(val, format)) {
198
+ ctx.addIssue({ code: "custom", message: getMessage("format", { format }) });
199
+ return;
200
+ }
201
+ }
202
+ if (includes && !val.includes(includes)) {
203
+ ctx.addIssue({ code: "custom", message: getMessage("includes", { includes }) });
204
+ return;
205
+ }
206
+ if (excludes) {
207
+ const excludeList = Array.isArray(excludes) ? excludes : [excludes];
208
+ for (const exclude of excludeList) {
209
+ if (val.includes(exclude)) {
210
+ ctx.addIssue({ code: "custom", message: getMessage("excludes", { excludes: exclude }) });
211
+ return;
212
+ }
213
+ }
214
+ }
215
+ if (regex) {
216
+ return;
217
+ }
218
+ const parsed = parseDateTimeValue(val, format, timezone2);
219
+ if (!parsed) {
220
+ const pattern = DATETIME_PATTERNS[format];
221
+ if (!pattern.test(val.trim())) {
222
+ ctx.addIssue({ code: "custom", message: getMessage("format", { format }) });
223
+ return;
224
+ } else {
225
+ ctx.addIssue({ code: "custom", message: getMessage("invalid") });
226
+ return;
227
+ }
228
+ }
229
+ const hour = parsed.hour();
230
+ if (minHour !== void 0 && hour < minHour) {
231
+ ctx.addIssue({ code: "custom", message: getMessage("hour", { minHour, maxHour: maxHour ?? 23 }) });
232
+ return;
233
+ }
234
+ if (maxHour !== void 0 && hour > maxHour) {
235
+ ctx.addIssue({ code: "custom", message: getMessage("hour", { minHour: minHour ?? 0, maxHour }) });
236
+ return;
237
+ }
238
+ if (allowedHours && allowedHours.length > 0) {
239
+ if (!allowedHours.includes(hour)) {
240
+ ctx.addIssue({ code: "custom", message: getMessage("hour", { allowedHours: allowedHours.join(", ") }) });
241
+ return;
242
+ }
243
+ }
244
+ const minute = parsed.minute();
245
+ if (minuteStep !== void 0 && minute % minuteStep !== 0) {
246
+ ctx.addIssue({ code: "custom", message: getMessage("minute", { minuteStep }) });
247
+ return;
248
+ }
249
+ if (min) {
250
+ const minParsed = typeof min === "string" ? parseDateTimeValue(min, format, timezone2) : dayjs(min);
251
+ if (minParsed && parsed.isBefore(minParsed)) {
252
+ const minFormatted = typeof min === "string" ? min : minParsed.format(format);
253
+ ctx.addIssue({ code: "custom", message: getMessage("min", { min: minFormatted }) });
254
+ return;
255
+ }
256
+ }
257
+ if (max) {
258
+ const maxParsed = typeof max === "string" ? parseDateTimeValue(max, format, timezone2) : dayjs(max);
259
+ if (maxParsed && parsed.isAfter(maxParsed)) {
260
+ const maxFormatted = typeof max === "string" ? max : maxParsed.format(format);
261
+ ctx.addIssue({ code: "custom", message: getMessage("max", { max: maxFormatted }) });
262
+ return;
263
+ }
264
+ }
265
+ const now = timezone2 ? dayjs().tz(timezone2) : dayjs();
266
+ if (mustBePast && !parsed.isBefore(now)) {
267
+ ctx.addIssue({ code: "custom", message: getMessage("past") });
268
+ return;
269
+ }
270
+ if (mustBeFuture && !parsed.isAfter(now)) {
271
+ ctx.addIssue({ code: "custom", message: getMessage("future") });
272
+ return;
273
+ }
274
+ if (mustBeToday && !parsed.isSame(now, "day")) {
275
+ ctx.addIssue({ code: "custom", message: getMessage("today") });
276
+ return;
277
+ }
278
+ if (mustNotBeToday && parsed.isSame(now, "day")) {
279
+ ctx.addIssue({ code: "custom", message: getMessage("notToday") });
280
+ return;
281
+ }
282
+ const dayOfWeek = parsed.day();
283
+ if (weekdaysOnly && (dayOfWeek === 0 || dayOfWeek === 6)) {
284
+ ctx.addIssue({ code: "custom", message: getMessage("weekday") });
285
+ return;
286
+ }
287
+ if (weekendsOnly && dayOfWeek !== 0 && dayOfWeek !== 6) {
288
+ ctx.addIssue({ code: "custom", message: getMessage("weekend") });
289
+ return;
290
+ }
291
+ });
292
+ return schema;
293
+ }
294
+
295
+ export {
296
+ DATETIME_PATTERNS,
297
+ validateDateTimeFormat,
298
+ parseDateTimeValue,
299
+ normalizeDateTimeValue,
300
+ datetime
301
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkTFGS34VDcjs = require('../chunk-TFGS34VD.cjs');
4
+ require('../chunk-UCOXAZJF.cjs');
5
+
6
+
7
+ exports.boolean = _chunkTFGS34VDcjs.boolean;
@@ -0,0 +1,119 @@
1
+ import { ZodBoolean, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ /**
5
+ * @fileoverview Boolean validator for Zod Kit
6
+ *
7
+ * Provides flexible boolean validation with support for various truthy/falsy values,
8
+ * strict mode validation, and comprehensive transformation options.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for boolean validation error messages
16
+ *
17
+ * @interface BooleanMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [shouldBeTrue] - Message when value should be true but isn't
20
+ * @property {string} [shouldBeFalse] - Message when value should be false but isn't
21
+ * @property {string} [invalid] - Message when value is not a valid boolean
22
+ */
23
+ type BooleanMessages = {
24
+ required?: string;
25
+ shouldBeTrue?: string;
26
+ shouldBeFalse?: string;
27
+ invalid?: string;
28
+ };
29
+ /**
30
+ * Configuration options for boolean validation
31
+ *
32
+ * @template IsRequired - Whether the field is required (affects return type)
33
+ *
34
+ * @interface BooleanOptions
35
+ * @property {boolean | null} [defaultValue] - Default value when input is empty
36
+ * @property {boolean} [shouldBe] - Specific boolean value that must be matched
37
+ * @property {unknown[]} [truthyValues] - Array of values that should be treated as true
38
+ * @property {unknown[]} [falsyValues] - Array of values that should be treated as false
39
+ * @property {boolean} [strict=false] - If true, only accepts actual boolean values
40
+ * @property {Function} [transform] - Custom transformation function for boolean values
41
+ * @property {Record<Locale, BooleanMessages>} [i18n] - Custom error messages for different locales
42
+ */
43
+ type BooleanOptions<IsRequired extends boolean = true> = {
44
+ defaultValue?: IsRequired extends true ? boolean : boolean | null;
45
+ shouldBe?: boolean;
46
+ truthyValues?: unknown[];
47
+ falsyValues?: unknown[];
48
+ strict?: boolean;
49
+ transform?: (value: boolean) => boolean;
50
+ i18n?: Partial<Record<Locale, Partial<BooleanMessages>>>;
51
+ };
52
+ /**
53
+ * Type alias for boolean validation schema based on required flag
54
+ *
55
+ * @template IsRequired - Whether the field is required
56
+ * @typedef BooleanSchema
57
+ * @description Returns ZodBoolean if required, ZodNullable<ZodBoolean> if optional
58
+ */
59
+ type BooleanSchema<IsRequired extends boolean> = IsRequired extends true ? ZodBoolean : ZodNullable<ZodBoolean>;
60
+ /**
61
+ * Creates a Zod schema for boolean validation with flexible value interpretation
62
+ *
63
+ * @template IsRequired - Whether the field is required (affects return type)
64
+ * @param {IsRequired} [required=false] - Whether the field is required
65
+ * @param {Omit<BooleanOptions<IsRequired>, 'required'>} [options] - Configuration options for boolean validation
66
+ * @returns {BooleanSchema<IsRequired>} Zod schema for boolean validation
67
+ *
68
+ * @description
69
+ * Creates a flexible boolean validator that can interpret various values as true/false,
70
+ * supports strict mode for type safety, and provides comprehensive transformation options.
71
+ *
72
+ * Features:
73
+ * - Flexible truthy/falsy value interpretation
74
+ * - Strict mode for type safety
75
+ * - Custom transformation functions
76
+ * - Specific boolean value requirements
77
+ * - Comprehensive internationalization
78
+ * - Default value support
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Basic boolean validation (optional by default)
83
+ * const basicSchema = boolean()
84
+ * basicSchema.parse(true) // ✓ Valid
85
+ * basicSchema.parse("true") // ✓ Valid (converted to true)
86
+ * basicSchema.parse(null) // ✓ Valid (optional)
87
+ *
88
+ * // Required boolean
89
+ * const requiredSchema = boolean(true)
90
+ * requiredSchema.parse(true) // ✓ Valid
91
+ * requiredSchema.parse(null) // ✗ Invalid (required)
92
+ *
93
+ * // Strict mode (only actual booleans)
94
+ * const strictSchema = boolean(false, { strict: true })
95
+ * strictSchema.parse(true) // ✓ Valid
96
+ * strictSchema.parse("true") // ✗ Invalid
97
+ *
98
+ * // Must be true
99
+ * const mustBeTrueSchema = boolean(true, { shouldBe: true })
100
+ * mustBeTrueSchema.parse(true) // ✓ Valid
101
+ * mustBeTrueSchema.parse(false) // ✗ Invalid
102
+ *
103
+ * // Custom truthy/falsy values
104
+ * const customSchema = boolean(false, {
105
+ * truthyValues: ["yes", "on", 1],
106
+ * falsyValues: ["no", "off", 0]
107
+ * })
108
+ * customSchema.parse("yes") // ✓ Valid (converted to true)
109
+ *
110
+ * // Optional with default
111
+ * const optionalSchema = boolean(false, { defaultValue: false })
112
+ * ```
113
+ *
114
+ * @throws {z.ZodError} When validation fails with specific error messages
115
+ * @see {@link BooleanOptions} for all available configuration options
116
+ */
117
+ declare function boolean<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<BooleanOptions<IsRequired>, 'required'>): BooleanSchema<IsRequired>;
118
+
119
+ export { type BooleanMessages, type BooleanOptions, type BooleanSchema, boolean };
@@ -0,0 +1,119 @@
1
+ import { ZodBoolean, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ /**
5
+ * @fileoverview Boolean validator for Zod Kit
6
+ *
7
+ * Provides flexible boolean validation with support for various truthy/falsy values,
8
+ * strict mode validation, and comprehensive transformation options.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for boolean validation error messages
16
+ *
17
+ * @interface BooleanMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [shouldBeTrue] - Message when value should be true but isn't
20
+ * @property {string} [shouldBeFalse] - Message when value should be false but isn't
21
+ * @property {string} [invalid] - Message when value is not a valid boolean
22
+ */
23
+ type BooleanMessages = {
24
+ required?: string;
25
+ shouldBeTrue?: string;
26
+ shouldBeFalse?: string;
27
+ invalid?: string;
28
+ };
29
+ /**
30
+ * Configuration options for boolean validation
31
+ *
32
+ * @template IsRequired - Whether the field is required (affects return type)
33
+ *
34
+ * @interface BooleanOptions
35
+ * @property {boolean | null} [defaultValue] - Default value when input is empty
36
+ * @property {boolean} [shouldBe] - Specific boolean value that must be matched
37
+ * @property {unknown[]} [truthyValues] - Array of values that should be treated as true
38
+ * @property {unknown[]} [falsyValues] - Array of values that should be treated as false
39
+ * @property {boolean} [strict=false] - If true, only accepts actual boolean values
40
+ * @property {Function} [transform] - Custom transformation function for boolean values
41
+ * @property {Record<Locale, BooleanMessages>} [i18n] - Custom error messages for different locales
42
+ */
43
+ type BooleanOptions<IsRequired extends boolean = true> = {
44
+ defaultValue?: IsRequired extends true ? boolean : boolean | null;
45
+ shouldBe?: boolean;
46
+ truthyValues?: unknown[];
47
+ falsyValues?: unknown[];
48
+ strict?: boolean;
49
+ transform?: (value: boolean) => boolean;
50
+ i18n?: Partial<Record<Locale, Partial<BooleanMessages>>>;
51
+ };
52
+ /**
53
+ * Type alias for boolean validation schema based on required flag
54
+ *
55
+ * @template IsRequired - Whether the field is required
56
+ * @typedef BooleanSchema
57
+ * @description Returns ZodBoolean if required, ZodNullable<ZodBoolean> if optional
58
+ */
59
+ type BooleanSchema<IsRequired extends boolean> = IsRequired extends true ? ZodBoolean : ZodNullable<ZodBoolean>;
60
+ /**
61
+ * Creates a Zod schema for boolean validation with flexible value interpretation
62
+ *
63
+ * @template IsRequired - Whether the field is required (affects return type)
64
+ * @param {IsRequired} [required=false] - Whether the field is required
65
+ * @param {Omit<BooleanOptions<IsRequired>, 'required'>} [options] - Configuration options for boolean validation
66
+ * @returns {BooleanSchema<IsRequired>} Zod schema for boolean validation
67
+ *
68
+ * @description
69
+ * Creates a flexible boolean validator that can interpret various values as true/false,
70
+ * supports strict mode for type safety, and provides comprehensive transformation options.
71
+ *
72
+ * Features:
73
+ * - Flexible truthy/falsy value interpretation
74
+ * - Strict mode for type safety
75
+ * - Custom transformation functions
76
+ * - Specific boolean value requirements
77
+ * - Comprehensive internationalization
78
+ * - Default value support
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Basic boolean validation (optional by default)
83
+ * const basicSchema = boolean()
84
+ * basicSchema.parse(true) // ✓ Valid
85
+ * basicSchema.parse("true") // ✓ Valid (converted to true)
86
+ * basicSchema.parse(null) // ✓ Valid (optional)
87
+ *
88
+ * // Required boolean
89
+ * const requiredSchema = boolean(true)
90
+ * requiredSchema.parse(true) // ✓ Valid
91
+ * requiredSchema.parse(null) // ✗ Invalid (required)
92
+ *
93
+ * // Strict mode (only actual booleans)
94
+ * const strictSchema = boolean(false, { strict: true })
95
+ * strictSchema.parse(true) // ✓ Valid
96
+ * strictSchema.parse("true") // ✗ Invalid
97
+ *
98
+ * // Must be true
99
+ * const mustBeTrueSchema = boolean(true, { shouldBe: true })
100
+ * mustBeTrueSchema.parse(true) // ✓ Valid
101
+ * mustBeTrueSchema.parse(false) // ✗ Invalid
102
+ *
103
+ * // Custom truthy/falsy values
104
+ * const customSchema = boolean(false, {
105
+ * truthyValues: ["yes", "on", 1],
106
+ * falsyValues: ["no", "off", 0]
107
+ * })
108
+ * customSchema.parse("yes") // ✓ Valid (converted to true)
109
+ *
110
+ * // Optional with default
111
+ * const optionalSchema = boolean(false, { defaultValue: false })
112
+ * ```
113
+ *
114
+ * @throws {z.ZodError} When validation fails with specific error messages
115
+ * @see {@link BooleanOptions} for all available configuration options
116
+ */
117
+ declare function boolean<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<BooleanOptions<IsRequired>, 'required'>): BooleanSchema<IsRequired>;
118
+
119
+ export { type BooleanMessages, type BooleanOptions, type BooleanSchema, boolean };
@@ -0,0 +1,7 @@
1
+ import {
2
+ boolean
3
+ } from "../chunk-42C5OHRK.js";
4
+ import "../chunk-6AAP4LPF.js";
5
+ export {
6
+ boolean
7
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkUBK3VCVHcjs = require('../chunk-UBK3VCVH.cjs');
5
+ require('../chunk-UCOXAZJF.cjs');
6
+
7
+
8
+
9
+ exports.color = _chunkUBK3VCVHcjs.color; exports.validateColor = _chunkUBK3VCVHcjs.validateColor;
@@ -0,0 +1,26 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ type ColorFormat = "hex" | "rgb" | "hsl" | "any";
5
+ type ColorMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ notHex?: string;
9
+ notRgb?: string;
10
+ notHsl?: string;
11
+ };
12
+ type ColorOptions<IsRequired extends boolean = true> = {
13
+ format?: ColorFormat | ColorFormat[];
14
+ allowAlpha?: boolean;
15
+ transform?: (value: string) => string;
16
+ defaultValue?: IsRequired extends true ? string : string | null;
17
+ i18n?: Partial<Record<Locale, Partial<ColorMessages>>>;
18
+ };
19
+ type ColorSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
20
+ declare function validateColor(value: string, formats: ColorFormat[], allowAlpha: boolean): {
21
+ valid: boolean;
22
+ failedFormat?: ColorFormat;
23
+ };
24
+ declare function color<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<ColorOptions<IsRequired>, "required">): ColorSchema<IsRequired>;
25
+
26
+ export { type ColorFormat, type ColorMessages, type ColorOptions, type ColorSchema, color, validateColor };
@@ -0,0 +1,26 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ type ColorFormat = "hex" | "rgb" | "hsl" | "any";
5
+ type ColorMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ notHex?: string;
9
+ notRgb?: string;
10
+ notHsl?: string;
11
+ };
12
+ type ColorOptions<IsRequired extends boolean = true> = {
13
+ format?: ColorFormat | ColorFormat[];
14
+ allowAlpha?: boolean;
15
+ transform?: (value: string) => string;
16
+ defaultValue?: IsRequired extends true ? string : string | null;
17
+ i18n?: Partial<Record<Locale, Partial<ColorMessages>>>;
18
+ };
19
+ type ColorSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
20
+ declare function validateColor(value: string, formats: ColorFormat[], allowAlpha: boolean): {
21
+ valid: boolean;
22
+ failedFormat?: ColorFormat;
23
+ };
24
+ declare function color<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<ColorOptions<IsRequired>, "required">): ColorSchema<IsRequired>;
25
+
26
+ export { type ColorFormat, type ColorMessages, type ColorOptions, type ColorSchema, color, validateColor };
@@ -0,0 +1,9 @@
1
+ import {
2
+ color,
3
+ validateColor
4
+ } from "../chunk-2SWEVDFZ.js";
5
+ import "../chunk-6AAP4LPF.js";
6
+ export {
7
+ color,
8
+ validateColor
9
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkRYFG2GKMcjs = require('../chunk-RYFG2GKM.cjs');
6
+ require('../chunk-UCOXAZJF.cjs');
7
+
8
+
9
+
10
+
11
+ exports.coordinate = _chunkRYFG2GKMcjs.coordinate; exports.validateLatitude = _chunkRYFG2GKMcjs.validateLatitude; exports.validateLongitude = _chunkRYFG2GKMcjs.validateLongitude;
@@ -0,0 +1,23 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ type CoordinateType = "latitude" | "longitude" | "pair";
5
+ type CoordinateMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ invalidLatitude?: string;
9
+ invalidLongitude?: string;
10
+ };
11
+ type CoordinateOptions<IsRequired extends boolean = true> = {
12
+ type?: CoordinateType;
13
+ precision?: number;
14
+ transform?: (value: string) => string;
15
+ defaultValue?: IsRequired extends true ? string : string | null;
16
+ i18n?: Partial<Record<Locale, Partial<CoordinateMessages>>>;
17
+ };
18
+ type CoordinateSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
19
+ declare function validateLatitude(value: number): boolean;
20
+ declare function validateLongitude(value: number): boolean;
21
+ declare function coordinate<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<CoordinateOptions<IsRequired>, "required">): CoordinateSchema<IsRequired>;
22
+
23
+ export { type CoordinateMessages, type CoordinateOptions, type CoordinateSchema, type CoordinateType, coordinate, validateLatitude, validateLongitude };