reslib 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.
Files changed (200) hide show
  1. package/README.md +298 -0
  2. package/build/auth/index.d.ts +2034 -0
  3. package/build/auth/index.js +5 -0
  4. package/build/auth/types.d.ts +465 -0
  5. package/build/auth/types.js +1 -0
  6. package/build/countries/countries.d.ts +1454 -0
  7. package/build/countries/countries.js +1 -0
  8. package/build/countries/index.d.ts +159 -0
  9. package/build/countries/index.js +5 -0
  10. package/build/countries/types.d.ts +65 -0
  11. package/build/countries/types.js +1 -0
  12. package/build/currency/currencies.d.ts +8 -0
  13. package/build/currency/currencies.js +1 -0
  14. package/build/currency/index.d.ts +51 -0
  15. package/build/currency/index.js +5 -0
  16. package/build/currency/session.d.ts +23 -0
  17. package/build/currency/session.js +5 -0
  18. package/build/currency/types.d.ts +1039 -0
  19. package/build/currency/types.js +1 -0
  20. package/build/currency/utils.d.ts +25 -0
  21. package/build/currency/utils.js +1 -0
  22. package/build/i18n/index.d.ts +640 -0
  23. package/build/i18n/index.js +5 -0
  24. package/build/inputFormatter/index.d.ts +396 -0
  25. package/build/inputFormatter/index.js +5 -0
  26. package/build/inputFormatter/types.d.ts +544 -0
  27. package/build/inputFormatter/types.js +1 -0
  28. package/build/logger/index.d.ts +235 -0
  29. package/build/logger/index.js +5 -0
  30. package/build/observable/index.d.ts +329 -0
  31. package/build/observable/index.js +1 -0
  32. package/build/platform/index.d.ts +32 -0
  33. package/build/platform/index.js +1 -0
  34. package/build/resources/ResourcePaginationHelper.d.ts +537 -0
  35. package/build/resources/ResourcePaginationHelper.js +2 -0
  36. package/build/resources/decorators/create.decorator.d.ts +20 -0
  37. package/build/resources/decorators/create.decorator.js +1 -0
  38. package/build/resources/decorators/index.d.ts +41 -0
  39. package/build/resources/decorators/index.js +1 -0
  40. package/build/resources/fields/index.d.ts +33 -0
  41. package/build/resources/fields/index.js +1 -0
  42. package/build/resources/filters.d.ts +62 -0
  43. package/build/resources/filters.js +1 -0
  44. package/build/resources/index.d.ts +854 -0
  45. package/build/resources/index.js +6 -0
  46. package/build/resources/types/filters.d.ts +508 -0
  47. package/build/resources/types/filters.js +1 -0
  48. package/build/resources/types/index.d.ts +4138 -0
  49. package/build/resources/types/index.js +1 -0
  50. package/build/session/index.d.ts +1474 -0
  51. package/build/session/index.js +1 -0
  52. package/build/translations/auth.en.d.ts +3 -0
  53. package/build/translations/auth.en.js +1 -0
  54. package/build/translations/countries.en.d.ts +6 -0
  55. package/build/translations/countries.en.js +1 -0
  56. package/build/translations/currencies.en.d.ts +5 -0
  57. package/build/translations/currencies.en.js +1 -0
  58. package/build/translations/date.en.d.ts +19 -0
  59. package/build/translations/date.en.js +1 -0
  60. package/build/translations/index.d.ts +1583 -0
  61. package/build/translations/index.js +5 -0
  62. package/build/translations/resources.en.d.ts +6 -0
  63. package/build/translations/resources.en.js +1 -0
  64. package/build/translations/validator.en.d.ts +104 -0
  65. package/build/translations/validator.en.js +5 -0
  66. package/build/types/date.d.ts +44 -0
  67. package/build/types/date.js +1 -0
  68. package/build/types/dictionary.d.ts +29 -0
  69. package/build/types/dictionary.js +1 -0
  70. package/build/types/i18n.d.ts +121 -0
  71. package/build/types/i18n.js +1 -0
  72. package/build/types/index.d.ts +145 -0
  73. package/build/types/index.js +1 -0
  74. package/build/utils/areEquals.d.ts +19 -0
  75. package/build/utils/areEquals.js +1 -0
  76. package/build/utils/date/dateHelper.d.ts +371 -0
  77. package/build/utils/date/dateHelper.js +5 -0
  78. package/build/utils/date/index.d.ts +212 -0
  79. package/build/utils/date/index.js +5 -0
  80. package/build/utils/date/isDateObj.d.ts +14 -0
  81. package/build/utils/date/isDateObj.js +1 -0
  82. package/build/utils/debounce.d.ts +52 -0
  83. package/build/utils/debounce.js +1 -0
  84. package/build/utils/defaultArray.d.ts +18 -0
  85. package/build/utils/defaultArray.js +1 -0
  86. package/build/utils/defaultBool.d.ts +14 -0
  87. package/build/utils/defaultBool.js +1 -0
  88. package/build/utils/defaultStr.d.ts +17 -0
  89. package/build/utils/defaultStr.js +1 -0
  90. package/build/utils/defaultVal.d.ts +18 -0
  91. package/build/utils/defaultVal.js +1 -0
  92. package/build/utils/dom/index.d.ts +65 -0
  93. package/build/utils/dom/index.js +1 -0
  94. package/build/utils/dom/isDOMElement.d.ts +11 -0
  95. package/build/utils/dom/isDOMElement.js +1 -0
  96. package/build/utils/file/index.d.ts +26 -0
  97. package/build/utils/file/index.js +1 -0
  98. package/build/utils/global.d.ts +53 -0
  99. package/build/utils/global.js +1 -0
  100. package/build/utils/image.d.ts +56 -0
  101. package/build/utils/image.js +1 -0
  102. package/build/utils/index.d.ts +39 -0
  103. package/build/utils/index.js +6 -0
  104. package/build/utils/interpolate.d.ts +105 -0
  105. package/build/utils/interpolate.js +1 -0
  106. package/build/utils/isEmail.d.ts +57 -0
  107. package/build/utils/isEmail.js +1 -0
  108. package/build/utils/isEmpty.d.ts +18 -0
  109. package/build/utils/isEmpty.js +1 -0
  110. package/build/utils/isNonNullString.d.ts +17 -0
  111. package/build/utils/isNonNullString.js +1 -0
  112. package/build/utils/isNullable.d.ts +7 -0
  113. package/build/utils/isNullable.js +1 -0
  114. package/build/utils/isNumber.d.ts +36 -0
  115. package/build/utils/isNumber.js +1 -0
  116. package/build/utils/isPrimitive.d.ts +16 -0
  117. package/build/utils/isPrimitive.js +1 -0
  118. package/build/utils/isPromise.d.ts +14 -0
  119. package/build/utils/isPromise.js +1 -0
  120. package/build/utils/isRegex.d.ts +15 -0
  121. package/build/utils/isRegex.js +1 -0
  122. package/build/utils/isTime.d.ts +18 -0
  123. package/build/utils/isTime.js +1 -0
  124. package/build/utils/json.d.ts +224 -0
  125. package/build/utils/json.js +1 -0
  126. package/build/utils/numbers.d.ts +148 -0
  127. package/build/utils/numbers.js +5 -0
  128. package/build/utils/object.d.ts +567 -0
  129. package/build/utils/object.js +1 -0
  130. package/build/utils/sort.d.ts +67 -0
  131. package/build/utils/sort.js +1 -0
  132. package/build/utils/string.d.ts +165 -0
  133. package/build/utils/string.js +1 -0
  134. package/build/utils/stringify.d.ts +23 -0
  135. package/build/utils/stringify.js +1 -0
  136. package/build/utils/uniqid.d.ts +18 -0
  137. package/build/utils/uniqid.js +1 -0
  138. package/build/utils/uri/index.d.ts +333 -0
  139. package/build/utils/uri/index.js +2 -0
  140. package/build/validator/index.d.ts +4 -0
  141. package/build/validator/index.js +6 -0
  142. package/build/validator/rules/array.d.ts +848 -0
  143. package/build/validator/rules/array.js +5 -0
  144. package/build/validator/rules/boolean.d.ts +87 -0
  145. package/build/validator/rules/boolean.js +5 -0
  146. package/build/validator/rules/date.d.ts +551 -0
  147. package/build/validator/rules/date.js +5 -0
  148. package/build/validator/rules/default.d.ts +367 -0
  149. package/build/validator/rules/default.js +5 -0
  150. package/build/validator/rules/enum.d.ts +155 -0
  151. package/build/validator/rules/enum.js +5 -0
  152. package/build/validator/rules/file.d.ts +356 -0
  153. package/build/validator/rules/file.js +5 -0
  154. package/build/validator/rules/format.d.ts +2825 -0
  155. package/build/validator/rules/format.js +6 -0
  156. package/build/validator/rules/index.d.ts +16 -0
  157. package/build/validator/rules/index.js +6 -0
  158. package/build/validator/rules/multiRules.d.ts +475 -0
  159. package/build/validator/rules/multiRules.js +5 -0
  160. package/build/validator/rules/numeric.d.ts +1135 -0
  161. package/build/validator/rules/numeric.js +5 -0
  162. package/build/validator/rules/string.d.ts +504 -0
  163. package/build/validator/rules/string.js +5 -0
  164. package/build/validator/rules/target.d.ts +137 -0
  165. package/build/validator/rules/target.js +5 -0
  166. package/build/validator/rules/utils.d.ts +1 -0
  167. package/build/validator/rules/utils.js +1 -0
  168. package/build/validator/rulesMarkers.d.ts +11 -0
  169. package/build/validator/rulesMarkers.js +1 -0
  170. package/build/validator/types.d.ts +2906 -0
  171. package/build/validator/types.js +1 -0
  172. package/build/validator/validator.d.ts +3692 -0
  173. package/build/validator/validator.js +5 -0
  174. package/lib/cjs/auth.js +1 -0
  175. package/lib/cjs/countries.js +1 -0
  176. package/lib/cjs/currency.js +1 -0
  177. package/lib/cjs/i18n.js +1 -0
  178. package/lib/cjs/inputFormatter.js +1 -0
  179. package/lib/cjs/logger.js +1 -0
  180. package/lib/cjs/observable.js +1 -0
  181. package/lib/cjs/platform.js +1 -0
  182. package/lib/cjs/resources.js +1 -0
  183. package/lib/cjs/session.js +1 -0
  184. package/lib/cjs/types.js +1 -0
  185. package/lib/cjs/utils.js +1 -0
  186. package/lib/cjs/validator.js +1 -0
  187. package/lib/esm/auth.mjs +1 -0
  188. package/lib/esm/countries.mjs +1 -0
  189. package/lib/esm/currency.mjs +1 -0
  190. package/lib/esm/i18n.mjs +1 -0
  191. package/lib/esm/inputFormatter.mjs +1 -0
  192. package/lib/esm/logger.mjs +1 -0
  193. package/lib/esm/observable.mjs +1 -0
  194. package/lib/esm/platform.mjs +1 -0
  195. package/lib/esm/resources.mjs +1 -0
  196. package/lib/esm/session.mjs +1 -0
  197. package/lib/esm/types.mjs +1 -0
  198. package/lib/esm/utils.mjs +1 -0
  199. package/lib/esm/validator.mjs +1 -0
  200. package/package.json +244 -0
