@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,13 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkB4EZYZOKcjs = require('../chunk-B4EZYZOK.cjs');
7
+ require('../chunk-UCOXAZJF.cjs');
8
+
9
+
10
+
11
+
12
+
13
+ exports.ID_PATTERNS = _chunkB4EZYZOKcjs.ID_PATTERNS; exports.detectIdType = _chunkB4EZYZOKcjs.detectIdType; exports.id = _chunkB4EZYZOKcjs.id; exports.validateIdType = _chunkB4EZYZOKcjs.validateIdType;
@@ -0,0 +1,288 @@
1
+ import { ZodNumber, ZodNullable, ZodString } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ /**
5
+ * @fileoverview ID validator for Zod Kit
6
+ *
7
+ * Provides comprehensive ID validation with support for multiple ID formats,
8
+ * auto-detection, custom patterns, and flexible validation options.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for ID validation error messages
16
+ *
17
+ * @interface IdMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when ID format is invalid
20
+ * @property {string} [minLength] - Message when ID is too short
21
+ * @property {string} [maxLength] - Message when ID is too long
22
+ * @property {string} [numeric] - Message when numeric ID format is invalid
23
+ * @property {string} [uuid] - Message when UUID format is invalid
24
+ * @property {string} [uuidv1] - Message when UUID v1 format is invalid
25
+ * @property {string} [uuidv2] - Message when UUID v2 format is invalid
26
+ * @property {string} [uuidv3] - Message when UUID v3 format is invalid
27
+ * @property {string} [uuidv4] - Message when UUID v4 format is invalid
28
+ * @property {string} [uuidv5] - Message when UUID v5 format is invalid
29
+ * @property {string} [uuidv6] - Message when UUID v6 format is invalid
30
+ * @property {string} [uuidv7] - Message when UUID v7 format is invalid
31
+ * @property {string} [uuidv8] - Message when UUID v8 format is invalid
32
+ * @property {string} [objectId] - Message when MongoDB ObjectId format is invalid
33
+ * @property {string} [nanoid] - Message when Nano ID format is invalid
34
+ * @property {string} [snowflake] - Message when Snowflake ID format is invalid
35
+ * @property {string} [cuid] - Message when CUID format is invalid
36
+ * @property {string} [ulid] - Message when ULID format is invalid
37
+ * @property {string} [shortid] - Message when ShortId format is invalid
38
+ * @property {string} [customFormat] - Message when custom regex format is invalid
39
+ * @property {string} [includes] - Message when ID doesn't contain required string
40
+ * @property {string} [excludes] - Message when ID contains forbidden string
41
+ * @property {string} [startsWith] - Message when ID doesn't start with required string
42
+ * @property {string} [endsWith] - Message when ID doesn't end with required string
43
+ */
44
+ type IdMessages = {
45
+ required?: string;
46
+ invalid?: string;
47
+ minLength?: string;
48
+ maxLength?: string;
49
+ numeric?: string;
50
+ uuid?: string;
51
+ uuidv1?: string;
52
+ uuidv2?: string;
53
+ uuidv3?: string;
54
+ uuidv4?: string;
55
+ uuidv5?: string;
56
+ uuidv6?: string;
57
+ uuidv7?: string;
58
+ uuidv8?: string;
59
+ objectId?: string;
60
+ nanoid?: string;
61
+ snowflake?: string;
62
+ cuid?: string;
63
+ ulid?: string;
64
+ shortid?: string;
65
+ customFormat?: string;
66
+ includes?: string;
67
+ excludes?: string;
68
+ startsWith?: string;
69
+ endsWith?: string;
70
+ };
71
+ /**
72
+ * Supported ID types for validation
73
+ *
74
+ * @typedef {string} IdType
75
+ *
76
+ * Available types:
77
+ * - numeric: Pure numeric IDs (1, 123, 999999)
78
+ * - uuid: UUID any version (v1–v8)
79
+ * - uuidv1: UUID v1 (timestamp-based)
80
+ * - uuidv2: UUID v2 (DCE security)
81
+ * - uuidv3: UUID v3 (MD5 name-based)
82
+ * - uuidv4: UUID v4 (random)
83
+ * - uuidv5: UUID v5 (SHA-1 name-based)
84
+ * - uuidv6: UUID v6 (reordered timestamp, RFC 9562)
85
+ * - uuidv7: UUID v7 (Unix timestamp, sortable, RFC 9562)
86
+ * - uuidv8: UUID v8 (custom, RFC 9562)
87
+ * - objectId: MongoDB ObjectId (24-character hexadecimal)
88
+ * - nanoid: Nano ID format (21-character URL-safe)
89
+ * - snowflake: Twitter Snowflake (19-digit number)
90
+ * - cuid: CUID format (25-character starting with 'c')
91
+ * - ulid: ULID format (26-character case-insensitive)
92
+ * - shortid: ShortId format (7-14 character URL-safe)
93
+ * - auto: Auto-detect format from the value
94
+ */
95
+ type IdType = "numeric" | "uuid" | "uuidv1" | "uuidv2" | "uuidv3" | "uuidv4" | "uuidv5" | "uuidv6" | "uuidv7" | "uuidv8" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
96
+ /**
97
+ * Configuration options for ID validation
98
+ *
99
+ * @template IsRequired - Whether the field is required (affects return type)
100
+ * @template Type - The ID type being validated
101
+ *
102
+ * @interface IdOptions
103
+ * @property {IsRequired} [required=true] - Whether the field is required
104
+ * @property {Type} [type="auto"] - Expected ID type or auto-detection
105
+ * @property {number} [minLength] - Minimum length of ID
106
+ * @property {number} [maxLength] - Maximum length of ID
107
+ * @property {IdType[]} [allowedTypes] - Multiple allowed ID types (overrides type)
108
+ * @property {RegExp} [customRegex] - Custom regex pattern (overrides type validation)
109
+ * @property {string} [includes] - String that must be included in ID
110
+ * @property {string | string[]} [excludes] - String(s) that must not be included
111
+ * @property {string} [startsWith] - String that ID must start with
112
+ * @property {string} [endsWith] - String that ID must end with
113
+ * @property {boolean} [caseSensitive=true] - Whether validation is case-sensitive
114
+ * @property {Function} [transform] - Custom transformation function for ID
115
+ * @property {any} [defaultValue] - Default value when input is empty (string for string types, number for numeric)
116
+ * @property {Record<Locale, IdMessages>} [i18n] - Custom error messages for different locales
117
+ */
118
+ type IdOptions<Type extends IdType | undefined = undefined> = {
119
+ type?: Type;
120
+ minLength?: number;
121
+ maxLength?: number;
122
+ allowedTypes?: IdType[];
123
+ customRegex?: RegExp;
124
+ includes?: string;
125
+ excludes?: string | string[];
126
+ startsWith?: string;
127
+ endsWith?: string;
128
+ caseSensitive?: boolean;
129
+ transform?: (value: string) => string;
130
+ defaultValue?: any;
131
+ i18n?: Partial<Record<Locale, Partial<IdMessages>>>;
132
+ };
133
+ /**
134
+ * Type alias for ID validation schema based on required flag and ID type
135
+ *
136
+ * @template IsRequired - Whether the field is required
137
+ * @template IdType - The ID type being validated
138
+ * @typedef IdSchema
139
+ * @description Returns appropriate Zod type based on required flag and ID type:
140
+ * - numeric type: ZodNumber or ZodNullable<ZodNumber>
141
+ * - other types: ZodString or ZodNullable<ZodString>
142
+ */
143
+ type IdSchema<IsRequired extends boolean, Type extends IdType | undefined = undefined> = Type extends "numeric" ? IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber> : IsRequired extends true ? ZodString : ZodNullable<ZodString>;
144
+ declare const ID_PATTERNS: {
145
+ readonly numeric: RegExp;
146
+ readonly uuid: RegExp;
147
+ readonly uuidv1: RegExp;
148
+ readonly uuidv2: RegExp;
149
+ readonly uuidv3: RegExp;
150
+ readonly uuidv4: RegExp;
151
+ readonly uuidv5: RegExp;
152
+ readonly uuidv6: RegExp;
153
+ readonly uuidv7: RegExp;
154
+ readonly uuidv8: RegExp;
155
+ readonly objectId: RegExp;
156
+ readonly nanoid: RegExp;
157
+ readonly snowflake: RegExp;
158
+ readonly cuid: RegExp;
159
+ readonly ulid: RegExp;
160
+ readonly shortid: RegExp;
161
+ };
162
+ /**
163
+ * Detects the ID type of a given value using pattern matching
164
+ *
165
+ * @param {string} value - The ID value to analyze
166
+ * @returns {IdType | null} The detected ID type or null if no pattern matches
167
+ *
168
+ * @description
169
+ * Attempts to identify the ID type by testing against known patterns.
170
+ * Patterns are ordered by specificity to avoid false positives.
171
+ * More specific patterns (UUID, ObjectId) are tested before generic ones (numeric, shortid).
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * detectIdType("550e8400-e29b-41d4-a716-446655440000") // "uuid"
176
+ * detectIdType("507f1f77bcf86cd799439011") // "objectId"
177
+ * detectIdType("V1StGXR8_Z5jdHi6B-myT") // "nanoid"
178
+ * detectIdType("123456789") // "numeric"
179
+ * detectIdType("invalid-id") // null
180
+ * ```
181
+ */
182
+ declare const detectIdType: (value: string) => IdType | null;
183
+ /**
184
+ * Validates if a value matches the specified ID type
185
+ *
186
+ * @param {string} value - The ID value to validate
187
+ * @param {IdType} type - The expected ID type
188
+ * @returns {boolean} True if the value matches the specified type
189
+ *
190
+ * @description
191
+ * Validates a specific ID type using regex patterns or auto-detection.
192
+ * For "auto" type, uses detectIdType to check if any known pattern matches.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * validateIdType("123456", "numeric") // true
197
+ * validateIdType("abc123", "numeric") // false
198
+ * validateIdType("550e8400-e29b-41d4-a716-446655440000", "uuid") // true
199
+ * validateIdType("invalid-uuid", "uuid") // false
200
+ * ```
201
+ */
202
+ declare const validateIdType: (value: string, type: IdType) => boolean;
203
+ /**
204
+ * Creates a Zod schema for ID validation with comprehensive format support
205
+ *
206
+ * @template IsRequired - Whether the field is required (affects return type)
207
+ * @template Type - The ID type being validated (affects return type for numeric)
208
+ * @param {IsRequired} [required=false] - Whether the field is required
209
+ * @returns {IdSchema<IsRequired, Type>} Zod schema for ID validation
210
+ *
211
+ * @description
212
+ * Creates a comprehensive ID validator with support for multiple ID formats,
213
+ * auto-detection, custom patterns, and flexible validation options.
214
+ *
215
+ * Features:
216
+ * - Multiple ID format support (UUID, ObjectId, Snowflake, etc.)
217
+ * - Auto-detection of ID types
218
+ * - Custom regex pattern support
219
+ * - Length validation
220
+ * - Content validation (includes, excludes, startsWith, endsWith)
221
+ * - Case sensitivity control
222
+ * - Multiple allowed types
223
+ * - Custom transformation functions
224
+ * - Comprehensive internationalization
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * // Auto-detect ID format
229
+ * const autoSchema = id()
230
+ * autoSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
231
+ * autoSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
232
+ * autoSchema.parse("123456") // ✓ Valid (numeric)
233
+ *
234
+ * // Specific ID type
235
+ * const uuidSchema = id(false, { type: "uuid" })
236
+ * uuidSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid
237
+ * uuidSchema.parse("invalid-uuid") // ✗ Invalid
238
+ *
239
+ * // Multiple allowed types
240
+ * const multiSchema = id(false, { allowedTypes: ["uuid", "objectId"] })
241
+ * multiSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
242
+ * multiSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
243
+ * multiSchema.parse("123456") // ✗ Invalid (numeric not allowed)
244
+ *
245
+ * // Custom regex pattern
246
+ * const customSchema = id(false, { customRegex: /^CUST_\d{6}$/ })
247
+ * customSchema.parse("CUST_123456") // ✓ Valid
248
+ * customSchema.parse("invalid") // ✗ Invalid
249
+ *
250
+ * // Content validation
251
+ * const prefixSchema = id(false, {
252
+ * type: "auto",
253
+ * startsWith: "user_",
254
+ * minLength: 10
255
+ * })
256
+ * prefixSchema.parse("user_123456") // ✓ Valid
257
+ *
258
+ * // Case insensitive
259
+ * const caseInsensitiveSchema = id(false, {
260
+ * type: "uuid",
261
+ * caseSensitive: false
262
+ * })
263
+ * caseInsensitiveSchema.parse("550E8400-E29B-41D4-A716-446655440000") // ✓ Valid
264
+ *
265
+ * // Optional with default
266
+ * const optionalSchema = id(false, {
267
+ * defaultValue: null
268
+ * })
269
+ * ```
270
+ *
271
+ * @throws {z.ZodError} When validation fails with specific error messages
272
+ * @see {@link IdOptions} for all available configuration options
273
+ * @see {@link IdType} for supported ID types
274
+ * @see {@link detectIdType} for auto-detection logic
275
+ * @see {@link validateIdType} for type-specific validation
276
+ */
277
+ declare function id<IsRequired extends boolean = false>(required?: IsRequired): IdSchema<IsRequired, undefined>;
278
+ declare function id<IsRequired extends boolean = false>(required: IsRequired, options: Omit<IdOptions<"numeric">, "required"> & {
279
+ type: "numeric";
280
+ }): IdSchema<IsRequired, "numeric">;
281
+ declare function id<IsRequired extends boolean = false, Type extends Exclude<IdType, "numeric"> = Exclude<IdType, "numeric">>(required: IsRequired, options: Omit<IdOptions<Type>, "required"> & {
282
+ type: Type;
283
+ }): IdSchema<IsRequired, Type>;
284
+ declare function id<IsRequired extends boolean = false>(required: IsRequired, options: Omit<IdOptions, "required"> & {
285
+ type?: never;
286
+ }): IdSchema<IsRequired, undefined>;
287
+
288
+ export { ID_PATTERNS, type IdMessages, type IdOptions, type IdSchema, type IdType, detectIdType, id, validateIdType };
@@ -0,0 +1,288 @@
1
+ import { ZodNumber, ZodNullable, ZodString } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ /**
5
+ * @fileoverview ID validator for Zod Kit
6
+ *
7
+ * Provides comprehensive ID validation with support for multiple ID formats,
8
+ * auto-detection, custom patterns, and flexible validation options.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for ID validation error messages
16
+ *
17
+ * @interface IdMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when ID format is invalid
20
+ * @property {string} [minLength] - Message when ID is too short
21
+ * @property {string} [maxLength] - Message when ID is too long
22
+ * @property {string} [numeric] - Message when numeric ID format is invalid
23
+ * @property {string} [uuid] - Message when UUID format is invalid
24
+ * @property {string} [uuidv1] - Message when UUID v1 format is invalid
25
+ * @property {string} [uuidv2] - Message when UUID v2 format is invalid
26
+ * @property {string} [uuidv3] - Message when UUID v3 format is invalid
27
+ * @property {string} [uuidv4] - Message when UUID v4 format is invalid
28
+ * @property {string} [uuidv5] - Message when UUID v5 format is invalid
29
+ * @property {string} [uuidv6] - Message when UUID v6 format is invalid
30
+ * @property {string} [uuidv7] - Message when UUID v7 format is invalid
31
+ * @property {string} [uuidv8] - Message when UUID v8 format is invalid
32
+ * @property {string} [objectId] - Message when MongoDB ObjectId format is invalid
33
+ * @property {string} [nanoid] - Message when Nano ID format is invalid
34
+ * @property {string} [snowflake] - Message when Snowflake ID format is invalid
35
+ * @property {string} [cuid] - Message when CUID format is invalid
36
+ * @property {string} [ulid] - Message when ULID format is invalid
37
+ * @property {string} [shortid] - Message when ShortId format is invalid
38
+ * @property {string} [customFormat] - Message when custom regex format is invalid
39
+ * @property {string} [includes] - Message when ID doesn't contain required string
40
+ * @property {string} [excludes] - Message when ID contains forbidden string
41
+ * @property {string} [startsWith] - Message when ID doesn't start with required string
42
+ * @property {string} [endsWith] - Message when ID doesn't end with required string
43
+ */
44
+ type IdMessages = {
45
+ required?: string;
46
+ invalid?: string;
47
+ minLength?: string;
48
+ maxLength?: string;
49
+ numeric?: string;
50
+ uuid?: string;
51
+ uuidv1?: string;
52
+ uuidv2?: string;
53
+ uuidv3?: string;
54
+ uuidv4?: string;
55
+ uuidv5?: string;
56
+ uuidv6?: string;
57
+ uuidv7?: string;
58
+ uuidv8?: string;
59
+ objectId?: string;
60
+ nanoid?: string;
61
+ snowflake?: string;
62
+ cuid?: string;
63
+ ulid?: string;
64
+ shortid?: string;
65
+ customFormat?: string;
66
+ includes?: string;
67
+ excludes?: string;
68
+ startsWith?: string;
69
+ endsWith?: string;
70
+ };
71
+ /**
72
+ * Supported ID types for validation
73
+ *
74
+ * @typedef {string} IdType
75
+ *
76
+ * Available types:
77
+ * - numeric: Pure numeric IDs (1, 123, 999999)
78
+ * - uuid: UUID any version (v1–v8)
79
+ * - uuidv1: UUID v1 (timestamp-based)
80
+ * - uuidv2: UUID v2 (DCE security)
81
+ * - uuidv3: UUID v3 (MD5 name-based)
82
+ * - uuidv4: UUID v4 (random)
83
+ * - uuidv5: UUID v5 (SHA-1 name-based)
84
+ * - uuidv6: UUID v6 (reordered timestamp, RFC 9562)
85
+ * - uuidv7: UUID v7 (Unix timestamp, sortable, RFC 9562)
86
+ * - uuidv8: UUID v8 (custom, RFC 9562)
87
+ * - objectId: MongoDB ObjectId (24-character hexadecimal)
88
+ * - nanoid: Nano ID format (21-character URL-safe)
89
+ * - snowflake: Twitter Snowflake (19-digit number)
90
+ * - cuid: CUID format (25-character starting with 'c')
91
+ * - ulid: ULID format (26-character case-insensitive)
92
+ * - shortid: ShortId format (7-14 character URL-safe)
93
+ * - auto: Auto-detect format from the value
94
+ */
95
+ type IdType = "numeric" | "uuid" | "uuidv1" | "uuidv2" | "uuidv3" | "uuidv4" | "uuidv5" | "uuidv6" | "uuidv7" | "uuidv8" | "objectId" | "nanoid" | "snowflake" | "cuid" | "ulid" | "shortid" | "auto";
96
+ /**
97
+ * Configuration options for ID validation
98
+ *
99
+ * @template IsRequired - Whether the field is required (affects return type)
100
+ * @template Type - The ID type being validated
101
+ *
102
+ * @interface IdOptions
103
+ * @property {IsRequired} [required=true] - Whether the field is required
104
+ * @property {Type} [type="auto"] - Expected ID type or auto-detection
105
+ * @property {number} [minLength] - Minimum length of ID
106
+ * @property {number} [maxLength] - Maximum length of ID
107
+ * @property {IdType[]} [allowedTypes] - Multiple allowed ID types (overrides type)
108
+ * @property {RegExp} [customRegex] - Custom regex pattern (overrides type validation)
109
+ * @property {string} [includes] - String that must be included in ID
110
+ * @property {string | string[]} [excludes] - String(s) that must not be included
111
+ * @property {string} [startsWith] - String that ID must start with
112
+ * @property {string} [endsWith] - String that ID must end with
113
+ * @property {boolean} [caseSensitive=true] - Whether validation is case-sensitive
114
+ * @property {Function} [transform] - Custom transformation function for ID
115
+ * @property {any} [defaultValue] - Default value when input is empty (string for string types, number for numeric)
116
+ * @property {Record<Locale, IdMessages>} [i18n] - Custom error messages for different locales
117
+ */
118
+ type IdOptions<Type extends IdType | undefined = undefined> = {
119
+ type?: Type;
120
+ minLength?: number;
121
+ maxLength?: number;
122
+ allowedTypes?: IdType[];
123
+ customRegex?: RegExp;
124
+ includes?: string;
125
+ excludes?: string | string[];
126
+ startsWith?: string;
127
+ endsWith?: string;
128
+ caseSensitive?: boolean;
129
+ transform?: (value: string) => string;
130
+ defaultValue?: any;
131
+ i18n?: Partial<Record<Locale, Partial<IdMessages>>>;
132
+ };
133
+ /**
134
+ * Type alias for ID validation schema based on required flag and ID type
135
+ *
136
+ * @template IsRequired - Whether the field is required
137
+ * @template IdType - The ID type being validated
138
+ * @typedef IdSchema
139
+ * @description Returns appropriate Zod type based on required flag and ID type:
140
+ * - numeric type: ZodNumber or ZodNullable<ZodNumber>
141
+ * - other types: ZodString or ZodNullable<ZodString>
142
+ */
143
+ type IdSchema<IsRequired extends boolean, Type extends IdType | undefined = undefined> = Type extends "numeric" ? IsRequired extends true ? ZodNumber : ZodNullable<ZodNumber> : IsRequired extends true ? ZodString : ZodNullable<ZodString>;
144
+ declare const ID_PATTERNS: {
145
+ readonly numeric: RegExp;
146
+ readonly uuid: RegExp;
147
+ readonly uuidv1: RegExp;
148
+ readonly uuidv2: RegExp;
149
+ readonly uuidv3: RegExp;
150
+ readonly uuidv4: RegExp;
151
+ readonly uuidv5: RegExp;
152
+ readonly uuidv6: RegExp;
153
+ readonly uuidv7: RegExp;
154
+ readonly uuidv8: RegExp;
155
+ readonly objectId: RegExp;
156
+ readonly nanoid: RegExp;
157
+ readonly snowflake: RegExp;
158
+ readonly cuid: RegExp;
159
+ readonly ulid: RegExp;
160
+ readonly shortid: RegExp;
161
+ };
162
+ /**
163
+ * Detects the ID type of a given value using pattern matching
164
+ *
165
+ * @param {string} value - The ID value to analyze
166
+ * @returns {IdType | null} The detected ID type or null if no pattern matches
167
+ *
168
+ * @description
169
+ * Attempts to identify the ID type by testing against known patterns.
170
+ * Patterns are ordered by specificity to avoid false positives.
171
+ * More specific patterns (UUID, ObjectId) are tested before generic ones (numeric, shortid).
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * detectIdType("550e8400-e29b-41d4-a716-446655440000") // "uuid"
176
+ * detectIdType("507f1f77bcf86cd799439011") // "objectId"
177
+ * detectIdType("V1StGXR8_Z5jdHi6B-myT") // "nanoid"
178
+ * detectIdType("123456789") // "numeric"
179
+ * detectIdType("invalid-id") // null
180
+ * ```
181
+ */
182
+ declare const detectIdType: (value: string) => IdType | null;
183
+ /**
184
+ * Validates if a value matches the specified ID type
185
+ *
186
+ * @param {string} value - The ID value to validate
187
+ * @param {IdType} type - The expected ID type
188
+ * @returns {boolean} True if the value matches the specified type
189
+ *
190
+ * @description
191
+ * Validates a specific ID type using regex patterns or auto-detection.
192
+ * For "auto" type, uses detectIdType to check if any known pattern matches.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * validateIdType("123456", "numeric") // true
197
+ * validateIdType("abc123", "numeric") // false
198
+ * validateIdType("550e8400-e29b-41d4-a716-446655440000", "uuid") // true
199
+ * validateIdType("invalid-uuid", "uuid") // false
200
+ * ```
201
+ */
202
+ declare const validateIdType: (value: string, type: IdType) => boolean;
203
+ /**
204
+ * Creates a Zod schema for ID validation with comprehensive format support
205
+ *
206
+ * @template IsRequired - Whether the field is required (affects return type)
207
+ * @template Type - The ID type being validated (affects return type for numeric)
208
+ * @param {IsRequired} [required=false] - Whether the field is required
209
+ * @returns {IdSchema<IsRequired, Type>} Zod schema for ID validation
210
+ *
211
+ * @description
212
+ * Creates a comprehensive ID validator with support for multiple ID formats,
213
+ * auto-detection, custom patterns, and flexible validation options.
214
+ *
215
+ * Features:
216
+ * - Multiple ID format support (UUID, ObjectId, Snowflake, etc.)
217
+ * - Auto-detection of ID types
218
+ * - Custom regex pattern support
219
+ * - Length validation
220
+ * - Content validation (includes, excludes, startsWith, endsWith)
221
+ * - Case sensitivity control
222
+ * - Multiple allowed types
223
+ * - Custom transformation functions
224
+ * - Comprehensive internationalization
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * // Auto-detect ID format
229
+ * const autoSchema = id()
230
+ * autoSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
231
+ * autoSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
232
+ * autoSchema.parse("123456") // ✓ Valid (numeric)
233
+ *
234
+ * // Specific ID type
235
+ * const uuidSchema = id(false, { type: "uuid" })
236
+ * uuidSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid
237
+ * uuidSchema.parse("invalid-uuid") // ✗ Invalid
238
+ *
239
+ * // Multiple allowed types
240
+ * const multiSchema = id(false, { allowedTypes: ["uuid", "objectId"] })
241
+ * multiSchema.parse("550e8400-e29b-41d4-a716-446655440000") // ✓ Valid (UUID)
242
+ * multiSchema.parse("507f1f77bcf86cd799439011") // ✓ Valid (ObjectId)
243
+ * multiSchema.parse("123456") // ✗ Invalid (numeric not allowed)
244
+ *
245
+ * // Custom regex pattern
246
+ * const customSchema = id(false, { customRegex: /^CUST_\d{6}$/ })
247
+ * customSchema.parse("CUST_123456") // ✓ Valid
248
+ * customSchema.parse("invalid") // ✗ Invalid
249
+ *
250
+ * // Content validation
251
+ * const prefixSchema = id(false, {
252
+ * type: "auto",
253
+ * startsWith: "user_",
254
+ * minLength: 10
255
+ * })
256
+ * prefixSchema.parse("user_123456") // ✓ Valid
257
+ *
258
+ * // Case insensitive
259
+ * const caseInsensitiveSchema = id(false, {
260
+ * type: "uuid",
261
+ * caseSensitive: false
262
+ * })
263
+ * caseInsensitiveSchema.parse("550E8400-E29B-41D4-A716-446655440000") // ✓ Valid
264
+ *
265
+ * // Optional with default
266
+ * const optionalSchema = id(false, {
267
+ * defaultValue: null
268
+ * })
269
+ * ```
270
+ *
271
+ * @throws {z.ZodError} When validation fails with specific error messages
272
+ * @see {@link IdOptions} for all available configuration options
273
+ * @see {@link IdType} for supported ID types
274
+ * @see {@link detectIdType} for auto-detection logic
275
+ * @see {@link validateIdType} for type-specific validation
276
+ */
277
+ declare function id<IsRequired extends boolean = false>(required?: IsRequired): IdSchema<IsRequired, undefined>;
278
+ declare function id<IsRequired extends boolean = false>(required: IsRequired, options: Omit<IdOptions<"numeric">, "required"> & {
279
+ type: "numeric";
280
+ }): IdSchema<IsRequired, "numeric">;
281
+ declare function id<IsRequired extends boolean = false, Type extends Exclude<IdType, "numeric"> = Exclude<IdType, "numeric">>(required: IsRequired, options: Omit<IdOptions<Type>, "required"> & {
282
+ type: Type;
283
+ }): IdSchema<IsRequired, Type>;
284
+ declare function id<IsRequired extends boolean = false>(required: IsRequired, options: Omit<IdOptions, "required"> & {
285
+ type?: never;
286
+ }): IdSchema<IsRequired, undefined>;
287
+
288
+ export { ID_PATTERNS, type IdMessages, type IdOptions, type IdSchema, type IdType, detectIdType, id, validateIdType };
@@ -0,0 +1,13 @@
1
+ import {
2
+ ID_PATTERNS,
3
+ detectIdType,
4
+ id,
5
+ validateIdType
6
+ } from "../chunk-MHJFYYGV.js";
7
+ import "../chunk-6AAP4LPF.js";
8
+ export {
9
+ ID_PATTERNS,
10
+ detectIdType,
11
+ id,
12
+ validateIdType
13
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunk32JI34CVcjs = require('../chunk-32JI34CV.cjs');
6
+ require('../chunk-UCOXAZJF.cjs');
7
+
8
+
9
+
10
+
11
+ exports.ip = _chunk32JI34CVcjs.ip; exports.validateIPv4 = _chunk32JI34CVcjs.validateIPv4; exports.validateIPv6 = _chunk32JI34CVcjs.validateIPv6;
@@ -0,0 +1,25 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ type IpVersion = "v4" | "v6" | "any";
5
+ type IpMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ notIPv4?: string;
9
+ notIPv6?: string;
10
+ notInWhitelist?: string;
11
+ };
12
+ type IpOptions<IsRequired extends boolean = true> = {
13
+ version?: IpVersion;
14
+ allowCIDR?: boolean;
15
+ whitelist?: string[];
16
+ transform?: (value: string) => string;
17
+ defaultValue?: IsRequired extends true ? string : string | null;
18
+ i18n?: Partial<Record<Locale, Partial<IpMessages>>>;
19
+ };
20
+ type IpSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
21
+ declare function validateIPv4(value: string): boolean;
22
+ declare function validateIPv6(value: string): boolean;
23
+ declare function ip<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<IpOptions<IsRequired>, "required">): IpSchema<IsRequired>;
24
+
25
+ export { type IpMessages, type IpOptions, type IpSchema, type IpVersion, ip, validateIPv4, validateIPv6 };
@@ -0,0 +1,25 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ type IpVersion = "v4" | "v6" | "any";
5
+ type IpMessages = {
6
+ required?: string;
7
+ invalid?: string;
8
+ notIPv4?: string;
9
+ notIPv6?: string;
10
+ notInWhitelist?: string;
11
+ };
12
+ type IpOptions<IsRequired extends boolean = true> = {
13
+ version?: IpVersion;
14
+ allowCIDR?: boolean;
15
+ whitelist?: string[];
16
+ transform?: (value: string) => string;
17
+ defaultValue?: IsRequired extends true ? string : string | null;
18
+ i18n?: Partial<Record<Locale, Partial<IpMessages>>>;
19
+ };
20
+ type IpSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
21
+ declare function validateIPv4(value: string): boolean;
22
+ declare function validateIPv6(value: string): boolean;
23
+ declare function ip<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<IpOptions<IsRequired>, "required">): IpSchema<IsRequired>;
24
+
25
+ export { type IpMessages, type IpOptions, type IpSchema, type IpVersion, ip, validateIPv4, validateIPv6 };
@@ -0,0 +1,11 @@
1
+ import {
2
+ ip,
3
+ validateIPv4,
4
+ validateIPv6
5
+ } from "../chunk-RO47DKQG.js";
6
+ import "../chunk-6AAP4LPF.js";
7
+ export {
8
+ ip,
9
+ validateIPv4,
10
+ validateIPv6
11
+ };