@validex/core 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +583 -0
- package/dist/checks/index.cjs +51 -0
- package/dist/checks/index.d.cts +207 -0
- package/dist/checks/index.d.ts +207 -0
- package/dist/checks/index.js +51 -0
- package/dist/chunk-2OTGUKO7.cjs +26 -0
- package/dist/chunk-4HUGF4EZ.js +0 -0
- package/dist/chunk-5CYBSNNG.cjs +33 -0
- package/dist/chunk-5DOFRLSB.js +30 -0
- package/dist/chunk-64X6D23X.cjs +24 -0
- package/dist/chunk-6MGS4JWP.js +152 -0
- package/dist/chunk-AGJWIOFF.js +24 -0
- package/dist/chunk-BAFEYOPS.js +43 -0
- package/dist/chunk-BYMZTDYD.js +56 -0
- package/dist/chunk-D232V332.cjs +30 -0
- package/dist/chunk-FD77PZXB.js +9 -0
- package/dist/chunk-H3XHQLZF.cjs +43 -0
- package/dist/chunk-ISY3F7TI.cjs +239 -0
- package/dist/chunk-JEKRBIPN.cjs +1 -0
- package/dist/chunk-KTN4NQQL.js +33 -0
- package/dist/chunk-LSQNDPFQ.cjs +9 -0
- package/dist/chunk-NDLUDRZJ.js +24 -0
- package/dist/chunk-OCTLUBGT.cjs +24 -0
- package/dist/chunk-OFT3FQPJ.cjs +152 -0
- package/dist/chunk-OOFMB7K5.js +34 -0
- package/dist/chunk-OTPQTLPM.js +50 -0
- package/dist/chunk-P3FRVJ3U.cjs +50 -0
- package/dist/chunk-PFPNNQGJ.js +30 -0
- package/dist/chunk-PQ4TUE2Q.cjs +2688 -0
- package/dist/chunk-SMDC2EAD.js +26 -0
- package/dist/chunk-TB6J73U7.js +239 -0
- package/dist/chunk-TBVAKZA5.js +2688 -0
- package/dist/chunk-TSPTIW3V.cjs +34 -0
- package/dist/chunk-WE2OD5XD.cjs +30 -0
- package/dist/chunk-WKVMDEA3.js +26 -0
- package/dist/chunk-ZAUX2RGL.cjs +56 -0
- package/dist/chunk-ZWIO2MJX.cjs +26 -0
- package/dist/cli/index.cjs +120 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +120 -0
- package/dist/commonPasswords-3BYUBARZ.cjs +10 -0
- package/dist/commonPasswords-ZYOEI6PG.js +10 -0
- package/dist/countryCodes-EKJKVHR5.cjs +10 -0
- package/dist/countryCodes-RTJZVCLB.js +10 -0
- package/dist/countryCodes-VY56VZPT.cjs +255 -0
- package/dist/countryCodes-YRY75MQP.js +255 -0
- package/dist/creditCardPrefixes-EXMJZGE7.cjs +10 -0
- package/dist/creditCardPrefixes-EZK7T4IZ.js +10 -0
- package/dist/creditCardPrefixes-HKWKCHNU.cjs +48 -0
- package/dist/creditCardPrefixes-QP3S4ZAU.js +48 -0
- package/dist/currencyCodes-GU6W3HSN.cjs +171 -0
- package/dist/currencyCodes-P67AASLW.js +171 -0
- package/dist/currencyCodes-RMRLGDME.cjs +10 -0
- package/dist/currencyCodes-U6TSAWDR.js +10 -0
- package/dist/disposableDomains-DCXSV422.js +10 -0
- package/dist/disposableDomains-USU2JQSF.cjs +10 -0
- package/dist/ibanPatterns-2PM32RIY.cjs +85 -0
- package/dist/ibanPatterns-BSQUWKLY.js +85 -0
- package/dist/ibanPatterns-KTLY6TZY.cjs +10 -0
- package/dist/ibanPatterns-LJRPR7FV.js +10 -0
- package/dist/index-Cid7Ygr_.d.cts +950 -0
- package/dist/index-Cid7Ygr_.d.ts +950 -0
- package/dist/index.cjs +361 -0
- package/dist/index.d.cts +132 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +361 -0
- package/dist/locales/en.cjs +10 -0
- package/dist/locales/en.d.cts +234 -0
- package/dist/locales/en.d.ts +234 -0
- package/dist/locales/en.js +10 -0
- package/dist/passwordsTier1-NAZLSHKW.cjs +105 -0
- package/dist/passwordsTier1-OYRMLOWD.js +105 -0
- package/dist/passwordsTier2-GYJTYGY6.cjs +906 -0
- package/dist/passwordsTier2-JAEO5AYY.js +906 -0
- package/dist/passwordsTier3-BAPUFHZM.cjs +9006 -0
- package/dist/passwordsTier3-E6WBK5OB.js +9006 -0
- package/dist/phoneDetection-AFSSD4IB.cjs +6 -0
- package/dist/phoneDetection-G23LZ6MU.js +6 -0
- package/dist/phoneParser-2RTXDB6H.js +10 -0
- package/dist/phoneParser-CGRP2OUN.cjs +10 -0
- package/dist/postalCodes-4EZVDT2N.cjs +10 -0
- package/dist/postalCodes-ZPAJB3P5.js +10 -0
- package/dist/reservedUsernames-3QPPKUXR.cjs +246 -0
- package/dist/reservedUsernames-GIK6NX3J.js +246 -0
- package/dist/reservedUsernames-QR4ONXSL.js +10 -0
- package/dist/reservedUsernames-W65FGT6A.cjs +10 -0
- package/dist/rules/index.cjs +66 -0
- package/dist/rules/index.d.cts +2 -0
- package/dist/rules/index.d.ts +2 -0
- package/dist/rules/index.js +66 -0
- package/dist/utilities/index.cjs +8 -0
- package/dist/utilities/index.d.cts +47 -0
- package/dist/utilities/index.d.ts +47 -0
- package/dist/utilities/index.js +8 -0
- package/dist/vatPatterns-BLRXHNCP.js +36 -0
- package/dist/vatPatterns-DNVZJPTW.js +10 -0
- package/dist/vatPatterns-NPN6SV2Y.cjs +36 -0
- package/dist/vatPatterns-RRHUTA3U.cjs +10 -0
- package/package.json +133 -0
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
import { ZodPipe, ZodTransform } from 'zod';
|
|
2
|
+
|
|
3
|
+
/** Options for composition methods (hasUppercase, hasLowercase, hasDigits, hasSpecial). */
|
|
4
|
+
interface CompositionMethodOptions {
|
|
5
|
+
readonly min?: number | undefined;
|
|
6
|
+
readonly max?: number | undefined;
|
|
7
|
+
readonly label?: string | undefined;
|
|
8
|
+
readonly namespace?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Options for simple boolean check methods. */
|
|
11
|
+
interface CheckMethodOptions {
|
|
12
|
+
readonly label?: string | undefined;
|
|
13
|
+
readonly namespace?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** Options for the maxWords chainable method. */
|
|
16
|
+
interface MaxWordsOptions extends CheckMethodOptions {
|
|
17
|
+
readonly max: number;
|
|
18
|
+
}
|
|
19
|
+
/** Options for the minWords chainable method. */
|
|
20
|
+
interface MinWordsOptions extends CheckMethodOptions {
|
|
21
|
+
readonly min: number;
|
|
22
|
+
}
|
|
23
|
+
/** Options for the maxConsecutive chainable method. */
|
|
24
|
+
interface MaxConsecutiveOptions extends CheckMethodOptions {
|
|
25
|
+
readonly max: number;
|
|
26
|
+
}
|
|
27
|
+
declare module 'zod' {
|
|
28
|
+
/** Chainable validation and transform methods added by validex. */
|
|
29
|
+
interface ZodType {
|
|
30
|
+
hasUppercase: (opts?: CompositionMethodOptions) => this;
|
|
31
|
+
hasLowercase: (opts?: CompositionMethodOptions) => this;
|
|
32
|
+
hasDigits: (opts?: CompositionMethodOptions) => this;
|
|
33
|
+
hasSpecial: (opts?: CompositionMethodOptions) => this;
|
|
34
|
+
noEmails: (opts?: CheckMethodOptions) => this;
|
|
35
|
+
noUrls: (opts?: CheckMethodOptions) => this;
|
|
36
|
+
noHtml: (opts?: CheckMethodOptions) => this;
|
|
37
|
+
noPhoneNumbers: (opts?: CheckMethodOptions) => this;
|
|
38
|
+
noSpaces: (opts?: CheckMethodOptions) => this;
|
|
39
|
+
onlyAlpha: (opts?: CheckMethodOptions) => this;
|
|
40
|
+
onlyNumeric: (opts?: CheckMethodOptions) => this;
|
|
41
|
+
onlyAlphanumeric: (opts?: CheckMethodOptions) => this;
|
|
42
|
+
onlyAlphaSpaceHyphen: (opts?: CheckMethodOptions) => this;
|
|
43
|
+
onlyAlphanumericSpaceHyphen: (opts?: CheckMethodOptions) => this;
|
|
44
|
+
maxWords: (opts: MaxWordsOptions) => this;
|
|
45
|
+
minWords: (opts: MinWordsOptions) => this;
|
|
46
|
+
maxConsecutive: (opts: MaxConsecutiveOptions) => this;
|
|
47
|
+
toTitleCase: () => ZodPipe<this, ZodTransform<string, string>>;
|
|
48
|
+
toSlug: () => ZodPipe<this, ZodTransform<string, string>>;
|
|
49
|
+
stripHtml: () => ZodPipe<this, ZodTransform<string, string>>;
|
|
50
|
+
collapseWhitespace: () => ZodPipe<this, ZodTransform<string, string>>;
|
|
51
|
+
emptyToUndefined: () => ZodPipe<this, ZodTransform<string | undefined, unknown>>;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* BusinessNameOptions
|
|
57
|
+
* Configuration options for the business name validation rule.
|
|
58
|
+
*/
|
|
59
|
+
interface BusinessNameOptions extends FormatRuleOptions {
|
|
60
|
+
/** Length constraints for the business name. */
|
|
61
|
+
readonly length?: Range | undefined;
|
|
62
|
+
/** Extra characters to allow beyond the default set. */
|
|
63
|
+
readonly extraChars?: string | undefined;
|
|
64
|
+
/** Characters to disallow from the default character class. */
|
|
65
|
+
readonly disallowChars?: string | undefined;
|
|
66
|
+
/** Boundary constraint for first/last character. */
|
|
67
|
+
readonly boundary?: Boundary | undefined;
|
|
68
|
+
/** Maximum consecutive identical characters. */
|
|
69
|
+
readonly consecutive?: Range | undefined;
|
|
70
|
+
/** Apply title-case transform to the parsed value. */
|
|
71
|
+
readonly titleCase?: boolean | undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* BusinessName
|
|
75
|
+
* Validates that a string is a plausible business or company name. Allows
|
|
76
|
+
* letters, digits, ampersands, dots, commas, hyphens, apostrophes, and parens.
|
|
77
|
+
*
|
|
78
|
+
* @param options - Optional business name validation options.
|
|
79
|
+
* @returns A Zod schema that validates business name strings.
|
|
80
|
+
*/
|
|
81
|
+
declare const BusinessName: RuleFactory<BusinessNameOptions>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* ColorOptions
|
|
85
|
+
* Options for the color validation rule.
|
|
86
|
+
*/
|
|
87
|
+
interface ColorOptions extends BaseRuleOptions {
|
|
88
|
+
/** Color format to validate. Defaults to 'hex'. */
|
|
89
|
+
readonly format?: 'hex' | 'rgb' | 'hsl' | 'any' | undefined;
|
|
90
|
+
/** Whether to allow alpha channel values. Defaults to true. */
|
|
91
|
+
readonly alpha?: boolean | undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Color
|
|
95
|
+
* Validates that a string is a valid CSS color in the specified format.
|
|
96
|
+
* Supports hex, rgb, hsl, or any format with optional alpha channel.
|
|
97
|
+
*
|
|
98
|
+
* @param options - Optional color validation options.
|
|
99
|
+
* @returns A Zod schema that validates color strings.
|
|
100
|
+
*/
|
|
101
|
+
declare const Color: RuleFactory<ColorOptions>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* CountryOptions
|
|
105
|
+
* Configuration options for the country code validation rule.
|
|
106
|
+
*/
|
|
107
|
+
interface CountryOptions extends BaseRuleOptions {
|
|
108
|
+
/** Country code format: 'alpha2' (default) or 'alpha3'. */
|
|
109
|
+
readonly format?: 'alpha2' | 'alpha3' | undefined;
|
|
110
|
+
/** Restrict to only these country codes. */
|
|
111
|
+
readonly allowCountries?: readonly string[] | undefined;
|
|
112
|
+
/** Block these country codes. */
|
|
113
|
+
readonly blockCountries?: readonly string[] | undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Country
|
|
117
|
+
* Validates that a string is a valid ISO 3166-1 country code.
|
|
118
|
+
* Supports alpha-2 and alpha-3 formats with allow/block filtering.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Per-call country validation options.
|
|
121
|
+
* @returns A Zod schema that validates country code strings.
|
|
122
|
+
*/
|
|
123
|
+
declare const Country: RuleFactory<CountryOptions>;
|
|
124
|
+
|
|
125
|
+
/** IssuerType -- supported card network identifiers. */
|
|
126
|
+
type IssuerType = 'visa' | 'mastercard' | 'amex' | 'discover' | 'diners' | 'jcb' | 'unionpay';
|
|
127
|
+
/**
|
|
128
|
+
* CreditCardOptions
|
|
129
|
+
* Configuration options for the credit card validation rule.
|
|
130
|
+
*/
|
|
131
|
+
interface CreditCardOptions extends BaseRuleOptions {
|
|
132
|
+
/** Only accept cards from these issuers. */
|
|
133
|
+
readonly allowIssuers?: readonly IssuerType[] | undefined;
|
|
134
|
+
/** Reject cards from these issuers. */
|
|
135
|
+
readonly blockIssuers?: readonly IssuerType[] | undefined;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Credit Card
|
|
139
|
+
* Validates that a string is a valid credit card number using the Luhn
|
|
140
|
+
* algorithm with optional issuer filtering. Strips spaces and dashes
|
|
141
|
+
* from formatted input by default.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Per-call credit card validation options.
|
|
144
|
+
* @returns A Zod schema that validates credit card number strings.
|
|
145
|
+
*/
|
|
146
|
+
declare const CreditCard: RuleFactory<CreditCardOptions>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* CurrencyOptions
|
|
150
|
+
* Configuration options for the currency code validation rule.
|
|
151
|
+
*/
|
|
152
|
+
interface CurrencyOptions extends BaseRuleOptions {
|
|
153
|
+
/** Restrict to only these currency codes. */
|
|
154
|
+
readonly allowCurrencies?: readonly string[] | undefined;
|
|
155
|
+
/** Block these currency codes. */
|
|
156
|
+
readonly blockCurrencies?: readonly string[] | undefined;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Currency
|
|
160
|
+
* Validates that a string is a valid ISO 4217 currency code.
|
|
161
|
+
* Supports allow/block filtering for restricting accepted currencies.
|
|
162
|
+
*
|
|
163
|
+
* @param options - Per-call currency validation options.
|
|
164
|
+
* @returns A Zod schema that validates currency code strings.
|
|
165
|
+
*/
|
|
166
|
+
declare const Currency: RuleFactory<CurrencyOptions>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* DateTimeOptions
|
|
170
|
+
* Configuration options for the dateTime validation rule.
|
|
171
|
+
*/
|
|
172
|
+
interface DateTimeOptions extends BaseRuleOptions {
|
|
173
|
+
/** Format to validate: full ISO datetime, date-only, or time-only. */
|
|
174
|
+
readonly format?: 'iso' | 'date' | 'time' | undefined;
|
|
175
|
+
/** Earliest allowed date/time (inclusive). */
|
|
176
|
+
readonly min?: Date | string | undefined;
|
|
177
|
+
/** Latest allowed date/time (inclusive). */
|
|
178
|
+
readonly max?: Date | string | undefined;
|
|
179
|
+
/** Whether future dates are accepted. */
|
|
180
|
+
readonly allowFuture?: boolean | undefined;
|
|
181
|
+
/** Whether past dates are accepted. */
|
|
182
|
+
readonly allowPast?: boolean | undefined;
|
|
183
|
+
/** Whether UTC offset suffixes are accepted. */
|
|
184
|
+
readonly allowOffset?: boolean | undefined;
|
|
185
|
+
/** Whether local datetimes (no Z or offset) are accepted. */
|
|
186
|
+
readonly allowLocal?: boolean | undefined;
|
|
187
|
+
/** Fractional-seconds precision (0-9). */
|
|
188
|
+
readonly precision?: number | undefined;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* DateTime
|
|
192
|
+
* Validates that a string is a valid ISO 8601 datetime, date, or time.
|
|
193
|
+
* Supports range constraints, future/past restrictions, and precision.
|
|
194
|
+
*
|
|
195
|
+
* @param options - Per-call dateTime validation options.
|
|
196
|
+
* @returns A Zod schema that validates date/time strings.
|
|
197
|
+
*/
|
|
198
|
+
declare const DateTime: RuleFactory<DateTimeOptions>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* EmailOptions
|
|
202
|
+
* Configuration options for the email validation rule.
|
|
203
|
+
*/
|
|
204
|
+
interface EmailOptions extends BaseRuleOptions {
|
|
205
|
+
/** Length constraints for the email string. Defaults to { max: 254 }. */
|
|
206
|
+
readonly length?: Range | undefined;
|
|
207
|
+
/** Block email addresses that use plus aliases (e.g. user+tag@domain). */
|
|
208
|
+
readonly blockPlusAlias?: boolean | undefined;
|
|
209
|
+
/** List of domains to block. */
|
|
210
|
+
readonly blockDomains?: readonly string[] | undefined;
|
|
211
|
+
/** Restrict to only these domains. */
|
|
212
|
+
readonly allowDomains?: readonly string[] | undefined;
|
|
213
|
+
/** Block known disposable/temporary email domains (async). */
|
|
214
|
+
readonly blockDisposable?: boolean | undefined;
|
|
215
|
+
/** Allow subdomain email addresses. Defaults to true. */
|
|
216
|
+
readonly allowSubdomains?: boolean | undefined;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Email
|
|
220
|
+
* Validates that a string is a valid email address with configurable
|
|
221
|
+
* domain restrictions, plus-alias blocking, and disposable detection.
|
|
222
|
+
*
|
|
223
|
+
* @param options - Per-call email validation options.
|
|
224
|
+
* @returns A Zod schema that validates email strings.
|
|
225
|
+
*/
|
|
226
|
+
declare const Email: RuleFactory<EmailOptions>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* IbanOptions
|
|
230
|
+
* Configuration options for the IBAN validation rule.
|
|
231
|
+
*/
|
|
232
|
+
interface IbanOptions extends BaseRuleOptions {
|
|
233
|
+
/** Only accept IBANs from these country codes. */
|
|
234
|
+
readonly allowCountries?: readonly string[] | undefined;
|
|
235
|
+
/** Reject IBANs from these country codes. */
|
|
236
|
+
readonly blockCountries?: readonly string[] | undefined;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* IBAN
|
|
240
|
+
* Validates that a string is a valid IBAN with MOD-97 checksum verification.
|
|
241
|
+
* Supports country-specific BBAN format validation and allow/block filtering.
|
|
242
|
+
*
|
|
243
|
+
* @param options - Per-call IBAN validation options.
|
|
244
|
+
* @returns A Zod schema that validates IBAN strings.
|
|
245
|
+
*/
|
|
246
|
+
declare const Iban: RuleFactory<IbanOptions>;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* IpAddressOptions
|
|
250
|
+
* Configuration options for the ipAddress validation rule.
|
|
251
|
+
*/
|
|
252
|
+
interface IpAddressOptions extends BaseRuleOptions {
|
|
253
|
+
/** IP version to accept: v4, v6, or any. */
|
|
254
|
+
readonly version?: 'v4' | 'v6' | 'any' | undefined;
|
|
255
|
+
/** Whether CIDR notation (e.g., /24) is accepted. */
|
|
256
|
+
readonly allowCidr?: boolean | undefined;
|
|
257
|
+
/** Whether private/reserved addresses are accepted. */
|
|
258
|
+
readonly allowPrivate?: boolean | undefined;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* IP Address
|
|
262
|
+
* Validates that a string is a valid IP address, with optional version
|
|
263
|
+
* filtering, CIDR notation support, and private range restriction.
|
|
264
|
+
*
|
|
265
|
+
* @param options - Per-call ipAddress validation options.
|
|
266
|
+
* @returns A Zod schema that validates IP address strings.
|
|
267
|
+
*/
|
|
268
|
+
declare const IpAddress: RuleFactory<IpAddressOptions>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* JWTOptions
|
|
272
|
+
* Configuration options for the JWT validation rule.
|
|
273
|
+
*/
|
|
274
|
+
interface JWTOptions extends BaseRuleOptions {
|
|
275
|
+
/** Require the exp claim to be present. */
|
|
276
|
+
readonly requireExpiry?: boolean | undefined;
|
|
277
|
+
/** Validate that the token has not expired. */
|
|
278
|
+
readonly checkExpiry?: boolean | undefined;
|
|
279
|
+
/** Validate that the token nbf claim is satisfied. */
|
|
280
|
+
readonly checkNotBefore?: boolean | undefined;
|
|
281
|
+
/** Clock tolerance in seconds for temporal checks. */
|
|
282
|
+
readonly clockTolerance?: number | undefined;
|
|
283
|
+
/** Require specific claims to be present in the payload. */
|
|
284
|
+
readonly requireClaims?: readonly string[] | undefined;
|
|
285
|
+
/** Restrict allowed signing algorithms. */
|
|
286
|
+
readonly allowAlgorithms?: readonly string[] | undefined;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* JWT
|
|
290
|
+
* Validates that a string is a structurally valid JWT and optionally
|
|
291
|
+
* checks expiry, not-before, required claims, and allowed algorithms.
|
|
292
|
+
*
|
|
293
|
+
* @param options - Per-call JWT validation options.
|
|
294
|
+
* @returns A Zod schema that validates JWT strings.
|
|
295
|
+
*/
|
|
296
|
+
declare const Jwt: RuleFactory<JWTOptions>;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* LicenseKeyOptions
|
|
300
|
+
* Configuration options for the license key validation rule.
|
|
301
|
+
*/
|
|
302
|
+
interface LicenseKeyOptions extends FormatRuleOptions {
|
|
303
|
+
/** License key format type. Defaults to 'custom'. */
|
|
304
|
+
readonly type?: 'windows' | 'uuid' | 'custom' | undefined;
|
|
305
|
+
/** Number of segments in the key. Defaults to 5. */
|
|
306
|
+
readonly segments?: number | undefined;
|
|
307
|
+
/** Length of each segment. Defaults to 5. */
|
|
308
|
+
readonly segmentLength?: number | undefined;
|
|
309
|
+
/** Separator between segments. Defaults to '-'. */
|
|
310
|
+
readonly separator?: string | undefined;
|
|
311
|
+
/** Character set for each segment. Defaults to 'alphanumeric'. */
|
|
312
|
+
readonly charset?: 'alphanumeric' | 'alpha' | 'numeric' | 'hex' | undefined;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* LicenseKey
|
|
316
|
+
* Validates that a string is a valid license key. Supports UUID format,
|
|
317
|
+
* Windows-style keys, and fully customizable segment patterns.
|
|
318
|
+
*
|
|
319
|
+
* @param options - Optional license key validation options.
|
|
320
|
+
* @returns A Zod schema that validates license key strings.
|
|
321
|
+
*/
|
|
322
|
+
declare const LicenseKey: RuleFactory<LicenseKeyOptions>;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* MacAddressOptions
|
|
326
|
+
* Configuration options for the MAC address validation rule.
|
|
327
|
+
*/
|
|
328
|
+
interface MacAddressOptions extends BaseRuleOptions {
|
|
329
|
+
/** Delimiter between octets. Defaults to ':'. */
|
|
330
|
+
readonly delimiter?: ':' | '-' | 'none' | undefined;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Mac Address
|
|
334
|
+
* Validates that a string is a valid MAC address in the specified
|
|
335
|
+
* delimiter format. Trims whitespace by default.
|
|
336
|
+
*
|
|
337
|
+
* @param options - Per-call MAC address validation options.
|
|
338
|
+
* @returns A Zod schema that validates MAC address strings.
|
|
339
|
+
*/
|
|
340
|
+
declare const MacAddress: RuleFactory<MacAddressOptions>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* PasswordOptions
|
|
344
|
+
* Configuration options for the password validation rule.
|
|
345
|
+
*/
|
|
346
|
+
interface PasswordOptions extends BaseRuleOptions {
|
|
347
|
+
/** Length constraint for the password string. */
|
|
348
|
+
readonly length?: Range | undefined;
|
|
349
|
+
/** Required uppercase letter count. */
|
|
350
|
+
readonly uppercase?: Range | undefined;
|
|
351
|
+
/** Required lowercase letter count. */
|
|
352
|
+
readonly lowercase?: Range | undefined;
|
|
353
|
+
/** Required digit count. */
|
|
354
|
+
readonly digits?: Range | undefined;
|
|
355
|
+
/** Required special character count. */
|
|
356
|
+
readonly special?: Range | undefined;
|
|
357
|
+
/** Maximum consecutive identical characters. */
|
|
358
|
+
readonly consecutive?: Range | undefined;
|
|
359
|
+
/** Block common passwords. */
|
|
360
|
+
readonly blockCommon?: boolean | 'basic' | 'moderate' | 'strict' | undefined;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Password
|
|
364
|
+
* Validates that a string meets password strength requirements including
|
|
365
|
+
* length, character composition, and consecutive character limits.
|
|
366
|
+
*
|
|
367
|
+
* @param options - Per-call password validation options.
|
|
368
|
+
* @returns A Zod schema that validates password strings.
|
|
369
|
+
*/
|
|
370
|
+
declare const Password: RuleFactory<PasswordOptions>;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* PasswordConfirmationOptions
|
|
374
|
+
* Configuration for the password confirmation validation rule.
|
|
375
|
+
*/
|
|
376
|
+
interface PasswordConfirmationOptions extends BaseRuleOptions {
|
|
377
|
+
/** Name of the password field to match against (used by sameAs). */
|
|
378
|
+
readonly passwordField?: string | undefined;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Password Confirmation
|
|
382
|
+
* Returns a schema that validates the confirmation string using the same
|
|
383
|
+
* base password rule. Cross-field matching (sameAs) is resolved by
|
|
384
|
+
* validate() using the registered metadata.
|
|
385
|
+
*
|
|
386
|
+
* @param options - Per-call options (passwordField controls sameAs target).
|
|
387
|
+
* @returns A Zod schema that validates the confirmation string.
|
|
388
|
+
*/
|
|
389
|
+
declare const PasswordConfirmation: (options?: Partial<PasswordConfirmationOptions>) => unknown;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* PersonNameOptions
|
|
393
|
+
* Configuration options for the person name validation rule.
|
|
394
|
+
*/
|
|
395
|
+
interface PersonNameOptions extends FormatRuleOptions {
|
|
396
|
+
/** Length constraints for the full name string. */
|
|
397
|
+
readonly length?: Range | undefined;
|
|
398
|
+
/** Word count constraints. */
|
|
399
|
+
readonly words?: Range | undefined;
|
|
400
|
+
/** Allow unicode letters (\p{L}) vs ASCII-only. Defaults to true. */
|
|
401
|
+
readonly allowUnicode?: boolean | undefined;
|
|
402
|
+
/** Extra characters to allow in the character class. */
|
|
403
|
+
readonly extraChars?: string | undefined;
|
|
404
|
+
/** Characters to disallow from the default character class. */
|
|
405
|
+
readonly disallowChars?: string | undefined;
|
|
406
|
+
/** Boundary constraint for first/last character. */
|
|
407
|
+
readonly boundary?: Boundary | undefined;
|
|
408
|
+
/** Maximum consecutive identical characters. */
|
|
409
|
+
readonly consecutive?: Range | undefined;
|
|
410
|
+
/** Apply title-case transform to the parsed value. */
|
|
411
|
+
readonly titleCase?: boolean | undefined;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* PersonName
|
|
415
|
+
* Validates that a string is a plausible human name. Supports unicode,
|
|
416
|
+
* hyphens, apostrophes, boundary constraints, and word limits.
|
|
417
|
+
*
|
|
418
|
+
* @param options - Optional person name validation options.
|
|
419
|
+
* @returns A Zod schema that validates person name strings.
|
|
420
|
+
*/
|
|
421
|
+
declare const PersonName: RuleFactory<PersonNameOptions>;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* PhoneOptions
|
|
425
|
+
* Configuration options for the phone number validation rule.
|
|
426
|
+
*/
|
|
427
|
+
interface PhoneOptions extends BaseRuleOptions {
|
|
428
|
+
/** Default country code for parsing (ISO 3166-1 alpha-2). */
|
|
429
|
+
readonly country?: string | undefined;
|
|
430
|
+
/** Restrict to only these country codes. */
|
|
431
|
+
readonly allowCountries?: readonly string[] | undefined;
|
|
432
|
+
/** Block these country codes. */
|
|
433
|
+
readonly blockCountries?: readonly string[] | undefined;
|
|
434
|
+
/** Require a mobile phone number. */
|
|
435
|
+
readonly requireMobile?: boolean | undefined;
|
|
436
|
+
/** Require the input to start with '+' (country code prefix). */
|
|
437
|
+
readonly requireCountryCode?: boolean | undefined;
|
|
438
|
+
/** Output format for the normalized phone number. */
|
|
439
|
+
readonly format?: 'e164' | 'international' | 'national' | undefined;
|
|
440
|
+
/** Which metadata bundle libphonenumber-js should use. */
|
|
441
|
+
readonly metadata?: 'min' | 'mobile' | 'max' | 'custom' | undefined;
|
|
442
|
+
/** Path to a custom metadata JSON file (used when metadata is 'custom'). */
|
|
443
|
+
readonly customMetadataPath?: string | undefined;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Phone
|
|
447
|
+
* Validates that a string is a valid phone number. Supports country
|
|
448
|
+
* filtering, mobile requirement, and output format normalization.
|
|
449
|
+
*
|
|
450
|
+
* @param options - Per-call phone validation options.
|
|
451
|
+
* @returns A Zod schema that validates phone number strings.
|
|
452
|
+
*/
|
|
453
|
+
declare const Phone: RuleFactory<PhoneOptions>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* PostalCodeOptions
|
|
457
|
+
* Configuration options for the postal code validation rule.
|
|
458
|
+
*/
|
|
459
|
+
interface PostalCodeOptions extends FormatRuleOptions {
|
|
460
|
+
/** ISO 3166-1 alpha-2 country code (required). */
|
|
461
|
+
readonly country: string;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Postal Code
|
|
465
|
+
* Validates that a string is a valid postal code for the specified country.
|
|
466
|
+
* Uses postcode-validator for validation, or a custom regex/customFn override.
|
|
467
|
+
* Throws at creation time if the module is preloaded and the country is
|
|
468
|
+
* unsupported. Otherwise defers validation to parse time.
|
|
469
|
+
*
|
|
470
|
+
* @param options - Per-call postal code validation options.
|
|
471
|
+
* @returns A Zod schema that validates postal code strings.
|
|
472
|
+
*/
|
|
473
|
+
declare const PostalCode: RuleFactory<PostalCodeOptions>;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* SlugOptions
|
|
477
|
+
* Options for the slug validation rule.
|
|
478
|
+
*/
|
|
479
|
+
interface SlugOptions extends FormatRuleOptions {
|
|
480
|
+
/** Length constraints for the slug. Defaults to { min: 3, max: 100 }. */
|
|
481
|
+
readonly length?: Range | undefined;
|
|
482
|
+
/** Additional characters to allow in the slug character class. */
|
|
483
|
+
readonly extraChars?: string | undefined;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Slug
|
|
487
|
+
* Validates that a string is a URL-friendly slug. Supports custom length
|
|
488
|
+
* constraints, extra allowed characters, and regex override.
|
|
489
|
+
*
|
|
490
|
+
* @param options - Optional slug validation options.
|
|
491
|
+
* @returns A Zod schema that validates slug strings.
|
|
492
|
+
*/
|
|
493
|
+
declare const Slug: RuleFactory<SlugOptions>;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* TextOptions
|
|
497
|
+
* Configuration options for the text validation rule.
|
|
498
|
+
*/
|
|
499
|
+
interface TextOptions extends FormatRuleOptions {
|
|
500
|
+
/** Length constraints for the text string. */
|
|
501
|
+
readonly length?: Range | undefined;
|
|
502
|
+
/** Word count constraints. */
|
|
503
|
+
readonly words?: Range | undefined;
|
|
504
|
+
/** Consecutive character repetition constraints. */
|
|
505
|
+
readonly consecutive?: Range | undefined;
|
|
506
|
+
/** Reject text that contains email addresses. */
|
|
507
|
+
readonly noEmails?: boolean | undefined;
|
|
508
|
+
/** Reject text that contains URLs. */
|
|
509
|
+
readonly noUrls?: boolean | undefined;
|
|
510
|
+
/** Reject text that contains phone numbers. */
|
|
511
|
+
readonly noPhoneNumbers?: boolean | undefined;
|
|
512
|
+
/** Reject text that contains HTML tags. */
|
|
513
|
+
readonly noHtml?: boolean | undefined;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Text
|
|
517
|
+
* Validates free-form text with optional content detection,
|
|
518
|
+
* word limits, and consecutive character restrictions.
|
|
519
|
+
*
|
|
520
|
+
* @param options - Per-call text validation options.
|
|
521
|
+
* @returns A Zod schema that validates text strings.
|
|
522
|
+
*/
|
|
523
|
+
declare const Text: RuleFactory<TextOptions>;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* TokenType
|
|
527
|
+
* Supported token format types.
|
|
528
|
+
*/
|
|
529
|
+
type TokenType = 'nanoid' | 'hex' | 'base64' | 'cuid' | 'cuid2' | 'ulid';
|
|
530
|
+
/**
|
|
531
|
+
* TokenOptions
|
|
532
|
+
* Configuration options for the token validation rule.
|
|
533
|
+
*/
|
|
534
|
+
interface TokenOptions extends FormatRuleOptions {
|
|
535
|
+
/** Token format type. Required, no default. */
|
|
536
|
+
readonly type: TokenType;
|
|
537
|
+
/** Length constraints for the token. Defaults vary by type. */
|
|
538
|
+
readonly length?: Range | undefined;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Token
|
|
542
|
+
* Validates that a string is a valid token of the specified type.
|
|
543
|
+
* Supports nanoid, hex, base64, cuid, cuid2, and ulid formats.
|
|
544
|
+
*
|
|
545
|
+
* @param options - Token validation options (type is required).
|
|
546
|
+
* @returns A Zod schema that validates token strings.
|
|
547
|
+
*/
|
|
548
|
+
declare const Token: RuleFactory<TokenOptions>;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* URLOptions
|
|
552
|
+
* Configuration options for the URL validation rule.
|
|
553
|
+
*/
|
|
554
|
+
interface URLOptions extends BaseRuleOptions {
|
|
555
|
+
/** Allowed protocols (without trailing colon). Defaults to ['http', 'https']. */
|
|
556
|
+
readonly protocols?: readonly string[] | undefined;
|
|
557
|
+
/** Require a TLD (at least one dot in hostname). Defaults to true. */
|
|
558
|
+
readonly requireTLD?: boolean | undefined;
|
|
559
|
+
/** Length constraints for the full URL. Defaults to { max: 2048 }. */
|
|
560
|
+
readonly length?: Range | undefined;
|
|
561
|
+
/** Whitelist of allowed domains. Empty means allow all. */
|
|
562
|
+
readonly allowDomains?: readonly string[] | undefined;
|
|
563
|
+
/** Blacklist of blocked domains. */
|
|
564
|
+
readonly blockDomains?: readonly string[] | undefined;
|
|
565
|
+
/** Allow query strings. Defaults to true. */
|
|
566
|
+
readonly allowQuery?: boolean | undefined;
|
|
567
|
+
/** Allow userinfo (user:pass@). Defaults to false. */
|
|
568
|
+
readonly allowAuth?: boolean | undefined;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Url
|
|
572
|
+
* Validates that a string is a valid URL with configurable protocol,
|
|
573
|
+
* TLD, domain, query, and auth constraints.
|
|
574
|
+
*
|
|
575
|
+
* @param options - Optional URL validation options.
|
|
576
|
+
* @returns A Zod schema that validates URL strings.
|
|
577
|
+
*/
|
|
578
|
+
declare const Url: RuleFactory<URLOptions>;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* UsernameOptions
|
|
582
|
+
* Configuration options for the username validation rule.
|
|
583
|
+
*/
|
|
584
|
+
interface UsernameOptions extends FormatRuleOptions {
|
|
585
|
+
/** Length constraints for the username. Defaults to { min: 3, max: 20 }. */
|
|
586
|
+
readonly length?: Range | undefined;
|
|
587
|
+
/** Character pattern preset. Defaults to 'alphanumeric-underscore'. */
|
|
588
|
+
readonly pattern?: 'alphanumeric' | 'alphanumeric-dash' | 'alphanumeric-underscore' | undefined;
|
|
589
|
+
/** Additional characters to allow in the character class. */
|
|
590
|
+
readonly extraChars?: string | undefined;
|
|
591
|
+
/** Characters to disallow from the pattern character class. */
|
|
592
|
+
readonly disallowChars?: string | undefined;
|
|
593
|
+
/** Boundary constraint for first/last character. Defaults to 'alphanumeric'. */
|
|
594
|
+
readonly boundary?: Boundary | undefined;
|
|
595
|
+
/** Maximum consecutive identical characters. */
|
|
596
|
+
readonly consecutive?: Range | undefined;
|
|
597
|
+
/** Reserved words that cannot be used as usernames. */
|
|
598
|
+
readonly reservedWords?: readonly string[] | undefined;
|
|
599
|
+
/** Block reserved words. Defaults to false. */
|
|
600
|
+
readonly blockReserved?: boolean | undefined;
|
|
601
|
+
/** Ignore case when checking patterns and reserved words. Defaults to true. */
|
|
602
|
+
readonly ignoreCase?: boolean | undefined;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Username
|
|
606
|
+
* Validates that a string is a valid username with configurable pattern,
|
|
607
|
+
* boundary constraints, and consecutive character limits.
|
|
608
|
+
*
|
|
609
|
+
* @param options - Optional username validation options.
|
|
610
|
+
* @returns A Zod schema that validates username strings.
|
|
611
|
+
*/
|
|
612
|
+
declare const Username: RuleFactory<UsernameOptions>;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* UUIDOptions
|
|
616
|
+
* Configuration options for the UUID validation rule.
|
|
617
|
+
*/
|
|
618
|
+
interface UUIDOptions extends BaseRuleOptions {
|
|
619
|
+
/** UUID version to accept (1-8 or 'any'). Defaults to 'any'. */
|
|
620
|
+
readonly version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 'any' | undefined;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* UUID
|
|
624
|
+
* Validates that a string is a valid UUID, optionally restricted to a
|
|
625
|
+
* specific version. Normalizes to lowercase + trimmed by default.
|
|
626
|
+
*
|
|
627
|
+
* @param options - Per-call UUID validation options.
|
|
628
|
+
* @returns A Zod schema that validates UUID strings.
|
|
629
|
+
*/
|
|
630
|
+
declare const Uuid: RuleFactory<UUIDOptions>;
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* VatNumberOptions
|
|
634
|
+
* Configuration options for the VAT number validation rule.
|
|
635
|
+
*/
|
|
636
|
+
interface VatNumberOptions extends BaseRuleOptions {
|
|
637
|
+
/** ISO country code to validate against (e.g. 'DE', 'FR'). */
|
|
638
|
+
readonly country?: string | undefined;
|
|
639
|
+
/** Require the country prefix at the start of the value. */
|
|
640
|
+
readonly requirePrefix?: boolean | undefined;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* VAT Number
|
|
644
|
+
* Validates that a string is a valid VAT identification number.
|
|
645
|
+
* Auto-detects country from prefix or validates against a specified code.
|
|
646
|
+
*
|
|
647
|
+
* @param options - Per-call VAT number validation options.
|
|
648
|
+
* @returns A Zod schema that validates VAT number strings.
|
|
649
|
+
*/
|
|
650
|
+
declare const VatNumber: RuleFactory<VatNumberOptions>;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* WebsiteOptions
|
|
654
|
+
* Configuration options for the website validation rule.
|
|
655
|
+
*/
|
|
656
|
+
interface WebsiteOptions extends BaseRuleOptions {
|
|
657
|
+
/** Length constraints for the full URL. Defaults to { max: 255 }. */
|
|
658
|
+
readonly length?: Range | undefined;
|
|
659
|
+
/** Require the hostname to start with 'www.'. */
|
|
660
|
+
readonly requireWww?: boolean | undefined;
|
|
661
|
+
/** Require https protocol (reject http). */
|
|
662
|
+
readonly requireHttps?: boolean | undefined;
|
|
663
|
+
/** Whitelist of allowed domains. Empty means allow all. */
|
|
664
|
+
readonly allowDomains?: readonly string[] | undefined;
|
|
665
|
+
/** Blacklist of blocked domains. */
|
|
666
|
+
readonly blockDomains?: readonly string[] | undefined;
|
|
667
|
+
/** Allow subdomain URLs. Defaults to true. */
|
|
668
|
+
readonly allowSubdomains?: boolean | undefined;
|
|
669
|
+
/** Allow URL paths beyond '/'. Defaults to true. */
|
|
670
|
+
readonly allowPath?: boolean | undefined;
|
|
671
|
+
/** Allow query strings. Defaults to false. */
|
|
672
|
+
readonly allowQuery?: boolean | undefined;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Website
|
|
676
|
+
* Validates that a string is a valid website URL. Auto-prepends https://
|
|
677
|
+
* to bare domains, enforces protocol/domain/path constraints.
|
|
678
|
+
*
|
|
679
|
+
* @param options - Optional website validation options.
|
|
680
|
+
* @returns A Zod schema that validates website URLs.
|
|
681
|
+
*/
|
|
682
|
+
declare const Website: RuleFactory<WebsiteOptions>;
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Range
|
|
686
|
+
* Defines a numeric range constraint. A number means exact value.
|
|
687
|
+
*
|
|
688
|
+
* @returns number | object with min/max
|
|
689
|
+
*/
|
|
690
|
+
type Range = number | {
|
|
691
|
+
readonly min?: number;
|
|
692
|
+
readonly max?: number;
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* Boundary
|
|
696
|
+
* Controls character restrictions at string start/end.
|
|
697
|
+
* A string shorthand applies to both start and end.
|
|
698
|
+
*
|
|
699
|
+
* @returns string | object with start/end
|
|
700
|
+
*/
|
|
701
|
+
type Boundary = 'alpha' | 'alphanumeric' | 'any' | {
|
|
702
|
+
readonly start?: 'alpha' | 'alphanumeric' | 'any';
|
|
703
|
+
readonly end?: 'alpha' | 'alphanumeric' | 'any';
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* BaseRuleOptions
|
|
707
|
+
* Base options available on every validation rule.
|
|
708
|
+
*/
|
|
709
|
+
interface BaseRuleOptions {
|
|
710
|
+
/** Explicit label for error messages. */
|
|
711
|
+
readonly label?: string;
|
|
712
|
+
/** Convert empty strings to undefined before validation. */
|
|
713
|
+
readonly emptyToUndefined?: boolean;
|
|
714
|
+
/** Apply rule-specific normalization (trim, lowercase, etc.). */
|
|
715
|
+
readonly normalize?: boolean;
|
|
716
|
+
/** Custom validation function that runs after all built-in checks. */
|
|
717
|
+
readonly customFn?: (value: string) => true | string | Promise<true | string>;
|
|
718
|
+
/** Cross-field equality check. Field name that this field must match. */
|
|
719
|
+
readonly sameAs?: string;
|
|
720
|
+
/** Conditional requirement. Field name — when that field has a value, this field becomes required. */
|
|
721
|
+
readonly requiredWhen?: string;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* FormatRuleOptions
|
|
725
|
+
* Extended options for rules that support regex override.
|
|
726
|
+
*/
|
|
727
|
+
interface FormatRuleOptions extends BaseRuleOptions {
|
|
728
|
+
/** Override the built-in format pattern with a custom regex. */
|
|
729
|
+
readonly regex?: RegExp;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* TranslationFunction
|
|
733
|
+
* A function that translates i18n keys to localized strings.
|
|
734
|
+
*
|
|
735
|
+
* @param key - The i18n key to translate.
|
|
736
|
+
* @param params - Interpolation parameters.
|
|
737
|
+
* @returns The translated string.
|
|
738
|
+
*/
|
|
739
|
+
type TranslationFunction = (key: string, params?: Record<string, unknown>) => string;
|
|
740
|
+
/**
|
|
741
|
+
* PathTransform
|
|
742
|
+
* Transforms a field path array into a custom string format.
|
|
743
|
+
*
|
|
744
|
+
* @param path - The field path segments.
|
|
745
|
+
* @returns The transformed path string.
|
|
746
|
+
*/
|
|
747
|
+
type PathTransform = (path: ReadonlyArray<string | number>) => string;
|
|
748
|
+
/**
|
|
749
|
+
* LabelTransform
|
|
750
|
+
* Transforms field labels for error messages.
|
|
751
|
+
*
|
|
752
|
+
* @param ctx - Context with path, fieldName, defaultLabel, and optional explicitLabel.
|
|
753
|
+
* @returns The transformed label string.
|
|
754
|
+
*/
|
|
755
|
+
type LabelTransform = (ctx: {
|
|
756
|
+
readonly path: ReadonlyArray<string | number>;
|
|
757
|
+
readonly fieldName: string;
|
|
758
|
+
readonly defaultLabel: string;
|
|
759
|
+
readonly explicitLabel?: string;
|
|
760
|
+
}) => string;
|
|
761
|
+
/**
|
|
762
|
+
* MessageTransform
|
|
763
|
+
* Transforms error messages for custom formatting.
|
|
764
|
+
*
|
|
765
|
+
* @param ctx - Context with key, code, namespace, path, label, message, and params.
|
|
766
|
+
* @returns The transformed message string.
|
|
767
|
+
*/
|
|
768
|
+
type MessageTransform = (ctx: {
|
|
769
|
+
readonly key: string;
|
|
770
|
+
readonly code: string;
|
|
771
|
+
readonly namespace: string;
|
|
772
|
+
readonly path: ReadonlyArray<string | number>;
|
|
773
|
+
readonly label: string;
|
|
774
|
+
readonly message: string;
|
|
775
|
+
readonly params: Record<string, unknown>;
|
|
776
|
+
}) => string;
|
|
777
|
+
/**
|
|
778
|
+
* I18nConfig
|
|
779
|
+
* Internationalization configuration.
|
|
780
|
+
*/
|
|
781
|
+
interface I18nConfig {
|
|
782
|
+
/** Enable i18n mode. When true, messages become i18n keys. */
|
|
783
|
+
readonly enabled: boolean;
|
|
784
|
+
/** Key prefix for all i18n keys. */
|
|
785
|
+
readonly prefix?: string;
|
|
786
|
+
/** Separator between key segments. */
|
|
787
|
+
readonly separator?: string;
|
|
788
|
+
/** How field paths are encoded into message keys. */
|
|
789
|
+
readonly pathMode?: 'semantic' | 'key' | 'full' | PathTransform;
|
|
790
|
+
/** Translation function for automatic message translation. */
|
|
791
|
+
readonly t?: TranslationFunction;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* LabelConfig
|
|
795
|
+
* Label derivation configuration.
|
|
796
|
+
*/
|
|
797
|
+
interface LabelConfig {
|
|
798
|
+
/** How labels are derived when not explicitly provided. */
|
|
799
|
+
readonly fallback?: 'derived' | 'generic' | 'none';
|
|
800
|
+
/** Custom label transform function. */
|
|
801
|
+
readonly transform?: LabelTransform;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* MessageConfig
|
|
805
|
+
* Message formatting configuration.
|
|
806
|
+
*/
|
|
807
|
+
interface MessageConfig {
|
|
808
|
+
/** Custom message transform function. */
|
|
809
|
+
readonly transform?: MessageTransform;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* RuleDefaults
|
|
813
|
+
* Typed per-rule defaults for all 25 built-in rules. Keys are namespace
|
|
814
|
+
* names (camelCase) matching each rule's `name` in createRule.
|
|
815
|
+
*/
|
|
816
|
+
interface RuleDefaults {
|
|
817
|
+
readonly email?: Partial<EmailOptions>;
|
|
818
|
+
readonly personName?: Partial<PersonNameOptions>;
|
|
819
|
+
readonly businessName?: Partial<BusinessNameOptions>;
|
|
820
|
+
readonly password?: Partial<PasswordOptions>;
|
|
821
|
+
readonly passwordConfirmation?: Partial<PasswordConfirmationOptions>;
|
|
822
|
+
readonly phone?: Partial<PhoneOptions>;
|
|
823
|
+
readonly website?: Partial<WebsiteOptions>;
|
|
824
|
+
readonly url?: Partial<URLOptions>;
|
|
825
|
+
readonly username?: Partial<UsernameOptions>;
|
|
826
|
+
readonly slug?: Partial<SlugOptions>;
|
|
827
|
+
readonly postalCode?: Partial<PostalCodeOptions>;
|
|
828
|
+
readonly licenseKey?: Partial<LicenseKeyOptions>;
|
|
829
|
+
readonly uuid?: Partial<UUIDOptions>;
|
|
830
|
+
readonly jwt?: Partial<JWTOptions>;
|
|
831
|
+
readonly dateTime?: Partial<DateTimeOptions>;
|
|
832
|
+
readonly token?: Partial<TokenOptions>;
|
|
833
|
+
readonly text?: Partial<TextOptions>;
|
|
834
|
+
readonly country?: Partial<CountryOptions>;
|
|
835
|
+
readonly currency?: Partial<CurrencyOptions>;
|
|
836
|
+
readonly color?: Partial<ColorOptions>;
|
|
837
|
+
readonly creditCard?: Partial<CreditCardOptions>;
|
|
838
|
+
readonly iban?: Partial<IbanOptions>;
|
|
839
|
+
readonly vatNumber?: Partial<VatNumberOptions>;
|
|
840
|
+
readonly macAddress?: Partial<MacAddressOptions>;
|
|
841
|
+
readonly ipAddress?: Partial<IpAddressOptions>;
|
|
842
|
+
/** Index signature for custom rules created with createRule. */
|
|
843
|
+
readonly [key: string]: Partial<Record<string, unknown>> | undefined;
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* GlobalConfig
|
|
847
|
+
* Top-level configuration for the validex library.
|
|
848
|
+
*/
|
|
849
|
+
interface GlobalConfig {
|
|
850
|
+
/** Internationalization settings. */
|
|
851
|
+
readonly i18n: I18nConfig;
|
|
852
|
+
/** Label derivation settings. */
|
|
853
|
+
readonly label?: LabelConfig;
|
|
854
|
+
/** Message formatting settings. */
|
|
855
|
+
readonly message?: MessageConfig;
|
|
856
|
+
/** Global rule defaults (overrides built-in defaults). */
|
|
857
|
+
readonly rules?: Partial<RuleDefaults>;
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* PreloadOptions
|
|
861
|
+
* Options for preloading async data at startup.
|
|
862
|
+
*/
|
|
863
|
+
interface PreloadOptions {
|
|
864
|
+
/** Preload disposable email domain list. */
|
|
865
|
+
readonly disposable?: boolean;
|
|
866
|
+
/** Preload common password lists. */
|
|
867
|
+
readonly passwords?: boolean | 'basic' | 'moderate' | 'strict';
|
|
868
|
+
/** Preload reserved username list. */
|
|
869
|
+
readonly reserved?: boolean;
|
|
870
|
+
/** Preload phone number metadata variant. */
|
|
871
|
+
readonly phone?: 'min' | 'mobile' | 'max';
|
|
872
|
+
/** Preload country codes. */
|
|
873
|
+
readonly countryCodes?: boolean;
|
|
874
|
+
/** Preload currency codes. */
|
|
875
|
+
readonly currencyCodes?: boolean;
|
|
876
|
+
/** Preload IBAN patterns. */
|
|
877
|
+
readonly ibanPatterns?: boolean;
|
|
878
|
+
/** Preload VAT patterns. */
|
|
879
|
+
readonly vatPatterns?: boolean;
|
|
880
|
+
/** Preload credit card prefixes. */
|
|
881
|
+
readonly creditCardPrefixes?: boolean;
|
|
882
|
+
/** Preload postal code validation module. */
|
|
883
|
+
readonly postalCodes?: boolean;
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* NestedErrors
|
|
887
|
+
* Recursive type for nested error objects matching schema shape.
|
|
888
|
+
*/
|
|
889
|
+
interface NestedErrors {
|
|
890
|
+
readonly [field: string]: readonly string[] | NestedErrors;
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* ValidationResult
|
|
894
|
+
* Result of running validate() on a schema and data.
|
|
895
|
+
*/
|
|
896
|
+
interface ValidationResult<T> {
|
|
897
|
+
/** Whether validation passed. */
|
|
898
|
+
readonly success: boolean;
|
|
899
|
+
/** Typed parsed data, only populated when success is true. */
|
|
900
|
+
readonly data?: T;
|
|
901
|
+
/** Flat dot-path to all error messages per field. */
|
|
902
|
+
readonly errors: Record<string, readonly string[]>;
|
|
903
|
+
/** Flat dot-path to first error message per field. */
|
|
904
|
+
readonly firstErrors: Record<string, string>;
|
|
905
|
+
/** Nested error object matching schema shape. */
|
|
906
|
+
readonly nestedErrors: NestedErrors;
|
|
907
|
+
/** Raw Zod issues (escape hatch). */
|
|
908
|
+
readonly issues: ReadonlyArray<unknown>;
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* CreateRuleOptions
|
|
912
|
+
* Configuration object passed to the createRule factory.
|
|
913
|
+
*/
|
|
914
|
+
interface CreateRuleOptions<T extends BaseRuleOptions> {
|
|
915
|
+
/** Namespace for error codes (e.g., 'email', 'password'). */
|
|
916
|
+
readonly name: string;
|
|
917
|
+
/** Tier 1 defaults for this rule. */
|
|
918
|
+
readonly defaults: Partial<T>;
|
|
919
|
+
/** Builder function that constructs the Zod schema from resolved options. */
|
|
920
|
+
readonly build: (opts: T) => unknown;
|
|
921
|
+
/** English message templates keyed by error code. */
|
|
922
|
+
readonly messages: Readonly<Record<string, string>>;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* RuleFactory
|
|
926
|
+
* The function returned by createRule. Accepts per-call options and returns a Zod schema.
|
|
927
|
+
*/
|
|
928
|
+
type RuleFactory<T extends BaseRuleOptions> = (options?: Partial<T>) => unknown;
|
|
929
|
+
/**
|
|
930
|
+
* ErrorParams
|
|
931
|
+
* Normalized error parameters extracted from a Zod issue by getParams().
|
|
932
|
+
*/
|
|
933
|
+
interface ErrorParams {
|
|
934
|
+
/** The validex error code. */
|
|
935
|
+
readonly code: string;
|
|
936
|
+
/** The error namespace. */
|
|
937
|
+
readonly namespace: string;
|
|
938
|
+
/** The resolved field label. */
|
|
939
|
+
readonly label: string;
|
|
940
|
+
/** i18n key for the label (only in i18n mode). */
|
|
941
|
+
readonly labelKey?: string;
|
|
942
|
+
/** Full i18n key for the message. */
|
|
943
|
+
readonly key: string;
|
|
944
|
+
/** Field path as array. */
|
|
945
|
+
readonly path: ReadonlyArray<string | number>;
|
|
946
|
+
/** Additional interpolation parameters. */
|
|
947
|
+
readonly [param: string]: unknown;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
export { type PhoneOptions as $, type MaxConsecutiveOptions as A, type BaseRuleOptions as B, type CreateRuleOptions as C, DateTime as D, type ErrorParams as E, type FormatRuleOptions as F, type GlobalConfig as G, type MaxWordsOptions as H, type I18nConfig as I, type JWTOptions as J, type MessageConfig as K, type LabelConfig as L, MacAddress as M, type MessageTransform as N, type MinWordsOptions as O, type PreloadOptions as P, type NestedErrors as Q, type RuleFactory as R, Password as S, PasswordConfirmation as T, type PasswordConfirmationOptions as U, type ValidationResult as V, type PasswordOptions as W, type PathTransform as X, PersonName as Y, type PersonNameOptions as Z, Phone as _, type Boundary as a, PostalCode as a0, type PostalCodeOptions as a1, type Range as a2, type RuleDefaults as a3, Slug as a4, type SlugOptions as a5, Text as a6, type TextOptions as a7, Token as a8, type TokenOptions as a9, type TokenType as aa, type TranslationFunction as ab, type URLOptions as ac, type UUIDOptions as ad, Url as ae, Username as af, type UsernameOptions as ag, Uuid as ah, VatNumber as ai, type VatNumberOptions as aj, Website as ak, type WebsiteOptions as al, BusinessName as b, type BusinessNameOptions as c, type CheckMethodOptions as d, Color as e, type ColorOptions as f, type CompositionMethodOptions as g, Country as h, type CountryOptions as i, CreditCard as j, type CreditCardOptions as k, Currency as l, type CurrencyOptions as m, type DateTimeOptions as n, Email as o, type EmailOptions as p, Iban as q, type IbanOptions as r, IpAddress as s, type IpAddressOptions as t, type IssuerType as u, Jwt as v, type LabelTransform as w, LicenseKey as x, type LicenseKeyOptions as y, type MacAddressOptions as z };
|