@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,196 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.cjs';
3
+
4
+ /**
5
+ * @fileoverview URL validator for Zod Kit
6
+ *
7
+ * Provides comprehensive URL validation with protocol filtering, domain control,
8
+ * port validation, path constraints, and localhost handling.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for URL validation error messages
16
+ *
17
+ * @interface UrlMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when URL format is invalid
20
+ * @property {string} [min] - Message when URL is too short
21
+ * @property {string} [max] - Message when URL is too long
22
+ * @property {string} [includes] - Message when URL doesn't contain required string
23
+ * @property {string} [excludes] - Message when URL contains forbidden string
24
+ * @property {string} [protocol] - Message when protocol is not allowed
25
+ * @property {string} [domain] - Message when domain is not allowed
26
+ * @property {string} [domainBlacklist] - Message when domain is blacklisted
27
+ * @property {string} [port] - Message when port is not allowed
28
+ * @property {string} [pathStartsWith] - Message when path doesn't start with required string
29
+ * @property {string} [pathEndsWith] - Message when path doesn't end with required string
30
+ * @property {string} [hasQuery] - Message when query parameters are required
31
+ * @property {string} [noQuery] - Message when query parameters are forbidden
32
+ * @property {string} [hasFragment] - Message when fragment is required
33
+ * @property {string} [noFragment] - Message when fragment is forbidden
34
+ * @property {string} [localhost] - Message when localhost is forbidden
35
+ * @property {string} [noLocalhost] - Message when localhost is required
36
+ */
37
+ type UrlMessages = {
38
+ required?: string;
39
+ invalid?: string;
40
+ min?: string;
41
+ max?: string;
42
+ includes?: string;
43
+ excludes?: string;
44
+ protocol?: string;
45
+ domain?: string;
46
+ domainBlacklist?: string;
47
+ port?: string;
48
+ pathStartsWith?: string;
49
+ pathEndsWith?: string;
50
+ hasQuery?: string;
51
+ noQuery?: string;
52
+ hasFragment?: string;
53
+ noFragment?: string;
54
+ localhost?: string;
55
+ noLocalhost?: string;
56
+ };
57
+ /**
58
+ * Configuration options for URL validation
59
+ *
60
+ * @template IsRequired - Whether the field is required (affects return type)
61
+ *
62
+ * @interface UrlOptions
63
+ * @property {IsRequired} [required=true] - Whether the field is required
64
+ * @property {number} [min] - Minimum length of URL
65
+ * @property {number} [max] - Maximum length of URL
66
+ * @property {string} [includes] - String that must be included in URL
67
+ * @property {string | string[]} [excludes] - String(s) that must not be included
68
+ * @property {string[]} [protocols] - Allowed protocols (e.g., ["https", "http"])
69
+ * @property {string[]} [allowedDomains] - Domains that are allowed
70
+ * @property {string[]} [blockedDomains] - Domains that are blocked
71
+ * @property {number[]} [allowedPorts] - Ports that are allowed
72
+ * @property {number[]} [blockedPorts] - Ports that are blocked
73
+ * @property {string} [pathStartsWith] - Path must start with this string
74
+ * @property {string} [pathEndsWith] - Path must end with this string
75
+ * @property {boolean} [mustHaveQuery] - Whether URL must have query parameters
76
+ * @property {boolean} [mustNotHaveQuery] - Whether URL must not have query parameters
77
+ * @property {boolean} [mustHaveFragment] - Whether URL must have fragment
78
+ * @property {boolean} [mustNotHaveFragment] - Whether URL must not have fragment
79
+ * @property {boolean} [allowLocalhost=true] - Whether to allow localhost URLs
80
+ * @property {boolean} [blockLocalhost] - Whether to explicitly block localhost URLs
81
+ * @property {Function} [transform] - Custom transformation function for URL strings
82
+ * @property {string | null} [defaultValue] - Default value when input is empty
83
+ * @property {Record<Locale, UrlMessages>} [i18n] - Custom error messages for different locales
84
+ */
85
+ type UrlOptions<IsRequired extends boolean = true> = {
86
+ min?: number;
87
+ max?: number;
88
+ includes?: string;
89
+ excludes?: string | string[];
90
+ protocols?: string[];
91
+ allowedDomains?: string[];
92
+ blockedDomains?: string[];
93
+ allowedPorts?: number[];
94
+ blockedPorts?: number[];
95
+ pathStartsWith?: string;
96
+ pathEndsWith?: string;
97
+ mustHaveQuery?: boolean;
98
+ mustNotHaveQuery?: boolean;
99
+ mustHaveFragment?: boolean;
100
+ mustNotHaveFragment?: boolean;
101
+ allowLocalhost?: boolean;
102
+ blockLocalhost?: boolean;
103
+ transform?: (value: string) => string;
104
+ defaultValue?: IsRequired extends true ? string : string | null;
105
+ i18n?: Partial<Record<Locale, Partial<UrlMessages>>>;
106
+ };
107
+ /**
108
+ * Type alias for URL validation schema based on required flag
109
+ *
110
+ * @template IsRequired - Whether the field is required
111
+ * @typedef UrlSchema
112
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
113
+ */
114
+ type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
115
+ /**
116
+ * Creates a Zod schema for URL validation with comprehensive constraints
117
+ *
118
+ * @template IsRequired - Whether the field is required (affects return type)
119
+ * @param {IsRequired} [required=false] - Whether the field is required
120
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
121
+ * @returns {UrlSchema<IsRequired>} Zod schema for URL validation
122
+ *
123
+ * @description
124
+ * Creates a comprehensive URL validator with protocol filtering, domain control,
125
+ * port validation, path constraints, and localhost handling.
126
+ *
127
+ * Features:
128
+ * - RFC-compliant URL format validation
129
+ * - Protocol whitelist/blacklist (http, https, ftp, etc.)
130
+ * - Domain whitelist/blacklist with subdomain support
131
+ * - Port validation and filtering
132
+ * - Path prefix/suffix validation
133
+ * - Query parameter requirements
134
+ * - Fragment requirements
135
+ * - Localhost detection and control
136
+ * - Length validation
137
+ * - Content inclusion/exclusion
138
+ * - Custom transformation functions
139
+ * - Comprehensive internationalization
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // Basic URL validation
144
+ * const basicSchema = url() // optional by default
145
+ * basicSchema.parse("https://example.com") // ✓ Valid
146
+ * basicSchema.parse(null) // ✓ Valid (optional)
147
+ *
148
+ * // Required validation
149
+ * const requiredSchema = parse("https://example.com") // ✓ Valid
150
+ (true)
151
+ * requiredSchema.parse(null) // ✗ Invalid (required)
152
+ *
153
+ *
154
+ * // HTTPS only
155
+ * const httpsSchema = url(false, { protocols: ["https"] })
156
+ * httpsSchema.parse("https://example.com") // ✓ Valid
157
+ * httpsSchema.parse("http://example.com") // ✗ Invalid
158
+ *
159
+ * // Domain restriction
160
+ * const domainSchema = url(false, {
161
+ * allowedDomains: ["company.com", "trusted.org"]
162
+ * })
163
+ * domainSchema.parse("https://app.company.com") // ✓ Valid (subdomain)
164
+ * domainSchema.parse("https://example.com") // ✗ Invalid
165
+ *
166
+ * // Block localhost
167
+ * const noLocalhostSchema = url(false, { blockLocalhost: true })
168
+ * noLocalhostSchema.parse("https://example.com") // ✓ Valid
169
+ * noLocalhostSchema.parse("http://localhost:3000") // ✗ Invalid
170
+ *
171
+ * // API endpoints with path requirements
172
+ * const apiSchema = url(false, {
173
+ * pathStartsWith: "/api/",
174
+ * mustHaveQuery: true
175
+ * })
176
+ * apiSchema.parse("https://api.com/api/users?page=1") // ✓ Valid
177
+ *
178
+ * // Port restrictions
179
+ * const portSchema = url(false, {
180
+ * allowedPorts: [80, 443, 8080]
181
+ * })
182
+ * portSchema.parse("https://example.com:443") // ✓ Valid
183
+ * portSchema.parse("https://example.com:3000") // ✗ Invalid
184
+ *
185
+ * // Optional with default
186
+ * const optionalSchema = url(false, {
187
+ * defaultValue: null
188
+ * })
189
+ * ```
190
+ *
191
+ * @throws {z.ZodError} When validation fails with specific error messages
192
+ * @see {@link UrlOptions} for all available configuration options
193
+ */
194
+ declare function url<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<UrlOptions<IsRequired>, 'required'>): UrlSchema<IsRequired>;
195
+
196
+ export { type UrlMessages, type UrlOptions, type UrlSchema, url };
@@ -0,0 +1,196 @@
1
+ import { ZodString, ZodNullable } from 'zod';
2
+ import { L as Locale } from '../config-CABSSvAp.js';
3
+
4
+ /**
5
+ * @fileoverview URL validator for Zod Kit
6
+ *
7
+ * Provides comprehensive URL validation with protocol filtering, domain control,
8
+ * port validation, path constraints, and localhost handling.
9
+ *
10
+ * @author Ong Hoe Yuan
11
+ * @version 0.0.5
12
+ */
13
+
14
+ /**
15
+ * Type definition for URL validation error messages
16
+ *
17
+ * @interface UrlMessages
18
+ * @property {string} [required] - Message when field is required but empty
19
+ * @property {string} [invalid] - Message when URL format is invalid
20
+ * @property {string} [min] - Message when URL is too short
21
+ * @property {string} [max] - Message when URL is too long
22
+ * @property {string} [includes] - Message when URL doesn't contain required string
23
+ * @property {string} [excludes] - Message when URL contains forbidden string
24
+ * @property {string} [protocol] - Message when protocol is not allowed
25
+ * @property {string} [domain] - Message when domain is not allowed
26
+ * @property {string} [domainBlacklist] - Message when domain is blacklisted
27
+ * @property {string} [port] - Message when port is not allowed
28
+ * @property {string} [pathStartsWith] - Message when path doesn't start with required string
29
+ * @property {string} [pathEndsWith] - Message when path doesn't end with required string
30
+ * @property {string} [hasQuery] - Message when query parameters are required
31
+ * @property {string} [noQuery] - Message when query parameters are forbidden
32
+ * @property {string} [hasFragment] - Message when fragment is required
33
+ * @property {string} [noFragment] - Message when fragment is forbidden
34
+ * @property {string} [localhost] - Message when localhost is forbidden
35
+ * @property {string} [noLocalhost] - Message when localhost is required
36
+ */
37
+ type UrlMessages = {
38
+ required?: string;
39
+ invalid?: string;
40
+ min?: string;
41
+ max?: string;
42
+ includes?: string;
43
+ excludes?: string;
44
+ protocol?: string;
45
+ domain?: string;
46
+ domainBlacklist?: string;
47
+ port?: string;
48
+ pathStartsWith?: string;
49
+ pathEndsWith?: string;
50
+ hasQuery?: string;
51
+ noQuery?: string;
52
+ hasFragment?: string;
53
+ noFragment?: string;
54
+ localhost?: string;
55
+ noLocalhost?: string;
56
+ };
57
+ /**
58
+ * Configuration options for URL validation
59
+ *
60
+ * @template IsRequired - Whether the field is required (affects return type)
61
+ *
62
+ * @interface UrlOptions
63
+ * @property {IsRequired} [required=true] - Whether the field is required
64
+ * @property {number} [min] - Minimum length of URL
65
+ * @property {number} [max] - Maximum length of URL
66
+ * @property {string} [includes] - String that must be included in URL
67
+ * @property {string | string[]} [excludes] - String(s) that must not be included
68
+ * @property {string[]} [protocols] - Allowed protocols (e.g., ["https", "http"])
69
+ * @property {string[]} [allowedDomains] - Domains that are allowed
70
+ * @property {string[]} [blockedDomains] - Domains that are blocked
71
+ * @property {number[]} [allowedPorts] - Ports that are allowed
72
+ * @property {number[]} [blockedPorts] - Ports that are blocked
73
+ * @property {string} [pathStartsWith] - Path must start with this string
74
+ * @property {string} [pathEndsWith] - Path must end with this string
75
+ * @property {boolean} [mustHaveQuery] - Whether URL must have query parameters
76
+ * @property {boolean} [mustNotHaveQuery] - Whether URL must not have query parameters
77
+ * @property {boolean} [mustHaveFragment] - Whether URL must have fragment
78
+ * @property {boolean} [mustNotHaveFragment] - Whether URL must not have fragment
79
+ * @property {boolean} [allowLocalhost=true] - Whether to allow localhost URLs
80
+ * @property {boolean} [blockLocalhost] - Whether to explicitly block localhost URLs
81
+ * @property {Function} [transform] - Custom transformation function for URL strings
82
+ * @property {string | null} [defaultValue] - Default value when input is empty
83
+ * @property {Record<Locale, UrlMessages>} [i18n] - Custom error messages for different locales
84
+ */
85
+ type UrlOptions<IsRequired extends boolean = true> = {
86
+ min?: number;
87
+ max?: number;
88
+ includes?: string;
89
+ excludes?: string | string[];
90
+ protocols?: string[];
91
+ allowedDomains?: string[];
92
+ blockedDomains?: string[];
93
+ allowedPorts?: number[];
94
+ blockedPorts?: number[];
95
+ pathStartsWith?: string;
96
+ pathEndsWith?: string;
97
+ mustHaveQuery?: boolean;
98
+ mustNotHaveQuery?: boolean;
99
+ mustHaveFragment?: boolean;
100
+ mustNotHaveFragment?: boolean;
101
+ allowLocalhost?: boolean;
102
+ blockLocalhost?: boolean;
103
+ transform?: (value: string) => string;
104
+ defaultValue?: IsRequired extends true ? string : string | null;
105
+ i18n?: Partial<Record<Locale, Partial<UrlMessages>>>;
106
+ };
107
+ /**
108
+ * Type alias for URL validation schema based on required flag
109
+ *
110
+ * @template IsRequired - Whether the field is required
111
+ * @typedef UrlSchema
112
+ * @description Returns ZodString if required, ZodNullable<ZodString> if optional
113
+ */
114
+ type UrlSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
115
+ /**
116
+ * Creates a Zod schema for URL validation with comprehensive constraints
117
+ *
118
+ * @template IsRequired - Whether the field is required (affects return type)
119
+ * @param {IsRequired} [required=false] - Whether the field is required
120
+ * @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
121
+ * @returns {UrlSchema<IsRequired>} Zod schema for URL validation
122
+ *
123
+ * @description
124
+ * Creates a comprehensive URL validator with protocol filtering, domain control,
125
+ * port validation, path constraints, and localhost handling.
126
+ *
127
+ * Features:
128
+ * - RFC-compliant URL format validation
129
+ * - Protocol whitelist/blacklist (http, https, ftp, etc.)
130
+ * - Domain whitelist/blacklist with subdomain support
131
+ * - Port validation and filtering
132
+ * - Path prefix/suffix validation
133
+ * - Query parameter requirements
134
+ * - Fragment requirements
135
+ * - Localhost detection and control
136
+ * - Length validation
137
+ * - Content inclusion/exclusion
138
+ * - Custom transformation functions
139
+ * - Comprehensive internationalization
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * // Basic URL validation
144
+ * const basicSchema = url() // optional by default
145
+ * basicSchema.parse("https://example.com") // ✓ Valid
146
+ * basicSchema.parse(null) // ✓ Valid (optional)
147
+ *
148
+ * // Required validation
149
+ * const requiredSchema = parse("https://example.com") // ✓ Valid
150
+ (true)
151
+ * requiredSchema.parse(null) // ✗ Invalid (required)
152
+ *
153
+ *
154
+ * // HTTPS only
155
+ * const httpsSchema = url(false, { protocols: ["https"] })
156
+ * httpsSchema.parse("https://example.com") // ✓ Valid
157
+ * httpsSchema.parse("http://example.com") // ✗ Invalid
158
+ *
159
+ * // Domain restriction
160
+ * const domainSchema = url(false, {
161
+ * allowedDomains: ["company.com", "trusted.org"]
162
+ * })
163
+ * domainSchema.parse("https://app.company.com") // ✓ Valid (subdomain)
164
+ * domainSchema.parse("https://example.com") // ✗ Invalid
165
+ *
166
+ * // Block localhost
167
+ * const noLocalhostSchema = url(false, { blockLocalhost: true })
168
+ * noLocalhostSchema.parse("https://example.com") // ✓ Valid
169
+ * noLocalhostSchema.parse("http://localhost:3000") // ✗ Invalid
170
+ *
171
+ * // API endpoints with path requirements
172
+ * const apiSchema = url(false, {
173
+ * pathStartsWith: "/api/",
174
+ * mustHaveQuery: true
175
+ * })
176
+ * apiSchema.parse("https://api.com/api/users?page=1") // ✓ Valid
177
+ *
178
+ * // Port restrictions
179
+ * const portSchema = url(false, {
180
+ * allowedPorts: [80, 443, 8080]
181
+ * })
182
+ * portSchema.parse("https://example.com:443") // ✓ Valid
183
+ * portSchema.parse("https://example.com:3000") // ✗ Invalid
184
+ *
185
+ * // Optional with default
186
+ * const optionalSchema = url(false, {
187
+ * defaultValue: null
188
+ * })
189
+ * ```
190
+ *
191
+ * @throws {z.ZodError} When validation fails with specific error messages
192
+ * @see {@link UrlOptions} for all available configuration options
193
+ */
194
+ declare function url<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<UrlOptions<IsRequired>, 'required'>): UrlSchema<IsRequired>;
195
+
196
+ export { type UrlMessages, type UrlOptions, type UrlSchema, url };
@@ -0,0 +1,7 @@
1
+ import {
2
+ url
3
+ } from "../chunk-WABKPFPK.js";
4
+ import "../chunk-6AAP4LPF.js";
5
+ export {
6
+ url
7
+ };
@@ -0,0 +1,5 @@
1
+ type Locale = "zh-TW" | "zh-CN" | "en-US" | "en-GB" | "ja-JP" | "ko-KR" | "ms-MY" | "id-ID" | "th-TH" | "vi-VN";
2
+ declare const setLocale: (locale: Locale) => void;
3
+ declare const getLocale: () => Locale;
4
+
5
+ export { type Locale as L, getLocale as g, setLocale as s };
@@ -0,0 +1,5 @@
1
+ type Locale = "zh-TW" | "zh-CN" | "en-US" | "en-GB" | "ja-JP" | "ko-KR" | "ms-MY" | "id-ID" | "th-TH" | "vi-VN";
2
+ declare const setLocale: (locale: Locale) => void;
3
+ declare const getLocale: () => Locale;
4
+
5
+ export { type Locale as L, getLocale as g, setLocale as s };