@@ -0,0 +1,504 @@
1
+ /**
2
+ * @decorator MinLength
3
+ *
4
+ * Validator rule that checks if a given string meets a minimum length requirement.
5
+ * This rule ensures that the input string has at least the specified number of characters.
6
+ *
7
+ * ### Parameters:
8
+ * - **options**: `ValidatorValidateOptions` - An object containing:
9
+ * - `value`: The string value to validate.
10
+ * - `ruleParams`: An array where the first element specifies the minimum length required.
11
+ *
12
+ * ### Return Value:
13
+ * - `ValidatorSyncResult`: Returns `true` if the value is empty or meets the minimum length requirement;
14
+ * otherwise, returns an error message indicating that the minimum length is not met.
15
+ *
16
+ * ### Example Usage:
17
+ * ```typescript
18
+ * class MyClass {
19
+ * @MinLength(3) //"This field must have a minimum of 3 characters"
20
+ * myString: string;
21
+ * }
22
+ * ```
23
+ *
24
+ * ### Notes:
25
+ * - This rule is useful for validating user input in forms, ensuring that the input meets a minimum length requirement.
26
+ * - The error message can be customized based on the parameters provided, allowing for clear feedback to users.
27
+ * - The `isEmpty` utility function is used to check for empty values, which may include `null`, `undefined`, or empty strings.
28
+ */
29
+ export declare const MinLength: (minLength: number) => PropertyDecorator;
30
+ /**
31
+ * @decorator MaxLength
32
+ *
33
+ * Validator rule that checks if a given string does not exceed a maximum length.
34
+ * This rule ensures that the input string has at most the specified number of characters.
35
+ *
36
+ * ### Parameters:
37
+ * - **options**: `ValidatorValidateOptions` - An object containing:
38
+ * - `value`: The string value to validate.
39
+ * - `ruleParams`: An array where the first element specifies the maximum length allowed.
40
+ *
41
+ * ### Return Value:
42
+ * - `ValidatorSyncResult`: Returns `true` if the value is empty or meets the maximum length requirement;
43
+ * otherwise, returns an error message indicating that the maximum length is exceeded.
44
+ *
45
+ * ### Example Usage:
46
+ * ```typescript
47
+ import { MaxLength } from 'reslib';
48
+ class MyClass {
49
+ @MaxLength(10)
50
+ myProperty: string;
51
+ }
52
+ * ```
53
+ *
54
+ * ### Notes:
55
+ * - This rule is useful for validating user input in forms, ensuring that the input does not exceed a specified length.
56
+ * - The error message can be customized based on the parameters provided, allowing for clear feedback to users.
57
+ * - The `isEmpty` utility function is used to check for empty values, which may include `null`, `undefined`, or empty strings.
58
+ */
59
+ export declare const MaxLength: (maxLength: number) => PropertyDecorator;
60
+ /**
61
+ * ### IsNonNullString Decorator
62
+ *
63
+ * Validates that a property value is a non-null, non-empty string. This
64
+ * decorator is stricter than IsRequired as it also ensures the value is
65
+ * a string with actual content (not just whitespace).
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * class Article {
70
+ * @IsNonNullString()
71
+ * title: string;
72
+ *
73
+ * @IsNonNullString()
74
+ * content: string;
75
+ *
76
+ * @IsNonNullString()
77
+ * author: string;
78
+ * }
79
+ *
80
+ * // Valid data
81
+ * const article = {
82
+ * title: "How to Validate Data",
83
+ * content: "This article explains validation...",
84
+ * author: "John Doe"
85
+ * };
86
+ *
87
+ * // Invalid data
88
+ * const invalid = {
89
+ * title: "", // Empty string
90
+ * content: " ", // Only whitespace
91
+ * author: null // Null value
92
+ * };
93
+ * ```
94
+ *
95
+ * @decorator
96
+ *
97
+ * @see {@link IsRequired} - Less strict alternative
98
+ * @public
99
+ */
100
+ export declare const IsNonNullString: () => PropertyDecorator;
101
+ /**
102
+ * @decorator Length
103
+ *
104
+ * Validator rule that validates the length of a string. This rule checks if the length of the input string
105
+ * falls within a specified range or matches a specific length.
106
+ *
107
+ * ### Parameters:
108
+ * - **options**: `ValidatorValidateOptions` - An object containing:
109
+ * - `value`: The string value to validate.
110
+ * - `ruleParams`: An array where:
111
+ * - The first element specifies the minimum length (optional).
112
+ * - The second element specifies the maximum length (optional).
113
+ *
114
+ * ### Return Value:
115
+ * - `ValidatorSyncResult`: Returns `true` if the string length is valid according to the specified rules;
116
+ * otherwise, returns an error message indicating the validation failure.
117
+ *
118
+ * ### Example Usage:
119
+ * ```typescript
120
+ *
121
+ * class MyClass {
122
+ * @Length(3, 10) //"This field must be between 3 and 10 characters long"
123
+ * myString: string;
124
+ * }
125
+ *
126
+ * class MyClass {
127
+ * @Length(4) //"This field must be exactly 4 characters long"
128
+ * myString: string;
129
+ * }
130
+ * ```
131
+ *
132
+ * ### Notes:
133
+ * - This rule is useful for validating user input in forms, ensuring that the input meets specific length requirements.
134
+ * - The error messages can be customized based on the parameters provided, allowing for clear feedback to users.
135
+ * - The `defaultStr` utility function is used to ensure that the value is treated as a string, even if it is `null` or `undefined`.
136
+ */
137
+ export declare const Length: (lengthOrMinLength: number, maxLength?: number | undefined) => PropertyDecorator;
138
+ /**
139
+ * ### EndsWithOneOf Rule
140
+ *
141
+ * Validates that the field under validation ends with one of the given values.
142
+ *
143
+ * #### Parameters
144
+ * - List of values that the field must end with
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * // Class validation
149
+ * class FileUpload {
150
+ * @EndsWithOneOf('jpg', 'png', 'gif', 'webp')
151
+ * imageFile: string;
152
+ *
153
+ * @EndsWithOneOf('.com', '.org', '.net')
154
+ * websiteUrl: string;
155
+ * }
156
+ * ```
157
+ *
158
+ * @param options - Validation options with rule parameters
159
+ * @param options.ruleParams - Array of valid ending values
160
+ * @returns Promise resolving to true if valid, rejecting with error message if invalid
161
+ *
162
+ *
163
+ * @public
164
+ */
165
+ export declare const EndsWithOneOf: (...ruleParameters: (string | number)[]) => PropertyDecorator;
166
+ /**
167
+ * ### StartsWithOneOf Decorator
168
+ *
169
+ * Validates that a string field starts with one of the specified prefixes.
170
+ * This decorator is useful for validating URLs, file paths, identifiers, or any string
171
+ * that must begin with specific patterns.
172
+ *
173
+ * ### Purpose
174
+ * Ensures that the input string begins with at least one of the provided prefix values.
175
+ * Common use cases include:
176
+ * - Validating URLs that must start with 'http://' or 'https://'
177
+ * - Checking file paths that must start with specific directories
178
+ * - Validating identifiers that must have specific prefixes (e.g., 'USER_', 'ADMIN_')
179
+ * - Ensuring configuration values follow naming conventions
180
+ *
181
+ * ### Parameters
182
+ * The decorator accepts a variable number of string prefixes that the field value must start with.
183
+ * At least one prefix must be provided.
184
+ *
185
+ * ### Validation Logic
186
+ * 1. **Type Check**: Ensures the value is a string
187
+ * 2. **Parameter Validation**: Verifies that prefixes are provided
188
+ * 3. **Prefix Matching**: Checks if the value starts with any of the specified prefixes
189
+ * 4. **Result**: Passes if any prefix matches, fails otherwise
190
+ *
191
+ * ### Return Behavior
192
+ * - **Success**: Resolves with `true` if validation passes
193
+ * - **Failure**: Rejects with localized error message if validation fails
194
+ * - **Type Error**: Rejects if value is not a string
195
+ * - **Parameter Error**: Rejects if no prefixes are provided
196
+ *
197
+ * ### Examples
198
+ *
199
+ * #### Basic URL Validation
200
+ * ```typescript
201
+ * class ApiConfig {
202
+ * @StartsWithOneOf('http://', 'https://')
203
+ * baseUrl: string;
204
+ * }
205
+ *
206
+ * // Valid: 'https://api.example.com'
207
+ * // Valid: 'http://localhost:3000'
208
+ * // Invalid: 'ftp://files.example.com'
209
+ * ```
210
+ *
211
+ * #### Identifier Prefix Validation
212
+ * ```typescript
213
+ * class User {
214
+ * @StartsWithOneOf('USER_', 'ADMIN_', 'MOD_')
215
+ * userId: string;
216
+ * }
217
+ *
218
+ * // Valid: 'USER_12345'
219
+ * // Valid: 'ADMIN_67890'
220
+ * // Invalid: 'GUEST_11111'
221
+ * ```
222
+ *
223
+ * #### File Path Validation
224
+ * ```typescript
225
+ * class FileUpload {
226
+ * @StartsWithOneOf('/uploads/', '/temp/', '/cache/')
227
+ * filePath: string;
228
+ * }
229
+ *
230
+ * // Valid: '/uploads/avatar.jpg'
231
+ * // Valid: '/temp/session.tmp'
232
+ * // Invalid: '/downloads/file.zip'
233
+ * ```
234
+ *
235
+ * ### Error Messages
236
+ * Uses i18n translations for error messages:
237
+ * - `validator.startsWithOneOf`: When value doesn't start with any prefix
238
+ * - `validator.invalidRuleParams`: When no prefixes are provided
239
+ *
240
+ * ### Type Safety
241
+ * - Strongly typed with TypeScript generics
242
+ * - Parameter types enforced at compile time
243
+ * - Runtime type checking for string values
244
+ *
245
+ * ### Performance Notes
246
+ * - Uses `Array.some()` for early termination on first match
247
+ * - Efficient string prefix checking with native `startsWith()`
248
+ * - Minimal memory allocation
249
+ *
250
+ * ### Related Decorators
251
+ * - {@link EndsWithOneOf}: Validates string endings
252
+ * - {@link IsString}: Validates string type
253
+ * - {@link MinLength}: Validates minimum length
254
+ *
255
+ * @decorator
256
+ * @public
257
+ */
258
+ export declare const StartsWithOneOf: (...ruleParameters: string[]) => PropertyDecorator;
259
+ /**
260
+ * ### IsString Rule
261
+ *
262
+ * Validates that the field under validation is a string. If you would like to
263
+ * allow the field to also be null, you should assign the nullable rule to the field.
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * // Class validation
268
+ * class TextContent {
269
+ * @IsRequired()
270
+ * @IsString()
271
+ * title: String;
272
+ *
273
+ * @IsString()
274
+ * description?: String | null;
275
+ * }
276
+ * ```
277
+ *
278
+ * @param options - Validation options containing value and context
279
+ * @returns Promise resolving to true if valid, rejecting with error message if invalid
280
+ *
281
+ *
282
+ * @public
283
+ */
284
+ export declare const IsString: () => PropertyDecorator;
285
+ declare module '../types' {
286
+ interface ValidatorRuleParamTypes {
287
+ /**
288
+ * ### String Rule
289
+ *
290
+ * Validates that the field under validation is a string. If you would like to
291
+ * allow the field to also be null, you should assign the nullable rule to the field.
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * // Valid String values
296
+ * await Validator.validate({
297
+ * value: 'Hello World',
298
+ * rules: ['String']
299
+ * }); // ✓ Valid
300
+ *
301
+ * await Validator.validate({
302
+ * value: '',
303
+ * rules: ['String']
304
+ * }); // ✓ Valid (empty String)
305
+ *
306
+ * // Invalid examples
307
+ * await Validator.validate({
308
+ * value: 123,
309
+ * rules: ['String']
310
+ * }); // ✗ Invalid
311
+ *
312
+ * await Validator.validate({
313
+ * value: null,
314
+ * rules: ['String']
315
+ * }); // ✗ Invalid (use nullable for null support)
316
+ *
317
+ * // With nullable support
318
+ * await Validator.validate({
319
+ * value: null,
320
+ * rules: ['nullable', 'String']
321
+ * }); // ✓ Valid
322
+ *
323
+ * // Class validation
324
+ * class TextContent {
325
+ * @Required
326
+ * @String()
327
+ * title: String;
328
+ *
329
+ * @String()
330
+ * description?: String | null;
331
+ * }
332
+ * ```
333
+ *
334
+ * @param options - Validation options containing value and context
335
+ * @returns Promise resolving to true if valid, rejecting with error message if invalid
336
+ *
337
+ *
338
+ * @public
339
+ */
340
+ String: ValidatorRuleParams<[]>;
341
+ /**
342
+ * ### StartsWithOneOf Rule
343
+ *
344
+ * Validates that the field under validation starts with one of the given values.
345
+ *
346
+ * #### Parameters
347
+ * - List of values that the field must start with
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * // Valid beginnings
352
+ * await Validator.validate({
353
+ * value: 'https://example.com',
354
+ * rules: [{StartsWithOneOf:"http://","https://"}]
355
+ * }); // ✓ Valid
356
+ *
357
+ * await Validator.validate({
358
+ * value: 'USER_12345',
359
+ * rules: [{StartsWithOneOf:"USER_","ADMIN_"}]
360
+ * }); // ✓ Valid
361
+ *
362
+ * // Invalid example
363
+ * await Validator.validate({
364
+ * value: 'ftp://example.com',
365
+ * rules: [{StartsWithOneOf:"http://","https://"}]
366
+ * }); // ✗ Invalid
367
+ *
368
+ * // Class validation
369
+ * class Configuration {
370
+ * @StartsWithOneOf('http://', 'https://')
371
+ * apiUrl: string;
372
+ *
373
+ * @StartsWithOneOf('prod_', 'dev_', 'test_')
374
+ * environment: string;
375
+ * }
376
+ * ```
377
+ *
378
+ * @param options - Validation options with rule parameters
379
+ * @param options.ruleParams - Array of valid starting values
380
+ * @returns Promise resolving to true if valid, rejecting with error message if invalid
381
+ *
382
+ *
383
+ * @public
384
+ */
385
+ StartsWithOneOf: ValidatorRuleParams<string[]>;
386
+ /**
387
+ * ### Ends With Rule
388
+ *
389
+ * Validates that the field under validation ends with one of the given values.
390
+ *
391
+ * #### Parameters
392
+ * - List of values that the field must end with
393
+ *
394
+ * @example
395
+ * ```typescript
396
+ * // Valid endings
397
+ * await Validator.validate({
398
+ * value: 'profile.jpg',
399
+ * rules: [{EndsWithOneOf:["jpg","png","gif"]}]
400
+ * }); // ✓ Valid
401
+ *
402
+ * await Validator.validate({
403
+ * value: 'document.pdf',
404
+ * rules: [{EndsWithOneOf:["pdf","doc","docx"]}]
405
+ * }); // ✓ Valid
406
+ *
407
+ * // Invalid example
408
+ * await Validator.validate({
409
+ * value: 'image.txt',
410
+ * rules: [{EndsWithOneOf:["jpg","png","gif"]}]
411
+ * }); // ✗ Invalid
412
+ *
413
+ * // Class validation
414
+ * class FileUpload {
415
+ * @EndsWithOneOf("jpg", "png", "gif", "webp")
416
+ * imageFile: string;
417
+ *
418
+ * @EndsWithOneOf(".com", ".org", ".net")
419
+ * websiteUrl: string;
420
+ * }
421
+ * ```
422
+ *
423
+ * @param options - Validation options with rule parameters
424
+ * @param options.ruleParams - Array of valid ending values
425
+ * @returns Promise resolving to true if valid, rejecting with error message if invalid
426
+ *
427
+ *
428
+ * @public
429
+ */
430
+ EndsWithOneOf: ValidatorRuleParams<string[]>;
431
+ /**
432
+ * ### Length Rule
433
+ *
434
+ * Validates that the field under validation has a string length that meets
435
+ * the specified criteria. Supports both exact length matching and range validation.
436
+ *
437
+ * #### Parameters
438
+ * - `lengthOrMinLength`: Required number - If only one parameter, exact length required.
439
+ * If two parameters provided, this is the minimum length.
440
+ * - `maxLength`: Optional number - Maximum length when range validation is used.
441
+ *
442
+ * #### Validation Modes
443
+ * 1. **Exact Length**: `@Length(5)` - String must be exactly 5 characters
444
+ * 2. **Range Validation**: `@Length(3, 10)` - String must be 3-10 characters
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * // Exact length validation
449
+ * await Validator.validate({
450
+ * value: 'Hello',
451
+ * rules: [{Length: [5]}]
452
+ * }); // ✓ Valid (exactly 5 characters)
453
+ *
454
+ * await Validator.validate({
455
+ * value: 'Hi',
456
+ * rules: [{Length: [5]}]
457
+ * }); // ✗ Invalid (only 2 characters)
458
+ *
459
+ * // Range validation
460
+ * await Validator.validate({
461
+ * value: 'Hello World',
462
+ * rules: [{Length: [5, 15]}]
463
+ * }); // ✓ Valid (10 characters, within 5-15 range)
464
+ *
465
+ * await Validator.validate({
466
+ * value: 'This is a very long string that exceeds the maximum',
467
+ * rules: [{Length: [5, 15]}]
468
+ * }); // ✗ Invalid (too long)
469
+ *
470
+ * // Class validation
471
+ * class User {
472
+ * @Length(8, 20) // Username: 8-20 characters
473
+ * username: string;
474
+ *
475
+ * @Length(4) // PIN: exactly 4 digits
476
+ * pinCode: string;
477
+ * }
478
+ * ```
479
+ *
480
+ * @param options - Validation options with rule parameters
481
+ * @param options.ruleParams - Array with [lengthOrMinLength, maxLength?]
482
+ * @returns Promise resolving to true if valid, rejecting with error message if invalid
483
+ *
484
+ *
485
+ * @public
486
+ */
487
+ Length: ValidatorRuleParams<[
488
+ lengthOrMinLength: number,
489
+ maxLength?: number
490
+ ]>;
491
+ /**
492
+ * Validator rule that checks if a string meets a minimum length requirement.
493
+ */
494
+ MinLength: ValidatorRuleParams<[minLength: number]>;
495
+ /**
496
+ * Validator rule that checks if a string does not exceed a maximum length.
497
+ */
498
+ MaxLength: ValidatorRuleParams<[maxLength: number]>;
499
+ /**
500
+ * Validator rule that checks if a value is a non-null string.
501
+ */
502
+ NonNullString: ValidatorRuleParams<[]>;
503
+ }
504
+ }