@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 { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+ import dayjs from 'dayjs';
4
+
5
+ /**
6
+ * @fileoverview DateTime validator for Zod Kit
7
+ *
8
+ * Provides comprehensive datetime validation with support for multiple formats,
9
+ * timezone handling, range validation, and internationalization.
10
+ *
11
+ * @author Ong Hoe Yuan
12
+ * @version 0.0.5
13
+ */
14
+
15
+ /**
16
+ * Type definition for datetime validation error messages
17
+ *
18
+ * @interface DateTimeMessages
19
+ * @property {string} [required] - Message when field is required but empty
20
+ * @property {string} [invalid] - Message when datetime format is invalid
21
+ * @property {string} [format] - Message when datetime doesn't match expected format
22
+ * @property {string} [min] - Message when datetime is before minimum allowed
23
+ * @property {string} [max] - Message when datetime is after maximum allowed
24
+ * @property {string} [includes] - Message when datetime doesn't include required string
25
+ * @property {string} [excludes] - Message when datetime contains excluded string
26
+ * @property {string} [past] - Message when datetime must be in the past
27
+ * @property {string} [future] - Message when datetime must be in the future
28
+ * @property {string} [today] - Message when datetime must be today
29
+ * @property {string} [notToday] - Message when datetime must not be today
30
+ * @property {string} [weekday] - Message when datetime must be a weekday
31
+ * @property {string} [weekend] - Message when datetime must be a weekend
32
+ * @property {string} [hour] - Message when hour is outside allowed range
33
+ * @property {string} [minute] - Message when minute doesn't match step requirement
34
+ * @property {string} [customRegex] - Message when custom regex validation fails
35
+ * @property {string} [notInWhitelist] - Message when value is not in whitelist
36
+ */
37
+ type DateTimeMessages = {
38
+ required?: string;
39
+ invalid?: string;
40
+ format?: string;
41
+ min?: string;
42
+ max?: string;
43
+ includes?: string;
44
+ excludes?: string;
45
+ past?: string;
46
+ future?: string;
47
+ today?: string;
48
+ notToday?: string;
49
+ weekday?: string;
50
+ weekend?: string;
51
+ hour?: string;
52
+ minute?: string;
53
+ customRegex?: string;
54
+ notInWhitelist?: string;
55
+ };
56
+ /**
57
+ * Supported datetime formats for validation
58
+ *
59
+ * @typedef {string} DateTimeFormat
60
+ *
61
+ * Standard formats:
62
+ * - YYYY-MM-DD HH:mm: ISO-style date with 24-hour time (2024-03-15 14:30)
63
+ * - YYYY-MM-DD HH:mm:ss: ISO-style date with seconds (2024-03-15 14:30:45)
64
+ * - YYYY-MM-DD hh:mm A: ISO-style date with 12-hour time (2024-03-15 02:30 PM)
65
+ * - YYYY-MM-DD hh:mm:ss A: ISO-style date with 12-hour time and seconds (2024-03-15 02:30:45 PM)
66
+ *
67
+ * Regional formats:
68
+ * - DD/MM/YYYY HH:mm: European format (15/03/2024 14:30)
69
+ * - DD/MM/YYYY HH:mm:ss: European format with seconds (15/03/2024 14:30:45)
70
+ * - DD/MM/YYYY hh:mm A: European format with 12-hour time (15/03/2024 02:30 PM)
71
+ * - MM/DD/YYYY HH:mm: US format (03/15/2024 14:30)
72
+ * - MM/DD/YYYY hh:mm A: US format with 12-hour time (03/15/2024 02:30 PM)
73
+ * - YYYY/MM/DD HH:mm: Alternative slash format (2024/03/15 14:30)
74
+ * - DD-MM-YYYY HH:mm: European dash format (15-03-2024 14:30)
75
+ * - MM-DD-YYYY HH:mm: US dash format (03-15-2024 14:30)
76
+ *
77
+ * Special formats:
78
+ * - ISO: ISO 8601 format (2024-03-15T14:30:45.000Z)
79
+ * - RFC: RFC 2822 format (Fri, 15 Mar 2024 14:30:45 GMT)
80
+ * - UNIX: Unix timestamp (1710508245)
81
+ */
82
+ type DateTimeFormat = "YYYY-MM-DD HH:mm" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM-DD hh:mm A" | "YYYY-MM-DD hh:mm:ss A" | "DD/MM/YYYY HH:mm" | "DD/MM/YYYY HH:mm:ss" | "DD/MM/YYYY hh:mm A" | "MM/DD/YYYY HH:mm" | "MM/DD/YYYY hh:mm A" | "YYYY/MM/DD HH:mm" | "DD-MM-YYYY HH:mm" | "MM-DD-YYYY HH:mm" | "ISO" | "RFC" | "UNIX";
83
+ /**
84
+ * Configuration options for datetime validation
85
+ *
86
+ * @template IsRequired - Whether the field is required (affects return type)
87
+ *
88
+ * @interface DateTimeOptions
89
+ * @property {IsRequired} [required=true] - Whether the field is required
90
+ * @property {DateTimeFormat} [format="YYYY-MM-DD HH:mm"] - Expected datetime format
91
+ * @property {string | Date} [min] - Minimum allowed datetime
92
+ * @property {string | Date} [max] - Maximum allowed datetime
93
+ * @property {number} [minHour] - Minimum allowed hour (0-23)
94
+ * @property {number} [maxHour] - Maximum allowed hour (0-23)
95
+ * @property {number[]} [allowedHours] - Specific hours that are allowed
96
+ * @property {number} [minuteStep] - Required minute intervals (e.g., 15 for :00, :15, :30, :45)
97
+ * @property {string} [timezone] - Timezone for parsing and validation (e.g., "Asia/Taipei")
98
+ * @property {string} [includes] - String that must be included in the datetime
99
+ * @property {string | string[]} [excludes] - String(s) that must not be included
100
+ * @property {RegExp} [regex] - Custom regex for validation (overrides format validation)
101
+ * @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
102
+ * @property {"upper" | "lower" | "none"} [casing="none"] - Case transformation
103
+ * @property {boolean} [mustBePast] - Whether datetime must be in the past
104
+ * @property {boolean} [mustBeFuture] - Whether datetime must be in the future
105
+ * @property {boolean} [mustBeToday] - Whether datetime must be today
106
+ * @property {boolean} [mustNotBeToday] - Whether datetime must not be today
107
+ * @property {boolean} [weekdaysOnly] - Whether datetime must be a weekday (Monday-Friday)
108
+ * @property {boolean} [weekendsOnly] - Whether datetime must be a weekend (Saturday-Sunday)
109
+ * @property {string[]} [whitelist] - Specific datetime strings that are always allowed
110
+ * @property {boolean} [whitelistOnly=false] - If true, only values in whitelist are allowed
111
+ * @property {Function} [transform] - Custom transformation function applied before validation
112
+ * @property {string | null} [defaultValue] - Default value when input is empty
113
+ * @property {Record<Locale, DateTimeMessages>} [i18n] - Custom error messages for different locales
114
+ */
115
+ type DateTimeOptions<IsRequired extends boolean = true> = {
116
+ format?: DateTimeFormat;
117
+ min?: string | Date;
118
+ max?: string | Date;
119
+ minHour?: number;
120
+ maxHour?: number;
121
+ allowedHours?: number[];
122
+ minuteStep?: number;
123
+ timezone?: string;
124
+ includes?: string;
125
+ excludes?: string | string[];
126
+ regex?: RegExp;
127
+ trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
128
+ casing?: "upper" | "lower" | "none";
129
+ mustBePast?: boolean;
130
+ mustBeFuture?: boolean;
131
+ mustBeToday?: boolean;
132
+ mustNotBeToday?: boolean;
133
+ weekdaysOnly?: boolean;
134
+ weekendsOnly?: boolean;
135
+ whitelist?: string[];
136
+ whitelistOnly?: boolean;
137
+ transform?: (value: string) => string;
138
+ defaultValue?: IsRequired extends true ? string : string | null;
139
+ i18n?: Partial<Record<Locale, Partial<DateTimeMessages>>>;
140
+ };
141
+ /**
142
+ * Type alias for datetime validation schema based on required flag
143
+ *
144
+ * @template IsRequired - Whether the field is required
145
+ * @typedef DateTimeSchema
146
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
147
+ */
148
+ type DateTimeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
149
+ /**
150
+ * Regular expression patterns for datetime format validation
151
+ *
152
+ * @constant {Record<DateTimeFormat, RegExp>} DATETIME_PATTERNS
153
+ * @description Maps each supported datetime format to its corresponding regex pattern
154
+ *
155
+ * Pattern explanations:
156
+ * - YYYY-MM-DD HH:mm: 4-digit year, 2-digit month, 2-digit day, 24-hour time
157
+ * - ISO: ISO 8601 format with optional milliseconds and timezone
158
+ * - RFC: RFC 2822 format with day name, date, time, and timezone
159
+ * - UNIX: 10-digit Unix timestamp
160
+ */
161
+ declare const DATETIME_PATTERNS: Record<DateTimeFormat, RegExp>;
162
+ /**
163
+ * Validates if a datetime string matches the specified format pattern
164
+ *
165
+ * @param {string} value - The datetime string to validate
166
+ * @param {DateTimeFormat} format - The expected datetime format
167
+ * @returns {boolean} True if the datetime is valid for the given format
168
+ *
169
+ * @description
170
+ * Performs both regex pattern matching and actual datetime parsing validation.
171
+ * Returns false if either the pattern doesn't match or the parsed datetime is invalid.
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * validateDateTimeFormat("2024-03-15 14:30", "YYYY-MM-DD HH:mm") // true
176
+ * validateDateTimeFormat("2024-03-15 25:30", "YYYY-MM-DD HH:mm") // false (invalid hour)
177
+ * validateDateTimeFormat("15/03/2024", "YYYY-MM-DD HH:mm") // false (wrong format)
178
+ * ```
179
+ */
180
+ declare const validateDateTimeFormat: (value: string, format: DateTimeFormat) => boolean;
181
+ /**
182
+ * Parses a datetime string into a dayjs object using the specified format
183
+ *
184
+ * @param {string} value - The datetime string to parse
185
+ * @param {DateTimeFormat} format - The expected datetime format
186
+ * @param {string} [timezone] - Optional timezone for parsing (e.g., "Asia/Taipei")
187
+ * @returns {dayjs.Dayjs | null} Parsed dayjs object or null if parsing fails
188
+ *
189
+ * @description
190
+ * Handles different datetime formats including ISO, RFC, Unix timestamps, and custom formats.
191
+ * Uses strict parsing mode for custom formats to ensure accuracy.
192
+ * Applies timezone conversion if specified.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * parseDateTimeValue("2024-03-15 14:30", "YYYY-MM-DD HH:mm")
197
+ * // Returns dayjs object for March 15, 2024 at 2:30 PM
198
+ *
199
+ * parseDateTimeValue("1710508245", "UNIX")
200
+ * // Returns dayjs object for the Unix timestamp
201
+ *
202
+ * parseDateTimeValue("2024-03-15T14:30:45.000Z", "ISO")
203
+ * // Returns dayjs object for the ISO datetime
204
+ * ```
205
+ *
206
+ * @throws {Error} Returns null if parsing fails or datetime is invalid
207
+ */
208
+ declare const parseDateTimeValue: (value: string, format: DateTimeFormat, timezone?: string) => dayjs.Dayjs | null;
209
+ /**
210
+ * Normalizes a datetime string to the specified format
211
+ *
212
+ * @param {string} value - The datetime string to normalize
213
+ * @param {DateTimeFormat} format - The target datetime format
214
+ * @param {string} [timezone] - Optional timezone for formatting
215
+ * @returns {string | null} Normalized datetime string or null if parsing fails
216
+ *
217
+ * @description
218
+ * Parses the input datetime and formats it according to the specified format.
219
+ * Handles special formats like ISO, RFC, and Unix timestamps appropriately.
220
+ * Returns null if the input datetime cannot be parsed.
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * normalizeDateTimeValue("2024-3-15 2:30 PM", "YYYY-MM-DD HH:mm")
225
+ * // Returns "2024-03-15 14:30"
226
+ *
227
+ * normalizeDateTimeValue("1710508245", "ISO")
228
+ * // Returns "2024-03-15T14:30:45.000Z"
229
+ * ```
230
+ */
231
+ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, timezone?: string) => string | null;
232
+ /**
233
+ * Creates a Zod schema for datetime validation with comprehensive options
234
+ *
235
+ * @template IsRequired - Whether the field is required (affects return type)
236
+ * @param {IsRequired} [required=false] - Whether the field is required
237
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
238
+ * @returns {DateTimeSchema<IsRequired>} Zod schema for datetime validation
239
+ *
240
+ * @description
241
+ * Creates a comprehensive datetime validator that supports multiple formats, timezone handling,
242
+ * range validation, temporal constraints, and extensive customization options.
243
+ *
244
+ * Features:
245
+ * - Multiple datetime formats (ISO, RFC, Unix, regional formats)
246
+ * - Timezone support and conversion
247
+ * - Range validation (min/max datetime)
248
+ * - Hour and minute constraints
249
+ * - Temporal validation (past/future/today)
250
+ * - Weekday/weekend validation
251
+ * - Whitelist/blacklist support
252
+ * - Custom regex patterns
253
+ * - String transformation and case handling
254
+ * - Comprehensive internationalization
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // Basic datetime validation
259
+ * const basicSchema = datetime() // optional by default
260
+ * basicSchema.parse("2024-03-15 14:30") // ✓ Valid
261
+ * basicSchema.parse(null) // ✓ Valid (optional)
262
+ *
263
+ * // Required validation
264
+ * const requiredSchema = parse("2024-03-15 14:30") // ✓ Valid
265
+ (true)
266
+ * requiredSchema.parse(null) // ✗ Invalid (required)
267
+ *
268
+ *
269
+ * // Business hours validation
270
+ * const businessHours = datetime({
271
+ * format: "YYYY-MM-DD HH:mm",
272
+ * minHour: 9,
273
+ * maxHour: 17,
274
+ * weekdaysOnly: true
275
+ * })
276
+ *
277
+ * // Timezone-aware validation
278
+ * const timezoneSchema = datetime(false, {
279
+ * timezone: "Asia/Taipei",
280
+ * mustBeFuture: true
281
+ * })
282
+ *
283
+ * // Multiple format support
284
+ * const flexibleSchema = datetime(false, {
285
+ * format: "DD/MM/YYYY HH:mm"
286
+ * })
287
+ * flexibleSchema.parse("15/03/2024 14:30") // ✓ Valid
288
+ *
289
+ * // Optional with default
290
+ * const optionalSchema = datetime(false, {
291
+ * defaultValue: "2024-01-01 00:00"
292
+ * })
293
+ * ```
294
+ *
295
+ * @throws {z.ZodError} When validation fails with specific error messages
296
+ * @see {@link DateTimeOptions} for all available configuration options
297
+ * @see {@link DateTimeFormat} for supported datetime formats
298
+ */
299
+ declare function datetime<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateTimeOptions<IsRequired>, 'required'>): DateTimeSchema<IsRequired>;
300
+
301
+ export { DATETIME_PATTERNS, type DateTimeFormat, type DateTimeMessages, type DateTimeOptions, type DateTimeSchema, datetime, normalizeDateTimeValue, parseDateTimeValue, validateDateTimeFormat };
@@ -0,0 +1,301 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+ import dayjs from 'dayjs';
4
+
5
+ /**
6
+ * @fileoverview DateTime validator for Zod Kit
7
+ *
8
+ * Provides comprehensive datetime validation with support for multiple formats,
9
+ * timezone handling, range validation, and internationalization.
10
+ *
11
+ * @author Ong Hoe Yuan
12
+ * @version 0.0.5
13
+ */
14
+
15
+ /**
16
+ * Type definition for datetime validation error messages
17
+ *
18
+ * @interface DateTimeMessages
19
+ * @property {string} [required] - Message when field is required but empty
20
+ * @property {string} [invalid] - Message when datetime format is invalid
21
+ * @property {string} [format] - Message when datetime doesn't match expected format
22
+ * @property {string} [min] - Message when datetime is before minimum allowed
23
+ * @property {string} [max] - Message when datetime is after maximum allowed
24
+ * @property {string} [includes] - Message when datetime doesn't include required string
25
+ * @property {string} [excludes] - Message when datetime contains excluded string
26
+ * @property {string} [past] - Message when datetime must be in the past
27
+ * @property {string} [future] - Message when datetime must be in the future
28
+ * @property {string} [today] - Message when datetime must be today
29
+ * @property {string} [notToday] - Message when datetime must not be today
30
+ * @property {string} [weekday] - Message when datetime must be a weekday
31
+ * @property {string} [weekend] - Message when datetime must be a weekend
32
+ * @property {string} [hour] - Message when hour is outside allowed range
33
+ * @property {string} [minute] - Message when minute doesn't match step requirement
34
+ * @property {string} [customRegex] - Message when custom regex validation fails
35
+ * @property {string} [notInWhitelist] - Message when value is not in whitelist
36
+ */
37
+ type DateTimeMessages = {
38
+ required?: string;
39
+ invalid?: string;
40
+ format?: string;
41
+ min?: string;
42
+ max?: string;
43
+ includes?: string;
44
+ excludes?: string;
45
+ past?: string;
46
+ future?: string;
47
+ today?: string;
48
+ notToday?: string;
49
+ weekday?: string;
50
+ weekend?: string;
51
+ hour?: string;
52
+ minute?: string;
53
+ customRegex?: string;
54
+ notInWhitelist?: string;
55
+ };
56
+ /**
57
+ * Supported datetime formats for validation
58
+ *
59
+ * @typedef {string} DateTimeFormat
60
+ *
61
+ * Standard formats:
62
+ * - YYYY-MM-DD HH:mm: ISO-style date with 24-hour time (2024-03-15 14:30)
63
+ * - YYYY-MM-DD HH:mm:ss: ISO-style date with seconds (2024-03-15 14:30:45)
64
+ * - YYYY-MM-DD hh:mm A: ISO-style date with 12-hour time (2024-03-15 02:30 PM)
65
+ * - YYYY-MM-DD hh:mm:ss A: ISO-style date with 12-hour time and seconds (2024-03-15 02:30:45 PM)
66
+ *
67
+ * Regional formats:
68
+ * - DD/MM/YYYY HH:mm: European format (15/03/2024 14:30)
69
+ * - DD/MM/YYYY HH:mm:ss: European format with seconds (15/03/2024 14:30:45)
70
+ * - DD/MM/YYYY hh:mm A: European format with 12-hour time (15/03/2024 02:30 PM)
71
+ * - MM/DD/YYYY HH:mm: US format (03/15/2024 14:30)
72
+ * - MM/DD/YYYY hh:mm A: US format with 12-hour time (03/15/2024 02:30 PM)
73
+ * - YYYY/MM/DD HH:mm: Alternative slash format (2024/03/15 14:30)
74
+ * - DD-MM-YYYY HH:mm: European dash format (15-03-2024 14:30)
75
+ * - MM-DD-YYYY HH:mm: US dash format (03-15-2024 14:30)
76
+ *
77
+ * Special formats:
78
+ * - ISO: ISO 8601 format (2024-03-15T14:30:45.000Z)
79
+ * - RFC: RFC 2822 format (Fri, 15 Mar 2024 14:30:45 GMT)
80
+ * - UNIX: Unix timestamp (1710508245)
81
+ */
82
+ type DateTimeFormat = "YYYY-MM-DD HH:mm" | "YYYY-MM-DD HH:mm:ss" | "YYYY-MM-DD hh:mm A" | "YYYY-MM-DD hh:mm:ss A" | "DD/MM/YYYY HH:mm" | "DD/MM/YYYY HH:mm:ss" | "DD/MM/YYYY hh:mm A" | "MM/DD/YYYY HH:mm" | "MM/DD/YYYY hh:mm A" | "YYYY/MM/DD HH:mm" | "DD-MM-YYYY HH:mm" | "MM-DD-YYYY HH:mm" | "ISO" | "RFC" | "UNIX";
83
+ /**
84
+ * Configuration options for datetime validation
85
+ *
86
+ * @template IsRequired - Whether the field is required (affects return type)
87
+ *
88
+ * @interface DateTimeOptions
89
+ * @property {IsRequired} [required=true] - Whether the field is required
90
+ * @property {DateTimeFormat} [format="YYYY-MM-DD HH:mm"] - Expected datetime format
91
+ * @property {string | Date} [min] - Minimum allowed datetime
92
+ * @property {string | Date} [max] - Maximum allowed datetime
93
+ * @property {number} [minHour] - Minimum allowed hour (0-23)
94
+ * @property {number} [maxHour] - Maximum allowed hour (0-23)
95
+ * @property {number[]} [allowedHours] - Specific hours that are allowed
96
+ * @property {number} [minuteStep] - Required minute intervals (e.g., 15 for :00, :15, :30, :45)
97
+ * @property {string} [timezone] - Timezone for parsing and validation (e.g., "Asia/Taipei")
98
+ * @property {string} [includes] - String that must be included in the datetime
99
+ * @property {string | string[]} [excludes] - String(s) that must not be included
100
+ * @property {RegExp} [regex] - Custom regex for validation (overrides format validation)
101
+ * @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
102
+ * @property {"upper" | "lower" | "none"} [casing="none"] - Case transformation
103
+ * @property {boolean} [mustBePast] - Whether datetime must be in the past
104
+ * @property {boolean} [mustBeFuture] - Whether datetime must be in the future
105
+ * @property {boolean} [mustBeToday] - Whether datetime must be today
106
+ * @property {boolean} [mustNotBeToday] - Whether datetime must not be today
107
+ * @property {boolean} [weekdaysOnly] - Whether datetime must be a weekday (Monday-Friday)
108
+ * @property {boolean} [weekendsOnly] - Whether datetime must be a weekend (Saturday-Sunday)
109
+ * @property {string[]} [whitelist] - Specific datetime strings that are always allowed
110
+ * @property {boolean} [whitelistOnly=false] - If true, only values in whitelist are allowed
111
+ * @property {Function} [transform] - Custom transformation function applied before validation
112
+ * @property {string | null} [defaultValue] - Default value when input is empty
113
+ * @property {Record<Locale, DateTimeMessages>} [i18n] - Custom error messages for different locales
114
+ */
115
+ type DateTimeOptions<IsRequired extends boolean = true> = {
116
+ format?: DateTimeFormat;
117
+ min?: string | Date;
118
+ max?: string | Date;
119
+ minHour?: number;
120
+ maxHour?: number;
121
+ allowedHours?: number[];
122
+ minuteStep?: number;
123
+ timezone?: string;
124
+ includes?: string;
125
+ excludes?: string | string[];
126
+ regex?: RegExp;
127
+ trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
128
+ casing?: "upper" | "lower" | "none";
129
+ mustBePast?: boolean;
130
+ mustBeFuture?: boolean;
131
+ mustBeToday?: boolean;
132
+ mustNotBeToday?: boolean;
133
+ weekdaysOnly?: boolean;
134
+ weekendsOnly?: boolean;
135
+ whitelist?: string[];
136
+ whitelistOnly?: boolean;
137
+ transform?: (value: string) => string;
138
+ defaultValue?: IsRequired extends true ? string : string | null;
139
+ i18n?: Partial<Record<Locale, Partial<DateTimeMessages>>>;
140
+ };
141
+ /**
142
+ * Type alias for datetime validation schema based on required flag
143
+ *
144
+ * @template IsRequired - Whether the field is required
145
+ * @typedef DateTimeSchema
146
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
147
+ */
148
+ type DateTimeSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
149
+ /**
150
+ * Regular expression patterns for datetime format validation
151
+ *
152
+ * @constant {Record<DateTimeFormat, RegExp>} DATETIME_PATTERNS
153
+ * @description Maps each supported datetime format to its corresponding regex pattern
154
+ *
155
+ * Pattern explanations:
156
+ * - YYYY-MM-DD HH:mm: 4-digit year, 2-digit month, 2-digit day, 24-hour time
157
+ * - ISO: ISO 8601 format with optional milliseconds and timezone
158
+ * - RFC: RFC 2822 format with day name, date, time, and timezone
159
+ * - UNIX: 10-digit Unix timestamp
160
+ */
161
+ declare const DATETIME_PATTERNS: Record<DateTimeFormat, RegExp>;
162
+ /**
163
+ * Validates if a datetime string matches the specified format pattern
164
+ *
165
+ * @param {string} value - The datetime string to validate
166
+ * @param {DateTimeFormat} format - The expected datetime format
167
+ * @returns {boolean} True if the datetime is valid for the given format
168
+ *
169
+ * @description
170
+ * Performs both regex pattern matching and actual datetime parsing validation.
171
+ * Returns false if either the pattern doesn't match or the parsed datetime is invalid.
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * validateDateTimeFormat("2024-03-15 14:30", "YYYY-MM-DD HH:mm") // true
176
+ * validateDateTimeFormat("2024-03-15 25:30", "YYYY-MM-DD HH:mm") // false (invalid hour)
177
+ * validateDateTimeFormat("15/03/2024", "YYYY-MM-DD HH:mm") // false (wrong format)
178
+ * ```
179
+ */
180
+ declare const validateDateTimeFormat: (value: string, format: DateTimeFormat) => boolean;
181
+ /**
182
+ * Parses a datetime string into a dayjs object using the specified format
183
+ *
184
+ * @param {string} value - The datetime string to parse
185
+ * @param {DateTimeFormat} format - The expected datetime format
186
+ * @param {string} [timezone] - Optional timezone for parsing (e.g., "Asia/Taipei")
187
+ * @returns {dayjs.Dayjs | null} Parsed dayjs object or null if parsing fails
188
+ *
189
+ * @description
190
+ * Handles different datetime formats including ISO, RFC, Unix timestamps, and custom formats.
191
+ * Uses strict parsing mode for custom formats to ensure accuracy.
192
+ * Applies timezone conversion if specified.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * parseDateTimeValue("2024-03-15 14:30", "YYYY-MM-DD HH:mm")
197
+ * // Returns dayjs object for March 15, 2024 at 2:30 PM
198
+ *
199
+ * parseDateTimeValue("1710508245", "UNIX")
200
+ * // Returns dayjs object for the Unix timestamp
201
+ *
202
+ * parseDateTimeValue("2024-03-15T14:30:45.000Z", "ISO")
203
+ * // Returns dayjs object for the ISO datetime
204
+ * ```
205
+ *
206
+ * @throws {Error} Returns null if parsing fails or datetime is invalid
207
+ */
208
+ declare const parseDateTimeValue: (value: string, format: DateTimeFormat, timezone?: string) => dayjs.Dayjs | null;
209
+ /**
210
+ * Normalizes a datetime string to the specified format
211
+ *
212
+ * @param {string} value - The datetime string to normalize
213
+ * @param {DateTimeFormat} format - The target datetime format
214
+ * @param {string} [timezone] - Optional timezone for formatting
215
+ * @returns {string | null} Normalized datetime string or null if parsing fails
216
+ *
217
+ * @description
218
+ * Parses the input datetime and formats it according to the specified format.
219
+ * Handles special formats like ISO, RFC, and Unix timestamps appropriately.
220
+ * Returns null if the input datetime cannot be parsed.
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * normalizeDateTimeValue("2024-3-15 2:30 PM", "YYYY-MM-DD HH:mm")
225
+ * // Returns "2024-03-15 14:30"
226
+ *
227
+ * normalizeDateTimeValue("1710508245", "ISO")
228
+ * // Returns "2024-03-15T14:30:45.000Z"
229
+ * ```
230
+ */
231
+ declare const normalizeDateTimeValue: (value: string, format: DateTimeFormat, timezone?: string) => string | null;
232
+ /**
233
+ * Creates a Zod schema for datetime validation with comprehensive options
234
+ *
235
+ * @template IsRequired - Whether the field is required (affects return type)
236
+ * @param {IsRequired} [required=false] - Whether the field is required
237
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
238
+ * @returns {DateTimeSchema<IsRequired>} Zod schema for datetime validation
239
+ *
240
+ * @description
241
+ * Creates a comprehensive datetime validator that supports multiple formats, timezone handling,
242
+ * range validation, temporal constraints, and extensive customization options.
243
+ *
244
+ * Features:
245
+ * - Multiple datetime formats (ISO, RFC, Unix, regional formats)
246
+ * - Timezone support and conversion
247
+ * - Range validation (min/max datetime)
248
+ * - Hour and minute constraints
249
+ * - Temporal validation (past/future/today)
250
+ * - Weekday/weekend validation
251
+ * - Whitelist/blacklist support
252
+ * - Custom regex patterns
253
+ * - String transformation and case handling
254
+ * - Comprehensive internationalization
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // Basic datetime validation
259
+ * const basicSchema = datetime() // optional by default
260
+ * basicSchema.parse("2024-03-15 14:30") // ✓ Valid
261
+ * basicSchema.parse(null) // ✓ Valid (optional)
262
+ *
263
+ * // Required validation
264
+ * const requiredSchema = parse("2024-03-15 14:30") // ✓ Valid
265
+ (true)
266
+ * requiredSchema.parse(null) // ✗ Invalid (required)
267
+ *
268
+ *
269
+ * // Business hours validation
270
+ * const businessHours = datetime({
271
+ * format: "YYYY-MM-DD HH:mm",
272
+ * minHour: 9,
273
+ * maxHour: 17,
274
+ * weekdaysOnly: true
275
+ * })
276
+ *
277
+ * // Timezone-aware validation
278
+ * const timezoneSchema = datetime(false, {
279
+ * timezone: "Asia/Taipei",
280
+ * mustBeFuture: true
281
+ * })
282
+ *
283
+ * // Multiple format support
284
+ * const flexibleSchema = datetime(false, {
285
+ * format: "DD/MM/YYYY HH:mm"
286
+ * })
287
+ * flexibleSchema.parse("15/03/2024 14:30") // ✓ Valid
288
+ *
289
+ * // Optional with default
290
+ * const optionalSchema = datetime(false, {
291
+ * defaultValue: "2024-01-01 00:00"
292
+ * })
293
+ * ```
294
+ *
295
+ * @throws {z.ZodError} When validation fails with specific error messages
296
+ * @see {@link DateTimeOptions} for all available configuration options
297
+ * @see {@link DateTimeFormat} for supported datetime formats
298
+ */
299
+ declare function datetime<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<DateTimeOptions<IsRequired>, 'required'>): DateTimeSchema<IsRequired>;
300
+
301
+ export { DATETIME_PATTERNS, type DateTimeFormat, type DateTimeMessages, type DateTimeOptions, type DateTimeSchema, datetime, normalizeDateTimeValue, parseDateTimeValue, validateDateTimeFormat };
@@ -0,0 +1,15 @@
1
+ import {
2
+ DATETIME_PATTERNS,
3
+ datetime,
4
+ normalizeDateTimeValue,
5
+ parseDateTimeValue,
6
+ validateDateTimeFormat
7
+ } from "../chunk-ZXUMK2RR.js";
8
+ import "../chunk-6AAP4LPF.js";
9
+ export {
10
+ DATETIME_PATTERNS,
11
+ datetime,
12
+ normalizeDateTimeValue,
13
+ parseDateTimeValue,
14
+ validateDateTimeFormat
15
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkHMSM6FFAcjs = require('../chunk-HMSM6FFA.cjs');
4
+ require('../chunk-UCOXAZJF.cjs');
5
+
6
+
7
+ exports.email = _chunkHMSM6FFAcjs.email;