@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.
- package/.github/workflows/ci.yml +24 -0
- package/CLAUDE.md +64 -22
- package/dist/chunk-2SWEVDFZ.js +134 -0
- package/dist/chunk-32JI34CV.cjs +146 -0
- package/dist/chunk-42C5OHRK.js +71 -0
- package/dist/chunk-46VAH2BJ.js +160 -0
- package/dist/chunk-5JGTDL3Y.js +87 -0
- package/dist/chunk-5LEXCVLX.js +257 -0
- package/dist/chunk-6AAP4LPF.js +2606 -0
- package/dist/chunk-B4EZYZOK.cjs +215 -0
- package/dist/chunk-COYKBWTI.js +161 -0
- package/dist/chunk-DFJZ3NS2.cjs +151 -0
- package/dist/chunk-EDHT4LPO.js +118 -0
- package/dist/chunk-EGHL277K.cjs +165 -0
- package/dist/chunk-ERH4NIMU.cjs +69 -0
- package/dist/chunk-FM3EZ72O.js +165 -0
- package/dist/chunk-GJIRDBZJ.cjs +90 -0
- package/dist/chunk-H2XTEM4M.js +696 -0
- package/dist/chunk-HMSM6FFA.cjs +181 -0
- package/dist/chunk-HTEHINI7.cjs +177 -0
- package/dist/chunk-JOLSGZGN.cjs +696 -0
- package/dist/chunk-JXY7APBU.js +69 -0
- package/dist/chunk-K2UOY6TB.js +136 -0
- package/dist/chunk-KFOHKTFD.js +61 -0
- package/dist/chunk-L4HSIKTU.cjs +135 -0
- package/dist/chunk-LH7ZB4BK.js +124 -0
- package/dist/chunk-LL4ZWLGO.js +90 -0
- package/dist/chunk-M6MTP3NY.cjs +99 -0
- package/dist/chunk-MHJFYYGV.js +215 -0
- package/dist/chunk-MINMXGW3.js +135 -0
- package/dist/chunk-MM7IL2RG.js +181 -0
- package/dist/chunk-OPQJWHXN.cjs +301 -0
- package/dist/chunk-ORFHDJII.cjs +136 -0
- package/dist/chunk-ORVV4MCF.cjs +87 -0
- package/dist/chunk-QICQ6YEY.js +75 -0
- package/dist/chunk-RKUQREMW.js +127 -0
- package/dist/chunk-RO47DKQG.js +146 -0
- package/dist/chunk-RRPXIRTQ.cjs +257 -0
- package/dist/chunk-RYFG2GKM.cjs +118 -0
- package/dist/chunk-STNHTRG7.cjs +124 -0
- package/dist/chunk-TFGS34VD.cjs +71 -0
- package/dist/chunk-TQXDUMML.cjs +61 -0
- package/dist/chunk-UBK3VCVH.cjs +134 -0
- package/dist/chunk-UCOXAZJF.cjs +2606 -0
- package/dist/chunk-UQZKFAFX.js +130 -0
- package/dist/chunk-VB2KV2ZM.cjs +130 -0
- package/dist/chunk-WABKPFPK.js +151 -0
- package/dist/chunk-WDI4QJMQ.js +177 -0
- package/dist/chunk-YDH3L27K.cjs +127 -0
- package/dist/chunk-YIM3D2AD.js +99 -0
- package/dist/chunk-YPSEIDUR.cjs +160 -0
- package/dist/chunk-ZNJLWJX3.cjs +75 -0
- package/dist/chunk-ZTFCJCPO.cjs +161 -0
- package/dist/chunk-ZXUMK2RR.js +301 -0
- package/dist/common/boolean.cjs +7 -0
- package/dist/common/boolean.d.cts +119 -0
- package/dist/common/boolean.d.ts +119 -0
- package/dist/common/boolean.js +7 -0
- package/dist/common/color.cjs +9 -0
- package/dist/common/color.d.cts +26 -0
- package/dist/common/color.d.ts +26 -0
- package/dist/common/color.js +9 -0
- package/dist/common/coordinate.cjs +11 -0
- package/dist/common/coordinate.d.cts +23 -0
- package/dist/common/coordinate.d.ts +23 -0
- package/dist/common/coordinate.js +11 -0
- package/dist/common/credit-card.cjs +11 -0
- package/dist/common/credit-card.d.cts +22 -0
- package/dist/common/credit-card.d.ts +22 -0
- package/dist/common/credit-card.js +11 -0
- package/dist/common/date.cjs +7 -0
- package/dist/common/date.d.cts +174 -0
- package/dist/common/date.d.ts +174 -0
- package/dist/common/date.js +7 -0
- package/dist/common/datetime.cjs +15 -0
- package/dist/common/datetime.d.cts +301 -0
- package/dist/common/datetime.d.ts +301 -0
- package/dist/common/datetime.js +15 -0
- package/dist/common/email.cjs +7 -0
- package/dist/common/email.d.cts +149 -0
- package/dist/common/email.d.ts +149 -0
- package/dist/common/email.js +7 -0
- package/dist/common/file.cjs +7 -0
- package/dist/common/file.d.cts +178 -0
- package/dist/common/file.d.ts +178 -0
- package/dist/common/file.js +7 -0
- package/dist/common/id.cjs +13 -0
- package/dist/common/id.d.cts +288 -0
- package/dist/common/id.d.ts +288 -0
- package/dist/common/id.js +13 -0
- package/dist/common/ip.cjs +11 -0
- package/dist/common/ip.d.cts +25 -0
- package/dist/common/ip.d.ts +25 -0
- package/dist/common/ip.js +11 -0
- package/dist/common/number.cjs +7 -0
- package/dist/common/number.d.cts +167 -0
- package/dist/common/number.d.ts +167 -0
- package/dist/common/number.js +7 -0
- package/dist/common/password.cjs +7 -0
- package/dist/common/password.d.cts +192 -0
- package/dist/common/password.d.ts +192 -0
- package/dist/common/password.js +7 -0
- package/dist/common/text.cjs +7 -0
- package/dist/common/text.d.cts +156 -0
- package/dist/common/text.d.ts +156 -0
- package/dist/common/text.js +7 -0
- package/dist/common/time.cjs +15 -0
- package/dist/common/time.d.cts +268 -0
- package/dist/common/time.d.ts +268 -0
- package/dist/common/time.js +15 -0
- package/dist/common/url.cjs +7 -0
- package/dist/common/url.d.cts +196 -0
- package/dist/common/url.d.ts +196 -0
- package/dist/common/url.js +7 -0
- package/dist/config-CABSSvAp.d.cts +5 -0
- package/dist/config-CABSSvAp.d.ts +5 -0
- package/dist/index.cjs +180 -5255
- package/dist/index.d.cts +28 -3150
- package/dist/index.d.ts +28 -3150
- package/dist/index.js +135 -5131
- package/dist/taiwan/bank-account.cjs +11 -0
- package/dist/taiwan/bank-account.d.cts +22 -0
- package/dist/taiwan/bank-account.d.ts +22 -0
- package/dist/taiwan/bank-account.js +11 -0
- package/dist/taiwan/business-id.cjs +9 -0
- package/dist/taiwan/business-id.d.cts +133 -0
- package/dist/taiwan/business-id.d.ts +133 -0
- package/dist/taiwan/business-id.js +9 -0
- package/dist/taiwan/fax.cjs +9 -0
- package/dist/taiwan/fax.d.cts +157 -0
- package/dist/taiwan/fax.d.ts +157 -0
- package/dist/taiwan/fax.js +9 -0
- package/dist/taiwan/invoice.cjs +9 -0
- package/dist/taiwan/invoice.d.cts +17 -0
- package/dist/taiwan/invoice.d.ts +17 -0
- package/dist/taiwan/invoice.js +9 -0
- package/dist/taiwan/license-plate.cjs +9 -0
- package/dist/taiwan/license-plate.d.cts +19 -0
- package/dist/taiwan/license-plate.d.ts +19 -0
- package/dist/taiwan/license-plate.js +9 -0
- package/dist/taiwan/mobile.cjs +9 -0
- package/dist/taiwan/mobile.d.cts +146 -0
- package/dist/taiwan/mobile.d.ts +146 -0
- package/dist/taiwan/mobile.js +9 -0
- package/dist/taiwan/national-id.cjs +15 -0
- package/dist/taiwan/national-id.d.cts +214 -0
- package/dist/taiwan/national-id.d.ts +214 -0
- package/dist/taiwan/national-id.js +15 -0
- package/dist/taiwan/passport.cjs +9 -0
- package/dist/taiwan/passport.d.cts +19 -0
- package/dist/taiwan/passport.d.ts +19 -0
- package/dist/taiwan/passport.js +9 -0
- package/dist/taiwan/postal-code.cjs +17 -0
- package/dist/taiwan/postal-code.d.cts +237 -0
- package/dist/taiwan/postal-code.d.ts +237 -0
- package/dist/taiwan/postal-code.js +17 -0
- package/dist/taiwan/tel.cjs +9 -0
- package/dist/taiwan/tel.d.cts +162 -0
- package/dist/taiwan/tel.d.ts +162 -0
- package/dist/taiwan/tel.js +9 -0
- package/package.json +132 -6
- package/src/i18n/locales/en-GB.json +51 -0
- package/src/i18n/locales/en-US.json +52 -1
- package/src/i18n/locales/id-ID.json +51 -0
- package/src/i18n/locales/ja-JP.json +51 -0
- package/src/i18n/locales/ko-KR.json +51 -0
- package/src/i18n/locales/ms-MY.json +51 -0
- package/src/i18n/locales/th-TH.json +51 -0
- package/src/i18n/locales/vi-VN.json +51 -0
- package/src/i18n/locales/zh-CN.json +51 -0
- package/src/i18n/locales/zh-TW.json +51 -0
- package/src/index.ts +10 -2
- package/src/validators/common/color.ts +192 -0
- package/src/validators/common/coordinate.ts +159 -0
- package/src/validators/common/credit-card.ts +134 -0
- package/src/validators/common/id.ts +45 -3
- package/src/validators/common/ip.ts +210 -0
- package/src/validators/taiwan/bank-account.ts +176 -0
- package/src/validators/taiwan/invoice.ts +84 -0
- package/src/validators/taiwan/license-plate.ts +110 -0
- package/src/validators/taiwan/passport.ts +103 -0
- package/tests/common/color.test.ts +587 -0
- package/tests/common/coordinate.test.ts +345 -0
- package/tests/common/credit-card.test.ts +378 -0
- package/tests/common/id.test.ts +68 -3
- package/tests/common/ip.test.ts +419 -0
- package/tests/taiwan/bank-account.test.ts +286 -0
- package/tests/taiwan/invoice.test.ts +227 -0
- package/tests/taiwan/license-plate.test.ts +280 -0
- package/tests/taiwan/passport.test.ts +277 -0
- package/tsup.config.ts +36 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Password validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive password validation with strength analysis, character requirements,
|
|
8
|
+
* security checks, and protection against common weak passwords.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for password validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface PasswordMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [min] - Message when password is too short
|
|
20
|
+
* @property {string} [max] - Message when password is too long
|
|
21
|
+
* @property {string} [uppercase] - Message when uppercase letters are required
|
|
22
|
+
* @property {string} [lowercase] - Message when lowercase letters are required
|
|
23
|
+
* @property {string} [digits] - Message when digits are required
|
|
24
|
+
* @property {string} [special] - Message when special characters are required
|
|
25
|
+
* @property {string} [noRepeating] - Message when repeating characters are forbidden
|
|
26
|
+
* @property {string} [noSequential] - Message when sequential characters are forbidden
|
|
27
|
+
* @property {string} [noCommonWords] - Message when common passwords are forbidden
|
|
28
|
+
* @property {string} [minStrength] - Message when password strength is insufficient
|
|
29
|
+
* @property {string} [excludes] - Message when password contains forbidden strings
|
|
30
|
+
* @property {string} [includes] - Message when password doesn't contain required string
|
|
31
|
+
* @property {string} [invalid] - Message when password doesn't match custom regex
|
|
32
|
+
*/
|
|
33
|
+
type PasswordMessages = {
|
|
34
|
+
required?: string;
|
|
35
|
+
min?: string;
|
|
36
|
+
max?: string;
|
|
37
|
+
uppercase?: string;
|
|
38
|
+
lowercase?: string;
|
|
39
|
+
digits?: string;
|
|
40
|
+
special?: string;
|
|
41
|
+
noRepeating?: string;
|
|
42
|
+
noSequential?: string;
|
|
43
|
+
noCommonWords?: string;
|
|
44
|
+
minStrength?: string;
|
|
45
|
+
excludes?: string;
|
|
46
|
+
includes?: string;
|
|
47
|
+
invalid?: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Password strength levels used for validation
|
|
51
|
+
*
|
|
52
|
+
* @typedef {"weak" | "medium" | "strong" | "very-strong"} PasswordStrength
|
|
53
|
+
* @description
|
|
54
|
+
* - weak: Basic passwords with minimal requirements
|
|
55
|
+
* - medium: Passwords with some character variety
|
|
56
|
+
* - strong: Passwords with good character variety and length
|
|
57
|
+
* - very-strong: Passwords with excellent character variety, length, and complexity
|
|
58
|
+
*/
|
|
59
|
+
type PasswordStrength = "weak" | "medium" | "strong" | "very-strong";
|
|
60
|
+
/**
|
|
61
|
+
* Configuration options for password validation
|
|
62
|
+
*
|
|
63
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
64
|
+
*
|
|
65
|
+
* @interface PasswordOptions
|
|
66
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
67
|
+
* @property {number} [min] - Minimum length of password
|
|
68
|
+
* @property {number} [max] - Maximum length of password
|
|
69
|
+
* @property {boolean} [uppercase] - Whether uppercase letters are required
|
|
70
|
+
* @property {boolean} [lowercase] - Whether lowercase letters are required
|
|
71
|
+
* @property {boolean} [digits] - Whether digits are required
|
|
72
|
+
* @property {boolean} [special] - Whether special characters are required
|
|
73
|
+
* @property {boolean} [noRepeating] - Whether to forbid repeating characters (3+ in a row)
|
|
74
|
+
* @property {boolean} [noSequential] - Whether to forbid sequential characters (abc, 123)
|
|
75
|
+
* @property {boolean} [noCommonWords] - Whether to forbid common weak passwords
|
|
76
|
+
* @property {PasswordStrength} [minStrength] - Minimum required password strength
|
|
77
|
+
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
78
|
+
* @property {string} [includes] - String that must be included in password
|
|
79
|
+
* @property {RegExp} [regex] - Custom regex pattern for validation
|
|
80
|
+
* @property {Function} [transform] - Custom transformation function for password
|
|
81
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
82
|
+
* @property {Record<Locale, PasswordMessages>} [i18n] - Custom error messages for different locales
|
|
83
|
+
*/
|
|
84
|
+
type PasswordOptions<IsRequired extends boolean = true> = {
|
|
85
|
+
min?: number;
|
|
86
|
+
max?: number;
|
|
87
|
+
uppercase?: boolean;
|
|
88
|
+
lowercase?: boolean;
|
|
89
|
+
digits?: boolean;
|
|
90
|
+
special?: boolean;
|
|
91
|
+
noRepeating?: boolean;
|
|
92
|
+
noSequential?: boolean;
|
|
93
|
+
noCommonWords?: boolean;
|
|
94
|
+
minStrength?: PasswordStrength;
|
|
95
|
+
excludes?: string | string[];
|
|
96
|
+
includes?: string;
|
|
97
|
+
regex?: RegExp;
|
|
98
|
+
transform?: (value: string) => string;
|
|
99
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
100
|
+
i18n?: Partial<Record<Locale, Partial<PasswordMessages>>>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Type alias for password validation schema based on required flag
|
|
104
|
+
*
|
|
105
|
+
* @template IsRequired - Whether the field is required
|
|
106
|
+
* @typedef PasswordSchema
|
|
107
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
108
|
+
*/
|
|
109
|
+
type PasswordSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
110
|
+
/**
|
|
111
|
+
* Creates a Zod schema for password validation with comprehensive security checks
|
|
112
|
+
*
|
|
113
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
114
|
+
* @param {IsRequired} [required=false] - Whether the field is required
|
|
115
|
+
* @param {Omit<ValidatorOptions<IsRequired>, 'required'>} [options] - Configuration options for validation
|
|
116
|
+
* @returns {PasswordSchema<IsRequired>} Zod schema for password validation
|
|
117
|
+
*
|
|
118
|
+
* @description
|
|
119
|
+
* Creates a comprehensive password validator with strength analysis, character requirements,
|
|
120
|
+
* security checks, and protection against common weak passwords.
|
|
121
|
+
*
|
|
122
|
+
* Features:
|
|
123
|
+
* - Length validation (min/max)
|
|
124
|
+
* - Character requirements (uppercase, lowercase, digits, special)
|
|
125
|
+
* - Security checks (no repeating, no sequential patterns)
|
|
126
|
+
* - Common password detection
|
|
127
|
+
* - Strength analysis with configurable minimum levels
|
|
128
|
+
* - Content inclusion/exclusion
|
|
129
|
+
* - Custom regex patterns
|
|
130
|
+
* - Custom transformation functions
|
|
131
|
+
* - Comprehensive internationalization
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Basic password validation
|
|
136
|
+
* const basicSchema = password() // optional by default
|
|
137
|
+
* basicSchema.parse("MyPassword123!") // ✓ Valid
|
|
138
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
139
|
+
*
|
|
140
|
+
* // Required validation
|
|
141
|
+
* const requiredSchema = parse("MyPassword123!") // ✓ Valid
|
|
142
|
+
(true)
|
|
143
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
144
|
+
*
|
|
145
|
+
*
|
|
146
|
+
* // Strong password requirements
|
|
147
|
+
* const strongSchema = password(false, {
|
|
148
|
+
* min: 12,
|
|
149
|
+
* uppercase: true,
|
|
150
|
+
* lowercase: true,
|
|
151
|
+
* digits: true,
|
|
152
|
+
* special: true,
|
|
153
|
+
* minStrength: "strong"
|
|
154
|
+
* })
|
|
155
|
+
*
|
|
156
|
+
* // No common passwords
|
|
157
|
+
* const secureSchema = password(false, {
|
|
158
|
+
* noCommonWords: true,
|
|
159
|
+
* noRepeating: true,
|
|
160
|
+
* noSequential: true
|
|
161
|
+
* })
|
|
162
|
+
* secureSchema.parse("password123") // ✗ Invalid (common password)
|
|
163
|
+
* secureSchema.parse("aaa123") // ✗ Invalid (repeating characters)
|
|
164
|
+
* secureSchema.parse("abc123") // ✗ Invalid (sequential characters)
|
|
165
|
+
*
|
|
166
|
+
* // Custom requirements
|
|
167
|
+
* const customSchema = password(false, {
|
|
168
|
+
* min: 8,
|
|
169
|
+
* includes: "@", // Must contain @
|
|
170
|
+
* excludes: ["admin", "user"], // Cannot contain these words
|
|
171
|
+
* regex: /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)/ // Custom pattern
|
|
172
|
+
* })
|
|
173
|
+
*
|
|
174
|
+
* // Minimum strength requirement
|
|
175
|
+
* const strengthSchema = password(false, { minStrength: "very-strong" })
|
|
176
|
+
* strengthSchema.parse("weak") // ✗ Invalid (insufficient strength)
|
|
177
|
+
* strengthSchema.parse("MyVeryStr0ng!P@ssw0rd2024") // ✓ Valid
|
|
178
|
+
*
|
|
179
|
+
* // Optional with default
|
|
180
|
+
* const optionalSchema = password(false, {
|
|
181
|
+
* defaultValue: null
|
|
182
|
+
* })
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
186
|
+
* @see {@link PasswordOptions} for all available configuration options
|
|
187
|
+
* @see {@link PasswordStrength} for strength level definitions
|
|
188
|
+
* @see {@link calculatePasswordStrength} for strength calculation logic
|
|
189
|
+
*/
|
|
190
|
+
declare function password<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<PasswordOptions<IsRequired>, 'required'>): PasswordSchema<IsRequired>;
|
|
191
|
+
|
|
192
|
+
export { type PasswordMessages, type PasswordOptions, type PasswordSchema, type PasswordStrength, password };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Text validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive text validation with length constraints, content validation,
|
|
8
|
+
* flexible trimming and casing options, and advanced transformation features.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for text validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface TextMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [notEmpty] - Message when field must not be empty (whitespace-only)
|
|
20
|
+
* @property {string} [minLength] - Message when text is shorter than minimum length
|
|
21
|
+
* @property {string} [maxLength] - Message when text exceeds maximum length
|
|
22
|
+
* @property {string} [startsWith] - Message when text doesn't start with required string
|
|
23
|
+
* @property {string} [endsWith] - Message when text doesn't end with required string
|
|
24
|
+
* @property {string} [includes] - Message when text doesn't contain required string
|
|
25
|
+
* @property {string} [excludes] - Message when text contains forbidden string
|
|
26
|
+
* @property {string} [invalid] - Message when text doesn't match regex pattern
|
|
27
|
+
*/
|
|
28
|
+
type TextMessages = {
|
|
29
|
+
required?: string;
|
|
30
|
+
notEmpty?: string;
|
|
31
|
+
minLength?: string;
|
|
32
|
+
maxLength?: string;
|
|
33
|
+
startsWith?: string;
|
|
34
|
+
endsWith?: string;
|
|
35
|
+
includes?: string;
|
|
36
|
+
excludes?: string;
|
|
37
|
+
invalid?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Configuration options for text validation
|
|
41
|
+
*
|
|
42
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
43
|
+
*
|
|
44
|
+
* @interface TextOptions
|
|
45
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
46
|
+
* @property {number} [minLength] - Minimum length of text
|
|
47
|
+
* @property {number} [maxLength] - Maximum length of text
|
|
48
|
+
* @property {string} [startsWith] - String that text must start with
|
|
49
|
+
* @property {string} [endsWith] - String that text must end with
|
|
50
|
+
* @property {string} [includes] - String that must be included in text
|
|
51
|
+
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
52
|
+
* @property {RegExp} [regex] - Regular expression pattern for validation
|
|
53
|
+
* @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
|
|
54
|
+
* @property {"upper" | "lower" | "title" | "none"} [casing="none"] - Case transformation
|
|
55
|
+
* @property {Function} [transform] - Custom transformation function for text
|
|
56
|
+
* @property {boolean} [notEmpty] - Whether to reject whitespace-only strings
|
|
57
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
58
|
+
* @property {Record<Locale, TextMessages>} [i18n] - Custom error messages for different locales
|
|
59
|
+
*/
|
|
60
|
+
type TextOptions<IsRequired extends boolean = true> = {
|
|
61
|
+
minLength?: number;
|
|
62
|
+
maxLength?: number;
|
|
63
|
+
startsWith?: string;
|
|
64
|
+
endsWith?: string;
|
|
65
|
+
includes?: string;
|
|
66
|
+
excludes?: string | string[];
|
|
67
|
+
regex?: RegExp;
|
|
68
|
+
trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
|
|
69
|
+
casing?: "upper" | "lower" | "title" | "none";
|
|
70
|
+
transform?: (value: string) => string;
|
|
71
|
+
notEmpty?: boolean;
|
|
72
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
73
|
+
i18n?: Partial<Record<Locale, Partial<TextMessages>>>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Type alias for text validation schema based on required flag
|
|
77
|
+
*
|
|
78
|
+
* @template IsRequired - Whether the field is required
|
|
79
|
+
* @typedef TextSchema
|
|
80
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
81
|
+
*/
|
|
82
|
+
type TextSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Zod schema for text validation with comprehensive string processing
|
|
85
|
+
*
|
|
86
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
87
|
+
* @param {TextOptions<IsRequired>} [options] - Configuration options for text validation
|
|
88
|
+
* @returns {TextSchema<IsRequired>} Zod schema for text validation
|
|
89
|
+
*
|
|
90
|
+
* @description
|
|
91
|
+
* Creates a comprehensive text validator with length constraints, content validation,
|
|
92
|
+
* flexible trimming and casing options, and advanced transformation features.
|
|
93
|
+
*
|
|
94
|
+
* Features:
|
|
95
|
+
* - Length validation (min/max)
|
|
96
|
+
* - Content validation (startsWith, endsWith, includes, excludes)
|
|
97
|
+
* - Regular expression pattern matching
|
|
98
|
+
* - Flexible trimming options (trim, trimStart, trimEnd, none)
|
|
99
|
+
* - Case transformation (upper, lower, title, none)
|
|
100
|
+
* - Empty string vs whitespace-only validation
|
|
101
|
+
* - Custom transformation functions
|
|
102
|
+
* - Comprehensive internationalization
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // Basic text validation (optional by default)
|
|
107
|
+
* const basicSchema = text()
|
|
108
|
+
* basicSchema.parse("Hello World") // ✓ Valid
|
|
109
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
110
|
+
*
|
|
111
|
+
* // Required text
|
|
112
|
+
* const requiredSchema = text(true)
|
|
113
|
+
* requiredSchema.parse("Hello") // ✓ Valid
|
|
114
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
115
|
+
*
|
|
116
|
+
* // Length constraints
|
|
117
|
+
* const lengthSchema = text(true, { minLength: 3, maxLength: 50 })
|
|
118
|
+
* lengthSchema.parse("Hello") // ✓ Valid
|
|
119
|
+
* lengthSchema.parse("Hi") // ✗ Invalid (too short)
|
|
120
|
+
*
|
|
121
|
+
* // Content validation
|
|
122
|
+
* const contentSchema = text(true, {
|
|
123
|
+
* startsWith: "Hello",
|
|
124
|
+
* endsWith: "!",
|
|
125
|
+
* includes: "World"
|
|
126
|
+
* })
|
|
127
|
+
* contentSchema.parse("Hello World!") // ✓ Valid
|
|
128
|
+
*
|
|
129
|
+
* // Case transformation
|
|
130
|
+
* const upperSchema = text(false, { casing: "upper" })
|
|
131
|
+
* upperSchema.parse("hello") // ✓ Valid (converted to "HELLO")
|
|
132
|
+
*
|
|
133
|
+
* // Trim modes
|
|
134
|
+
* const trimStartSchema = text(false, { trimMode: "trimStart" })
|
|
135
|
+
* trimStartSchema.parse(" hello ") // ✓ Valid (result: "hello ")
|
|
136
|
+
*
|
|
137
|
+
* // Regex validation
|
|
138
|
+
* const regexSchema = text(true, { regex: /^[a-zA-Z]+$/ })
|
|
139
|
+
* regexSchema.parse("hello") // ✓ Valid
|
|
140
|
+
* regexSchema.parse("hello123") // ✗ Invalid
|
|
141
|
+
*
|
|
142
|
+
* // Not empty (rejects whitespace-only)
|
|
143
|
+
* const notEmptySchema = text(true, { notEmpty: true })
|
|
144
|
+
* notEmptySchema.parse("hello") // ✓ Valid
|
|
145
|
+
* notEmptySchema.parse(" ") // ✗ Invalid
|
|
146
|
+
*
|
|
147
|
+
* // Optional with default
|
|
148
|
+
* const optionalSchema = text(false, { defaultValue: "default text" })
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
152
|
+
* @see {@link TextOptions} for all available configuration options
|
|
153
|
+
*/
|
|
154
|
+
declare function text<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TextOptions<IsRequired>, 'required'>): TextSchema<IsRequired>;
|
|
155
|
+
|
|
156
|
+
export { type TextMessages, type TextOptions, type TextSchema, text };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ZodString, ZodNullable } from 'zod';
|
|
2
|
+
import { L as Locale } from '../config-CABSSvAp.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Text validator for Zod Kit
|
|
6
|
+
*
|
|
7
|
+
* Provides comprehensive text validation with length constraints, content validation,
|
|
8
|
+
* flexible trimming and casing options, and advanced transformation features.
|
|
9
|
+
*
|
|
10
|
+
* @author Ong Hoe Yuan
|
|
11
|
+
* @version 0.0.5
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Type definition for text validation error messages
|
|
16
|
+
*
|
|
17
|
+
* @interface TextMessages
|
|
18
|
+
* @property {string} [required] - Message when field is required but empty
|
|
19
|
+
* @property {string} [notEmpty] - Message when field must not be empty (whitespace-only)
|
|
20
|
+
* @property {string} [minLength] - Message when text is shorter than minimum length
|
|
21
|
+
* @property {string} [maxLength] - Message when text exceeds maximum length
|
|
22
|
+
* @property {string} [startsWith] - Message when text doesn't start with required string
|
|
23
|
+
* @property {string} [endsWith] - Message when text doesn't end with required string
|
|
24
|
+
* @property {string} [includes] - Message when text doesn't contain required string
|
|
25
|
+
* @property {string} [excludes] - Message when text contains forbidden string
|
|
26
|
+
* @property {string} [invalid] - Message when text doesn't match regex pattern
|
|
27
|
+
*/
|
|
28
|
+
type TextMessages = {
|
|
29
|
+
required?: string;
|
|
30
|
+
notEmpty?: string;
|
|
31
|
+
minLength?: string;
|
|
32
|
+
maxLength?: string;
|
|
33
|
+
startsWith?: string;
|
|
34
|
+
endsWith?: string;
|
|
35
|
+
includes?: string;
|
|
36
|
+
excludes?: string;
|
|
37
|
+
invalid?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Configuration options for text validation
|
|
41
|
+
*
|
|
42
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
43
|
+
*
|
|
44
|
+
* @interface TextOptions
|
|
45
|
+
* @property {IsRequired} [required=true] - Whether the field is required
|
|
46
|
+
* @property {number} [minLength] - Minimum length of text
|
|
47
|
+
* @property {number} [maxLength] - Maximum length of text
|
|
48
|
+
* @property {string} [startsWith] - String that text must start with
|
|
49
|
+
* @property {string} [endsWith] - String that text must end with
|
|
50
|
+
* @property {string} [includes] - String that must be included in text
|
|
51
|
+
* @property {string | string[]} [excludes] - String(s) that must not be included
|
|
52
|
+
* @property {RegExp} [regex] - Regular expression pattern for validation
|
|
53
|
+
* @property {"trim" | "trimStart" | "trimEnd" | "none"} [trimMode="trim"] - Whitespace handling
|
|
54
|
+
* @property {"upper" | "lower" | "title" | "none"} [casing="none"] - Case transformation
|
|
55
|
+
* @property {Function} [transform] - Custom transformation function for text
|
|
56
|
+
* @property {boolean} [notEmpty] - Whether to reject whitespace-only strings
|
|
57
|
+
* @property {string | null} [defaultValue] - Default value when input is empty
|
|
58
|
+
* @property {Record<Locale, TextMessages>} [i18n] - Custom error messages for different locales
|
|
59
|
+
*/
|
|
60
|
+
type TextOptions<IsRequired extends boolean = true> = {
|
|
61
|
+
minLength?: number;
|
|
62
|
+
maxLength?: number;
|
|
63
|
+
startsWith?: string;
|
|
64
|
+
endsWith?: string;
|
|
65
|
+
includes?: string;
|
|
66
|
+
excludes?: string | string[];
|
|
67
|
+
regex?: RegExp;
|
|
68
|
+
trimMode?: "trim" | "trimStart" | "trimEnd" | "none";
|
|
69
|
+
casing?: "upper" | "lower" | "title" | "none";
|
|
70
|
+
transform?: (value: string) => string;
|
|
71
|
+
notEmpty?: boolean;
|
|
72
|
+
defaultValue?: IsRequired extends true ? string : string | null;
|
|
73
|
+
i18n?: Partial<Record<Locale, Partial<TextMessages>>>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Type alias for text validation schema based on required flag
|
|
77
|
+
*
|
|
78
|
+
* @template IsRequired - Whether the field is required
|
|
79
|
+
* @typedef TextSchema
|
|
80
|
+
* @description Returns ZodString if required, ZodNullable<ZodString> if optional
|
|
81
|
+
*/
|
|
82
|
+
type TextSchema<IsRequired extends boolean> = IsRequired extends true ? ZodString : ZodNullable<ZodString>;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Zod schema for text validation with comprehensive string processing
|
|
85
|
+
*
|
|
86
|
+
* @template IsRequired - Whether the field is required (affects return type)
|
|
87
|
+
* @param {TextOptions<IsRequired>} [options] - Configuration options for text validation
|
|
88
|
+
* @returns {TextSchema<IsRequired>} Zod schema for text validation
|
|
89
|
+
*
|
|
90
|
+
* @description
|
|
91
|
+
* Creates a comprehensive text validator with length constraints, content validation,
|
|
92
|
+
* flexible trimming and casing options, and advanced transformation features.
|
|
93
|
+
*
|
|
94
|
+
* Features:
|
|
95
|
+
* - Length validation (min/max)
|
|
96
|
+
* - Content validation (startsWith, endsWith, includes, excludes)
|
|
97
|
+
* - Regular expression pattern matching
|
|
98
|
+
* - Flexible trimming options (trim, trimStart, trimEnd, none)
|
|
99
|
+
* - Case transformation (upper, lower, title, none)
|
|
100
|
+
* - Empty string vs whitespace-only validation
|
|
101
|
+
* - Custom transformation functions
|
|
102
|
+
* - Comprehensive internationalization
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // Basic text validation (optional by default)
|
|
107
|
+
* const basicSchema = text()
|
|
108
|
+
* basicSchema.parse("Hello World") // ✓ Valid
|
|
109
|
+
* basicSchema.parse(null) // ✓ Valid (optional)
|
|
110
|
+
*
|
|
111
|
+
* // Required text
|
|
112
|
+
* const requiredSchema = text(true)
|
|
113
|
+
* requiredSchema.parse("Hello") // ✓ Valid
|
|
114
|
+
* requiredSchema.parse(null) // ✗ Invalid (required)
|
|
115
|
+
*
|
|
116
|
+
* // Length constraints
|
|
117
|
+
* const lengthSchema = text(true, { minLength: 3, maxLength: 50 })
|
|
118
|
+
* lengthSchema.parse("Hello") // ✓ Valid
|
|
119
|
+
* lengthSchema.parse("Hi") // ✗ Invalid (too short)
|
|
120
|
+
*
|
|
121
|
+
* // Content validation
|
|
122
|
+
* const contentSchema = text(true, {
|
|
123
|
+
* startsWith: "Hello",
|
|
124
|
+
* endsWith: "!",
|
|
125
|
+
* includes: "World"
|
|
126
|
+
* })
|
|
127
|
+
* contentSchema.parse("Hello World!") // ✓ Valid
|
|
128
|
+
*
|
|
129
|
+
* // Case transformation
|
|
130
|
+
* const upperSchema = text(false, { casing: "upper" })
|
|
131
|
+
* upperSchema.parse("hello") // ✓ Valid (converted to "HELLO")
|
|
132
|
+
*
|
|
133
|
+
* // Trim modes
|
|
134
|
+
* const trimStartSchema = text(false, { trimMode: "trimStart" })
|
|
135
|
+
* trimStartSchema.parse(" hello ") // ✓ Valid (result: "hello ")
|
|
136
|
+
*
|
|
137
|
+
* // Regex validation
|
|
138
|
+
* const regexSchema = text(true, { regex: /^[a-zA-Z]+$/ })
|
|
139
|
+
* regexSchema.parse("hello") // ✓ Valid
|
|
140
|
+
* regexSchema.parse("hello123") // ✗ Invalid
|
|
141
|
+
*
|
|
142
|
+
* // Not empty (rejects whitespace-only)
|
|
143
|
+
* const notEmptySchema = text(true, { notEmpty: true })
|
|
144
|
+
* notEmptySchema.parse("hello") // ✓ Valid
|
|
145
|
+
* notEmptySchema.parse(" ") // ✗ Invalid
|
|
146
|
+
*
|
|
147
|
+
* // Optional with default
|
|
148
|
+
* const optionalSchema = text(false, { defaultValue: "default text" })
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @throws {z.ZodError} When validation fails with specific error messages
|
|
152
|
+
* @see {@link TextOptions} for all available configuration options
|
|
153
|
+
*/
|
|
154
|
+
declare function text<IsRequired extends boolean = false>(required?: IsRequired, options?: Omit<TextOptions<IsRequired>, 'required'>): TextSchema<IsRequired>;
|
|
155
|
+
|
|
156
|
+
export { type TextMessages, type TextOptions, type TextSchema, text };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkRRPXIRTQcjs = require('../chunk-RRPXIRTQ.cjs');
|
|
8
|
+
require('../chunk-UCOXAZJF.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.TIME_PATTERNS = _chunkRRPXIRTQcjs.TIME_PATTERNS; exports.normalizeTime = _chunkRRPXIRTQcjs.normalizeTime; exports.parseTimeToMinutes = _chunkRRPXIRTQcjs.parseTimeToMinutes; exports.time = _chunkRRPXIRTQcjs.time; exports.validateTimeFormat = _chunkRRPXIRTQcjs.validateTimeFormat;
|