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.
- package/README.md +298 -0
- package/build/auth/index.d.ts +2034 -0
- package/build/auth/index.js +5 -0
- package/build/auth/types.d.ts +465 -0
- package/build/auth/types.js +1 -0
- package/build/countries/countries.d.ts +1454 -0
- package/build/countries/countries.js +1 -0
- package/build/countries/index.d.ts +159 -0
- package/build/countries/index.js +5 -0
- package/build/countries/types.d.ts +65 -0
- package/build/countries/types.js +1 -0
- package/build/currency/currencies.d.ts +8 -0
- package/build/currency/currencies.js +1 -0
- package/build/currency/index.d.ts +51 -0
- package/build/currency/index.js +5 -0
- package/build/currency/session.d.ts +23 -0
- package/build/currency/session.js +5 -0
- package/build/currency/types.d.ts +1039 -0
- package/build/currency/types.js +1 -0
- package/build/currency/utils.d.ts +25 -0
- package/build/currency/utils.js +1 -0
- package/build/i18n/index.d.ts +640 -0
- package/build/i18n/index.js +5 -0
- package/build/inputFormatter/index.d.ts +396 -0
- package/build/inputFormatter/index.js +5 -0
- package/build/inputFormatter/types.d.ts +544 -0
- package/build/inputFormatter/types.js +1 -0
- package/build/logger/index.d.ts +235 -0
- package/build/logger/index.js +5 -0
- package/build/observable/index.d.ts +329 -0
- package/build/observable/index.js +1 -0
- package/build/platform/index.d.ts +32 -0
- package/build/platform/index.js +1 -0
- package/build/resources/ResourcePaginationHelper.d.ts +537 -0
- package/build/resources/ResourcePaginationHelper.js +2 -0
- package/build/resources/decorators/create.decorator.d.ts +20 -0
- package/build/resources/decorators/create.decorator.js +1 -0
- package/build/resources/decorators/index.d.ts +41 -0
- package/build/resources/decorators/index.js +1 -0
- package/build/resources/fields/index.d.ts +33 -0
- package/build/resources/fields/index.js +1 -0
- package/build/resources/filters.d.ts +62 -0
- package/build/resources/filters.js +1 -0
- package/build/resources/index.d.ts +854 -0
- package/build/resources/index.js +6 -0
- package/build/resources/types/filters.d.ts +508 -0
- package/build/resources/types/filters.js +1 -0
- package/build/resources/types/index.d.ts +4138 -0
- package/build/resources/types/index.js +1 -0
- package/build/session/index.d.ts +1474 -0
- package/build/session/index.js +1 -0
- package/build/translations/auth.en.d.ts +3 -0
- package/build/translations/auth.en.js +1 -0
- package/build/translations/countries.en.d.ts +6 -0
- package/build/translations/countries.en.js +1 -0
- package/build/translations/currencies.en.d.ts +5 -0
- package/build/translations/currencies.en.js +1 -0
- package/build/translations/date.en.d.ts +19 -0
- package/build/translations/date.en.js +1 -0
- package/build/translations/index.d.ts +1583 -0
- package/build/translations/index.js +5 -0
- package/build/translations/resources.en.d.ts +6 -0
- package/build/translations/resources.en.js +1 -0
- package/build/translations/validator.en.d.ts +104 -0
- package/build/translations/validator.en.js +5 -0
- package/build/types/date.d.ts +44 -0
- package/build/types/date.js +1 -0
- package/build/types/dictionary.d.ts +29 -0
- package/build/types/dictionary.js +1 -0
- package/build/types/i18n.d.ts +121 -0
- package/build/types/i18n.js +1 -0
- package/build/types/index.d.ts +145 -0
- package/build/types/index.js +1 -0
- package/build/utils/areEquals.d.ts +19 -0
- package/build/utils/areEquals.js +1 -0
- package/build/utils/date/dateHelper.d.ts +371 -0
- package/build/utils/date/dateHelper.js +5 -0
- package/build/utils/date/index.d.ts +212 -0
- package/build/utils/date/index.js +5 -0
- package/build/utils/date/isDateObj.d.ts +14 -0
- package/build/utils/date/isDateObj.js +1 -0
- package/build/utils/debounce.d.ts +52 -0
- package/build/utils/debounce.js +1 -0
- package/build/utils/defaultArray.d.ts +18 -0
- package/build/utils/defaultArray.js +1 -0
- package/build/utils/defaultBool.d.ts +14 -0
- package/build/utils/defaultBool.js +1 -0
- package/build/utils/defaultStr.d.ts +17 -0
- package/build/utils/defaultStr.js +1 -0
- package/build/utils/defaultVal.d.ts +18 -0
- package/build/utils/defaultVal.js +1 -0
- package/build/utils/dom/index.d.ts +65 -0
- package/build/utils/dom/index.js +1 -0
- package/build/utils/dom/isDOMElement.d.ts +11 -0
- package/build/utils/dom/isDOMElement.js +1 -0
- package/build/utils/file/index.d.ts +26 -0
- package/build/utils/file/index.js +1 -0
- package/build/utils/global.d.ts +53 -0
- package/build/utils/global.js +1 -0
- package/build/utils/image.d.ts +56 -0
- package/build/utils/image.js +1 -0
- package/build/utils/index.d.ts +39 -0
- package/build/utils/index.js +6 -0
- package/build/utils/interpolate.d.ts +105 -0
- package/build/utils/interpolate.js +1 -0
- package/build/utils/isEmail.d.ts +57 -0
- package/build/utils/isEmail.js +1 -0
- package/build/utils/isEmpty.d.ts +18 -0
- package/build/utils/isEmpty.js +1 -0
- package/build/utils/isNonNullString.d.ts +17 -0
- package/build/utils/isNonNullString.js +1 -0
- package/build/utils/isNullable.d.ts +7 -0
- package/build/utils/isNullable.js +1 -0
- package/build/utils/isNumber.d.ts +36 -0
- package/build/utils/isNumber.js +1 -0
- package/build/utils/isPrimitive.d.ts +16 -0
- package/build/utils/isPrimitive.js +1 -0
- package/build/utils/isPromise.d.ts +14 -0
- package/build/utils/isPromise.js +1 -0
- package/build/utils/isRegex.d.ts +15 -0
- package/build/utils/isRegex.js +1 -0
- package/build/utils/isTime.d.ts +18 -0
- package/build/utils/isTime.js +1 -0
- package/build/utils/json.d.ts +224 -0
- package/build/utils/json.js +1 -0
- package/build/utils/numbers.d.ts +148 -0
- package/build/utils/numbers.js +5 -0
- package/build/utils/object.d.ts +567 -0
- package/build/utils/object.js +1 -0
- package/build/utils/sort.d.ts +67 -0
- package/build/utils/sort.js +1 -0
- package/build/utils/string.d.ts +165 -0
- package/build/utils/string.js +1 -0
- package/build/utils/stringify.d.ts +23 -0
- package/build/utils/stringify.js +1 -0
- package/build/utils/uniqid.d.ts +18 -0
- package/build/utils/uniqid.js +1 -0
- package/build/utils/uri/index.d.ts +333 -0
- package/build/utils/uri/index.js +2 -0
- package/build/validator/index.d.ts +4 -0
- package/build/validator/index.js +6 -0
- package/build/validator/rules/array.d.ts +848 -0
- package/build/validator/rules/array.js +5 -0
- package/build/validator/rules/boolean.d.ts +87 -0
- package/build/validator/rules/boolean.js +5 -0
- package/build/validator/rules/date.d.ts +551 -0
- package/build/validator/rules/date.js +5 -0
- package/build/validator/rules/default.d.ts +367 -0
- package/build/validator/rules/default.js +5 -0
- package/build/validator/rules/enum.d.ts +155 -0
- package/build/validator/rules/enum.js +5 -0
- package/build/validator/rules/file.d.ts +356 -0
- package/build/validator/rules/file.js +5 -0
- package/build/validator/rules/format.d.ts +2825 -0
- package/build/validator/rules/format.js +6 -0
- package/build/validator/rules/index.d.ts +16 -0
- package/build/validator/rules/index.js +6 -0
- package/build/validator/rules/multiRules.d.ts +475 -0
- package/build/validator/rules/multiRules.js +5 -0
- package/build/validator/rules/numeric.d.ts +1135 -0
- package/build/validator/rules/numeric.js +5 -0
- package/build/validator/rules/string.d.ts +504 -0
- package/build/validator/rules/string.js +5 -0
- package/build/validator/rules/target.d.ts +137 -0
- package/build/validator/rules/target.js +5 -0
- package/build/validator/rules/utils.d.ts +1 -0
- package/build/validator/rules/utils.js +1 -0
- package/build/validator/rulesMarkers.d.ts +11 -0
- package/build/validator/rulesMarkers.js +1 -0
- package/build/validator/types.d.ts +2906 -0
- package/build/validator/types.js +1 -0
- package/build/validator/validator.d.ts +3692 -0
- package/build/validator/validator.js +5 -0
- package/lib/cjs/auth.js +1 -0
- package/lib/cjs/countries.js +1 -0
- package/lib/cjs/currency.js +1 -0
- package/lib/cjs/i18n.js +1 -0
- package/lib/cjs/inputFormatter.js +1 -0
- package/lib/cjs/logger.js +1 -0
- package/lib/cjs/observable.js +1 -0
- package/lib/cjs/platform.js +1 -0
- package/lib/cjs/resources.js +1 -0
- package/lib/cjs/session.js +1 -0
- package/lib/cjs/types.js +1 -0
- package/lib/cjs/utils.js +1 -0
- package/lib/cjs/validator.js +1 -0
- package/lib/esm/auth.mjs +1 -0
- package/lib/esm/countries.mjs +1 -0
- package/lib/esm/currency.mjs +1 -0
- package/lib/esm/i18n.mjs +1 -0
- package/lib/esm/inputFormatter.mjs +1 -0
- package/lib/esm/logger.mjs +1 -0
- package/lib/esm/observable.mjs +1 -0
- package/lib/esm/platform.mjs +1 -0
- package/lib/esm/resources.mjs +1 -0
- package/lib/esm/session.mjs +1 -0
- package/lib/esm/types.mjs +1 -0
- package/lib/esm/utils.mjs +1 -0
- package/lib/esm/validator.mjs +1 -0
- package/package.json +244 -0
|
@@ -0,0 +1,1135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ### IsNumberLTE Decorator
|
|
3
|
+
*
|
|
4
|
+
* Validates that a numeric field has a value less than or equal to a specified maximum.
|
|
5
|
+
* This decorator ensures that input values do not exceed a defined upper limit.
|
|
6
|
+
*
|
|
7
|
+
* ### Purpose
|
|
8
|
+
* Useful for enforcing maximum values in numeric inputs such as:
|
|
9
|
+
* - Age limits (must be ≤ 120 years)
|
|
10
|
+
* - Quantity limits (must be ≤ maximum stock)
|
|
11
|
+
* - Score ranges (must be ≤ 100 points)
|
|
12
|
+
* - Price ceilings (must be ≤ maximum allowed price)
|
|
13
|
+
*
|
|
14
|
+
* ### Parameters
|
|
15
|
+
* Takes a single numeric parameter representing the maximum allowed value (inclusive).
|
|
16
|
+
*
|
|
17
|
+
* ### Validation Logic
|
|
18
|
+
* 1. **Type Conversion**: Converts input values to numbers using `toNumber()`
|
|
19
|
+
* 2. **NaN Handling**: Rejects if either value or comparison parameter is NaN
|
|
20
|
+
* 3. **Comparison**: Checks if `value ≤ comparisonValue`
|
|
21
|
+
* 4. **Result**: Passes if value is ≤ limit, fails otherwise
|
|
22
|
+
*
|
|
23
|
+
* ### Return Behavior
|
|
24
|
+
* - **Success**: Resolves with `true` if `value ≤ maxValue`
|
|
25
|
+
* - **Failure**: Rejects with localized error message if `value > maxValue`
|
|
26
|
+
* - **Invalid Input**: Rejects if values cannot be converted to numbers
|
|
27
|
+
* - **Missing Parameter**: Resolves with error if no comparison value provided
|
|
28
|
+
*
|
|
29
|
+
* ### Examples
|
|
30
|
+
*
|
|
31
|
+
* #### Basic Usage - Age Validation
|
|
32
|
+
* ```typescript
|
|
33
|
+
* class Person {
|
|
34
|
+
* @IsNumberLTE(120)
|
|
35
|
+
* age: number; // Must be ≤ 120 years
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // Valid: 25, 120, 0
|
|
39
|
+
* // Invalid: 121, 150
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* #### Quantity Limits
|
|
43
|
+
* ```typescript
|
|
44
|
+
* class Order {
|
|
45
|
+
* @IsNumberLTE(1000)
|
|
46
|
+
* quantity: number; // Maximum 1000 units per order
|
|
47
|
+
*
|
|
48
|
+
* @IsNumberLTE(100)
|
|
49
|
+
* discountPercent: number; // Max 100% discount
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* #### Score Validation
|
|
54
|
+
* ```typescript
|
|
55
|
+
* class Exam {
|
|
56
|
+
* @IsNumberLTE(100)
|
|
57
|
+
* score: number; // Test scores out of 100
|
|
58
|
+
*
|
|
59
|
+
* @IsNumberLTE(50)
|
|
60
|
+
* bonusPoints: number; // Max 50 bonus points
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* #### Price Ceilings
|
|
65
|
+
* ```typescript
|
|
66
|
+
* class Product {
|
|
67
|
+
* @IsNumberLTE(999.99)
|
|
68
|
+
* price: number; // Maximum retail price
|
|
69
|
+
*
|
|
70
|
+
* @IsNumberLTE(100)
|
|
71
|
+
* markupPercent: number; // Max 100% markup
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ### Error Messages
|
|
76
|
+
* Uses i18n translation key: `validator.numberLTE`
|
|
77
|
+
* Default format: "The {field} must be less than or equal to {comparisonValue}"
|
|
78
|
+
*
|
|
79
|
+
* ### Type Safety
|
|
80
|
+
* - Strongly typed with TypeScript generics
|
|
81
|
+
* - Parameter validation at compile time
|
|
82
|
+
* - Runtime type checking and conversion
|
|
83
|
+
*
|
|
84
|
+
* ### Performance Notes
|
|
85
|
+
* - Efficient numeric conversion and comparison
|
|
86
|
+
* - Early termination on invalid inputs
|
|
87
|
+
* - Minimal memory allocation
|
|
88
|
+
*
|
|
89
|
+
* ### Related Decorators
|
|
90
|
+
* - {@link IsNumberGTE}: Opposite validation (minimum values)
|
|
91
|
+
* - {@link IsNumberLT}: Strict less than validation
|
|
92
|
+
* - {@link IsNumberGT}: Strict greater than validation
|
|
93
|
+
* - {@link IsNumberBetween}: Range validation
|
|
94
|
+
*
|
|
95
|
+
* ### Implementation Details
|
|
96
|
+
* Uses the `compareNumer` helper function for consistent numeric validation
|
|
97
|
+
* across all comparison decorators. Handles edge cases like NaN values and
|
|
98
|
+
* type conversion automatically.
|
|
99
|
+
*
|
|
100
|
+
* @decorator
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
export declare const IsNumberLTE: (ruleParameters_0: number) => PropertyDecorator;
|
|
104
|
+
/**
|
|
105
|
+
* @decorator IsNumberLT
|
|
106
|
+
*
|
|
107
|
+
* Validator rule that checks if a given number is less than a specified value.
|
|
108
|
+
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
|
|
109
|
+
*
|
|
110
|
+
* ### Parameters:
|
|
111
|
+
* - **options**: `ValidatorValidateOptions` - An object containing:
|
|
112
|
+
* - `value`: The number to validate.
|
|
113
|
+
* - `ruleParams`: An array where the first element is the value to compare against.
|
|
114
|
+
*
|
|
115
|
+
* ### Return Value:
|
|
116
|
+
* - `ValidatorResult`: Resolves to `true` if the value is less than the specified comparison value,
|
|
117
|
+
* otherwise rejects with an error message indicating the validation failure.
|
|
118
|
+
*
|
|
119
|
+
* ### Example Usage:
|
|
120
|
+
* ```typescript
|
|
121
|
+
* class MyClass {
|
|
122
|
+
* @IsNumberLT(10)
|
|
123
|
+
* myNumber: number;
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* ### Notes:
|
|
128
|
+
* - This rule is useful for scenarios where you need to ensure that a numeric input is strictly less than a specified limit.
|
|
129
|
+
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
|
|
130
|
+
*/
|
|
131
|
+
export declare const IsNumberLT: (ruleParameters_0: number) => PropertyDecorator;
|
|
132
|
+
/**
|
|
133
|
+
* @decorator IsNumberGTE
|
|
134
|
+
*
|
|
135
|
+
* Validator rule that checks if a given number is greater than or equal to a specified value.
|
|
136
|
+
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
|
|
137
|
+
*
|
|
138
|
+
* ### Parameters:
|
|
139
|
+
* - **options**: `ValidatorValidateOptions` - An object containing:
|
|
140
|
+
* - `value`: The number to validate.
|
|
141
|
+
* - `ruleParams`: An array where the first element is the value to compare against.
|
|
142
|
+
*
|
|
143
|
+
* ### Return Value:
|
|
144
|
+
* - `ValidatorResult`: Resolves to `true` if the value is greater than or equal to the specified comparison value,
|
|
145
|
+
* otherwise rejects with an error message indicating the validation failure.
|
|
146
|
+
*
|
|
147
|
+
* ### Example Usage:
|
|
148
|
+
* ```typescript
|
|
149
|
+
* class MyClass {
|
|
150
|
+
* @IsNumberGTE(5)
|
|
151
|
+
* myNumber: number;
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* ### Notes:
|
|
156
|
+
* - This rule is useful for scenarios where you need to ensure that a numeric input meets or exceeds a specified limit.
|
|
157
|
+
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
|
|
158
|
+
*/
|
|
159
|
+
export declare const IsNumberGTE: (ruleParameters_0: number) => PropertyDecorator;
|
|
160
|
+
/**
|
|
161
|
+
* @decorator IsNumberGT
|
|
162
|
+
*
|
|
163
|
+
* Validator rule that checks if a given number is greater than a specified value.
|
|
164
|
+
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
|
|
165
|
+
*
|
|
166
|
+
* ### Parameters:
|
|
167
|
+
* - **options**: `ValidatorValidateOptions` - An object containing:
|
|
168
|
+
* - `value`: The number to validate.
|
|
169
|
+
* - `ruleParams`: An array where the first element is the value to compare against.
|
|
170
|
+
*
|
|
171
|
+
* ### Return Value:
|
|
172
|
+
* - `ValidatorResult`: Resolves to `true` if the value is greater than the specified comparison value,
|
|
173
|
+
* otherwise rejects with an error message indicating the validation failure.
|
|
174
|
+
*
|
|
175
|
+
* ### Example Usage:
|
|
176
|
+
* ```typescript
|
|
177
|
+
* class MyClass {
|
|
178
|
+
* @IsNumberGT([10])
|
|
179
|
+
* myNumber: number;
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* ### Notes:
|
|
184
|
+
* - This rule is useful for scenarios where you need to ensure that a numeric input exceeds a specified limit.
|
|
185
|
+
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
|
|
186
|
+
*/
|
|
187
|
+
export declare const IsNumberGT: (ruleParameters_0: number) => PropertyDecorator;
|
|
188
|
+
/**
|
|
189
|
+
* @decorator IsNumberEQ
|
|
190
|
+
*
|
|
191
|
+
* Validator rule that checks if a given number is equal to a specified value.
|
|
192
|
+
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
|
|
193
|
+
*
|
|
194
|
+
* ### Parameters:
|
|
195
|
+
* - **options**: `ValidatorValidateOptions` - An object containing:
|
|
196
|
+
* - `value`: The number to validate.
|
|
197
|
+
* - `ruleParams`: An array where the first element is the value to compare against.
|
|
198
|
+
*
|
|
199
|
+
* ### Return Value:
|
|
200
|
+
* - `ValidatorResult`: Resolves to `true` if the value is equal to the specified comparison value,
|
|
201
|
+
* otherwise rejects with an error message indicating the validation failure.
|
|
202
|
+
*
|
|
203
|
+
* ### Example Usage:
|
|
204
|
+
* ```typescript
|
|
205
|
+
* class MyClass {
|
|
206
|
+
* @ IsNumberEQ([10])
|
|
207
|
+
* myNumber: number;
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* ### Notes:
|
|
212
|
+
* - This rule is useful for scenarios where you need to ensure that a numeric input matches a specified value exactly.
|
|
213
|
+
* - The error message can be customized by modifying the second parameter of the `compareNumer` function.
|
|
214
|
+
*/
|
|
215
|
+
export declare const IsNumberEQ: (ruleParameters_0: number) => PropertyDecorator;
|
|
216
|
+
/**
|
|
217
|
+
* @decorator IsNumberNE
|
|
218
|
+
*
|
|
219
|
+
* Validator rule that checks if a given number is not equal to a specified value.
|
|
220
|
+
* This rule utilizes the `compareNumer` function to perform the comparison and return the result.
|
|
221
|
+
*
|
|
222
|
+
* ### Example Usage:
|
|
223
|
+
* ```typescript
|
|
224
|
+
* class MyClass {
|
|
225
|
+
* @IsNumberNE([10])
|
|
226
|
+
* myNumber: number;
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare const IsNumberNE: (ruleParameters_0: number) => PropertyDecorator;
|
|
231
|
+
/**
|
|
232
|
+
* ## Pre-Built Validation Decorators
|
|
233
|
+
*
|
|
234
|
+
* Collection of commonly used validation decorators that provide immediate
|
|
235
|
+
* validation capabilities for standard data types and formats. These decorators
|
|
236
|
+
* are built on top of registered validation rules and provide a convenient
|
|
237
|
+
* way to apply common validations.
|
|
238
|
+
*/
|
|
239
|
+
/**
|
|
240
|
+
* ### IsNumber Decorator
|
|
241
|
+
*
|
|
242
|
+
* Validates that a property value is a valid number. This decorator checks
|
|
243
|
+
* for numeric values and rejects non-numeric inputs.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* class Product {
|
|
248
|
+
* @IsNumber()
|
|
249
|
+
* price: number;
|
|
250
|
+
*
|
|
251
|
+
* @IsNumber()
|
|
252
|
+
* quantity: number;
|
|
253
|
+
*
|
|
254
|
+
* @IsRequired()
|
|
255
|
+
* @IsNumber()
|
|
256
|
+
* weight: number;
|
|
257
|
+
* }
|
|
258
|
+
*
|
|
259
|
+
* // Valid data
|
|
260
|
+
* const product = { price: 19.99, quantity: 5, weight: 2.5 };
|
|
261
|
+
*
|
|
262
|
+
* // Invalid data
|
|
263
|
+
* const invalid = { price: "not-a-number", quantity: 5, weight: 2.5 };
|
|
264
|
+
* // Will fail validation with error: "Price must be a number"
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @decorator
|
|
268
|
+
*
|
|
269
|
+
* @see {@link IsRequired} - Often used together
|
|
270
|
+
* @public
|
|
271
|
+
*/
|
|
272
|
+
export declare const IsNumber: () => PropertyDecorator;
|
|
273
|
+
/**
|
|
274
|
+
* ### IsNumberBetween Rule (Numeric)
|
|
275
|
+
*
|
|
276
|
+
* Validates that the field under validation has a numeric value between the
|
|
277
|
+
* given minimum and maximum values (inclusive).
|
|
278
|
+
*
|
|
279
|
+
* #### Parameters
|
|
280
|
+
* - `min` - Minimum value (inclusive)
|
|
281
|
+
* - `max` - Maximum value (inclusive)
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```typescript
|
|
285
|
+
* // Class validation
|
|
286
|
+
* class Product {
|
|
287
|
+
* @IsNumberBetween([1, 999])
|
|
288
|
+
* quantity: number;
|
|
289
|
+
*
|
|
290
|
+
* @IsNumberBetween([0.01, 9999.99])
|
|
291
|
+
* price: number;
|
|
292
|
+
*
|
|
293
|
+
* @IsNumberBetween([0, 100])
|
|
294
|
+
* discountPercentage: number;
|
|
295
|
+
* }
|
|
296
|
+
* ```
|
|
297
|
+
*
|
|
298
|
+
* @param options - Validation options with rule parameters
|
|
299
|
+
* @param options.ruleParams - Array containing [min, max] values
|
|
300
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
301
|
+
*
|
|
302
|
+
*
|
|
303
|
+
* @public
|
|
304
|
+
*/
|
|
305
|
+
export declare const IsNumberBetween: (min: number, max: number) => PropertyDecorator;
|
|
306
|
+
/**
|
|
307
|
+
* ### HasDecimalPlaces Rule
|
|
308
|
+
*
|
|
309
|
+
* Validates that the field under validation is numeric and contains the
|
|
310
|
+
* specified number of decimal places.
|
|
311
|
+
*
|
|
312
|
+
* #### Parameters
|
|
313
|
+
* - `places` - Exact number of decimal places required
|
|
314
|
+
* - `min,max` (optional) - Range of decimal places allowed
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* // Class validation
|
|
319
|
+
* class Financial {
|
|
320
|
+
* @HasDecimalPlaces([2])
|
|
321
|
+
* price: number; // Must have exactly 2 decimal places
|
|
322
|
+
*
|
|
323
|
+
* @HasDecimalPlaces([0, 4])
|
|
324
|
+
* exchangeRate: number; // 0-4 decimal places allowed
|
|
325
|
+
*
|
|
326
|
+
* @HasDecimalPlaces([3])
|
|
327
|
+
* weight: number; // Exactly 3 decimal places for precision
|
|
328
|
+
* }
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @param options - Validation options with rule parameters
|
|
332
|
+
* @param options.ruleParams - Array with decimal places specification
|
|
333
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
334
|
+
*
|
|
335
|
+
*
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
338
|
+
export declare const HasDecimalPlaces: (minDecimalPlaces: number, maxDecimalPlaces?: number | undefined) => PropertyDecorator;
|
|
339
|
+
/**
|
|
340
|
+
* ### IsInteger Rule
|
|
341
|
+
*
|
|
342
|
+
* Validates that the field under validation is an Integer. This rule does not
|
|
343
|
+
* verify that the input is of the "Integer" variable type, only that the input
|
|
344
|
+
* is a string or numeric value that contains an Integer.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* class Inventory {
|
|
349
|
+
* @Integer
|
|
350
|
+
* quantity: number;
|
|
351
|
+
*
|
|
352
|
+
* @Integer
|
|
353
|
+
* @Min([0])
|
|
354
|
+
* stockLevel: number;
|
|
355
|
+
*
|
|
356
|
+
* @Integer
|
|
357
|
+
* @NumberBetween([-1000, 1000])
|
|
358
|
+
* adjustment: number;
|
|
359
|
+
* }
|
|
360
|
+
* ```
|
|
361
|
+
*
|
|
362
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
363
|
+
*
|
|
364
|
+
*
|
|
365
|
+
* @public
|
|
366
|
+
*/
|
|
367
|
+
export declare const IsInteger: () => PropertyDecorator;
|
|
368
|
+
/**
|
|
369
|
+
* ### IsEvenNumber Decorator
|
|
370
|
+
*
|
|
371
|
+
* Validates that the field under validation is an integer and even (divisible by 2).
|
|
372
|
+
* Non-numeric inputs or non-integer numbers fail with appropriate messages.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```typescript
|
|
376
|
+
* class Model {
|
|
377
|
+
* @IsEvenNumber()
|
|
378
|
+
* evenId: number;
|
|
379
|
+
* }
|
|
380
|
+
* ```
|
|
381
|
+
* * @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* // Class validation with decorator
|
|
384
|
+
* class Invoice {
|
|
385
|
+
* @IsEvenNumber()
|
|
386
|
+
* batchNumber: number; // Must be an even integer (e.g., 2, 4, 6)
|
|
387
|
+
* }
|
|
388
|
+
*
|
|
389
|
+
* // Direct rule usage
|
|
390
|
+
* await Validator.validate({
|
|
391
|
+
* value: 42,
|
|
392
|
+
* rules: ['EvenNumber']
|
|
393
|
+
* }); // ✓ Valid
|
|
394
|
+
*
|
|
395
|
+
* await Validator.validate({
|
|
396
|
+
* value: 7,
|
|
397
|
+
* rules: ['EvenNumber']
|
|
398
|
+
* }); // ✗ Invalid (odd)
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @public
|
|
402
|
+
*/
|
|
403
|
+
export declare const IsEvenNumber: () => PropertyDecorator;
|
|
404
|
+
/**
|
|
405
|
+
* ### IsOddNumber Decorator
|
|
406
|
+
*
|
|
407
|
+
* Validates that the field under validation is an integer and odd (not divisible by 2).
|
|
408
|
+
* Non-numeric inputs or non-integer numbers fail with appropriate messages.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```typescript
|
|
412
|
+
* class Model {
|
|
413
|
+
* @IsOddNumber()
|
|
414
|
+
* oddId: number;
|
|
415
|
+
* }
|
|
416
|
+
* ```
|
|
417
|
+
* * @example
|
|
418
|
+
* ```typescript
|
|
419
|
+
* // Class validation with decorator
|
|
420
|
+
* class Invoice {
|
|
421
|
+
* @IsOddNumber()
|
|
422
|
+
* ticketNumber: number; // Must be an odd integer (e.g., 1, 3, 5)
|
|
423
|
+
* }
|
|
424
|
+
*
|
|
425
|
+
* // Direct rule usage
|
|
426
|
+
* await Validator.validate({
|
|
427
|
+
* value: 9,
|
|
428
|
+
* rules: ['OddNumber']
|
|
429
|
+
* }); // ✓ Valid
|
|
430
|
+
*
|
|
431
|
+
* await Validator.validate({
|
|
432
|
+
* value: 10,
|
|
433
|
+
* rules: ['OddNumber']
|
|
434
|
+
* }); // ✗ Invalid (even)
|
|
435
|
+
* ```
|
|
436
|
+
*
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
export declare const IsOddNumber: () => PropertyDecorator;
|
|
440
|
+
/**
|
|
441
|
+
* ### Multiple Of Rule
|
|
442
|
+
*
|
|
443
|
+
* Validates that the field under validation is a multiple of the specified value.
|
|
444
|
+
* This is useful for ensuring values conform to specific increments.
|
|
445
|
+
*
|
|
446
|
+
* #### Parameters
|
|
447
|
+
* - `multiple` - The value that the field must be a multiple of
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* // Multiple validation
|
|
452
|
+
* class Pricing {
|
|
453
|
+
* @IsMultipleOf(0.01)
|
|
454
|
+
* price: number; // Must be in cent increments
|
|
455
|
+
*
|
|
456
|
+
* @IsMultipleOf(5)
|
|
457
|
+
* discountPercent: number; // 5% increments
|
|
458
|
+
*
|
|
459
|
+
* @IsMultipleOf(15)
|
|
460
|
+
* appointmentDuration: number; // 15-minute slots
|
|
461
|
+
* }
|
|
462
|
+
* ```
|
|
463
|
+
*
|
|
464
|
+
* @param options - Validation options with rule parameters
|
|
465
|
+
* @param options.ruleParams - Array containing the multiple value
|
|
466
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
467
|
+
*
|
|
468
|
+
*
|
|
469
|
+
* @public
|
|
470
|
+
*/
|
|
471
|
+
export declare const IsMultipleOf: (ruleParameters_0: number) => PropertyDecorator;
|
|
472
|
+
declare module '../types' {
|
|
473
|
+
interface ValidatorRuleParamTypes {
|
|
474
|
+
/**
|
|
475
|
+
* ### Number Rule
|
|
476
|
+
*
|
|
477
|
+
* Validates that the field under validation is a valid number. This rule checks
|
|
478
|
+
* for numeric values and rejects non-numeric inputs. It accepts both integers
|
|
479
|
+
* and floating-point numbers.
|
|
480
|
+
*
|
|
481
|
+
* @example
|
|
482
|
+
* ```typescript
|
|
483
|
+
* // Valid numeric values
|
|
484
|
+
* await Validator.validate({
|
|
485
|
+
* value: 42,
|
|
486
|
+
* rules: ['Number']
|
|
487
|
+
* }); // ✓ Valid
|
|
488
|
+
*
|
|
489
|
+
* await Validator.validate({
|
|
490
|
+
* value: 3.14,
|
|
491
|
+
* rules: ['Number']
|
|
492
|
+
* }); // ✓ Valid (decimal)
|
|
493
|
+
*
|
|
494
|
+
* await Validator.validate({
|
|
495
|
+
* value: -123,
|
|
496
|
+
* rules: ['Number']
|
|
497
|
+
* }); // ✓ Valid (negative)
|
|
498
|
+
*
|
|
499
|
+
* await Validator.validate({
|
|
500
|
+
* value: '456',
|
|
501
|
+
* rules: ['Number']
|
|
502
|
+
* }); // ✓ Valid (numeric string)
|
|
503
|
+
*
|
|
504
|
+
* // Invalid examples
|
|
505
|
+
* await Validator.validate({
|
|
506
|
+
* value: 'abc',
|
|
507
|
+
* rules: ['Number']
|
|
508
|
+
* }); // ✗ Invalid (non-numeric string)
|
|
509
|
+
*
|
|
510
|
+
* await Validator.validate({
|
|
511
|
+
* value: null,
|
|
512
|
+
* rules: ['Number']
|
|
513
|
+
* }); // ✗ Invalid (null)
|
|
514
|
+
*
|
|
515
|
+
* await Validator.validate({
|
|
516
|
+
* value: {},
|
|
517
|
+
* rules: ['Number']
|
|
518
|
+
* }); // ✗ Invalid (object)
|
|
519
|
+
*
|
|
520
|
+
* // Class validation
|
|
521
|
+
* class Product {
|
|
522
|
+
* @IsNumber()
|
|
523
|
+
* price: number;
|
|
524
|
+
*
|
|
525
|
+
* @IsNumber()
|
|
526
|
+
* quantity: number;
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @returns true if valid number, rejecting with error message if invalid
|
|
531
|
+
*
|
|
532
|
+
* @public
|
|
533
|
+
*/
|
|
534
|
+
Number: ValidatorRuleParams<[]>;
|
|
535
|
+
/**
|
|
536
|
+
* ### NumberLTE Rule
|
|
537
|
+
*
|
|
538
|
+
* Validates that the field under validation has a numeric value less than or equal to
|
|
539
|
+
* a specified maximum value. This rule ensures that input values do not exceed
|
|
540
|
+
* a defined upper limit.
|
|
541
|
+
*
|
|
542
|
+
* #### Parameters
|
|
543
|
+
* - `max` - Maximum allowed value (inclusive)
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* // Age limit validation
|
|
548
|
+
* await Validator.validate({
|
|
549
|
+
* value: 25,
|
|
550
|
+
* rules: [{NumberLTE: [120]}]
|
|
551
|
+
* }); // ✓ Valid (age ≤ 120)
|
|
552
|
+
*
|
|
553
|
+
* await Validator.validate({
|
|
554
|
+
* value: 120,
|
|
555
|
+
* rules: [{NumberLTE: [120]}]
|
|
556
|
+
* }); // ✓ Valid (exactly 120)
|
|
557
|
+
*
|
|
558
|
+
* // Quantity limit validation
|
|
559
|
+
* await Validator.validate({
|
|
560
|
+
* value: 500,
|
|
561
|
+
* rules: [{NumberLTE: [1000]}]
|
|
562
|
+
* }); // ✓ Valid (quantity ≤ 1000)
|
|
563
|
+
*
|
|
564
|
+
* // Invalid examples
|
|
565
|
+
* await Validator.validate({
|
|
566
|
+
* value: 150,
|
|
567
|
+
* rules: [{NumberLTE: [120]}]
|
|
568
|
+
* }); // ✗ Invalid (age > 120)
|
|
569
|
+
*
|
|
570
|
+
* // Class validation
|
|
571
|
+
* class Person {
|
|
572
|
+
* @IsNumberLTE(120)
|
|
573
|
+
* age: number; // Must be ≤ 120 years
|
|
574
|
+
* }
|
|
575
|
+
*
|
|
576
|
+
* class Order {
|
|
577
|
+
* @IsNumberLTE(1000)
|
|
578
|
+
* quantity: number; // Maximum 1000 units
|
|
579
|
+
* }
|
|
580
|
+
* ```
|
|
581
|
+
*
|
|
582
|
+
* @param options - Validation options with rule parameters
|
|
583
|
+
* @param options.ruleParams - Array containing the maximum value
|
|
584
|
+
* @returns true if value ≤ max, rejecting with error message if value > max
|
|
585
|
+
*
|
|
586
|
+
*
|
|
587
|
+
* @public
|
|
588
|
+
*/
|
|
589
|
+
NumberLTE: ValidatorRuleParams<[number]>;
|
|
590
|
+
/**
|
|
591
|
+
* ### NumberLT Rule
|
|
592
|
+
*
|
|
593
|
+
* Validates that the field under validation has a numeric value strictly less than
|
|
594
|
+
* a specified maximum value. This rule ensures that input values stay below
|
|
595
|
+
* a defined upper limit (exclusive).
|
|
596
|
+
*
|
|
597
|
+
* #### Parameters
|
|
598
|
+
* - `max` - Maximum allowed value (exclusive)
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```typescript
|
|
602
|
+
* // Age limit validation (must be under 18 for minors)
|
|
603
|
+
* await Validator.validate({
|
|
604
|
+
* value: 17,
|
|
605
|
+
* rules: [{NumberLT: [18]}]
|
|
606
|
+
* }); // ✓ Valid (age < 18)
|
|
607
|
+
*
|
|
608
|
+
* await Validator.validate({
|
|
609
|
+
* value: 17.9,
|
|
610
|
+
* rules: [{NumberLT: [18]}]
|
|
611
|
+
* }); // ✓ Valid (still < 18)
|
|
612
|
+
*
|
|
613
|
+
* // Discount limit validation
|
|
614
|
+
* await Validator.validate({
|
|
615
|
+
* value: 49.99,
|
|
616
|
+
* rules: [{NumberLT: [50]}]
|
|
617
|
+
* }); // ✓ Valid (discount < 50%)
|
|
618
|
+
*
|
|
619
|
+
* // Invalid examples
|
|
620
|
+
* await Validator.validate({
|
|
621
|
+
* value: 18,
|
|
622
|
+
* rules: [{NumberLT: [18]}]
|
|
623
|
+
* }); // ✗ Invalid (18 is not < 18)
|
|
624
|
+
*
|
|
625
|
+
* await Validator.validate({
|
|
626
|
+
* value: 25,
|
|
627
|
+
* rules: [{NumberLT: [18]}]
|
|
628
|
+
* }); // ✗ Invalid (25 > 18)
|
|
629
|
+
*
|
|
630
|
+
* // Class validation
|
|
631
|
+
* class Minor {
|
|
632
|
+
* @IsNumberLT(18)
|
|
633
|
+
* age: number; // Must be < 18 years
|
|
634
|
+
* }
|
|
635
|
+
*
|
|
636
|
+
* class Discount {
|
|
637
|
+
* @IsNumberLT(50)
|
|
638
|
+
* percentage: number; // Must be < 50%
|
|
639
|
+
* }
|
|
640
|
+
* ```
|
|
641
|
+
*
|
|
642
|
+
* @param options - Validation options with rule parameters
|
|
643
|
+
* @param options.ruleParams - Array containing the exclusive maximum value
|
|
644
|
+
* @returns true if value < max, rejecting with error message if value ≥ max
|
|
645
|
+
*
|
|
646
|
+
*
|
|
647
|
+
* @public
|
|
648
|
+
*/
|
|
649
|
+
NumberLT: ValidatorRuleParams<[number]>;
|
|
650
|
+
/**
|
|
651
|
+
* ### NumberGTE Rule
|
|
652
|
+
*
|
|
653
|
+
* Validates that the field under validation has a numeric value greater than or equal to
|
|
654
|
+
* a specified minimum value. This rule ensures that input values meet or exceed
|
|
655
|
+
* a defined lower limit (inclusive).
|
|
656
|
+
*
|
|
657
|
+
* #### Parameters
|
|
658
|
+
* - `min` - Minimum allowed value (inclusive)
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```typescript
|
|
662
|
+
* // Age requirement validation (must be 18 or older)
|
|
663
|
+
* await Validator.validate({
|
|
664
|
+
* value: 18,
|
|
665
|
+
* rules: [{NumberGTE: [18]}]
|
|
666
|
+
* }); // ✓ Valid (age ≥ 18)
|
|
667
|
+
*
|
|
668
|
+
* await Validator.validate({
|
|
669
|
+
* value: 25,
|
|
670
|
+
* rules: [{NumberGTE: [18]}]
|
|
671
|
+
* }); // ✓ Valid (age > 18)
|
|
672
|
+
*
|
|
673
|
+
* // Minimum balance validation
|
|
674
|
+
* await Validator.validate({
|
|
675
|
+
* value: 100.00,
|
|
676
|
+
* rules: [{NumberGTE: [50.00]}]
|
|
677
|
+
* }); // ✓ Valid (balance ≥ $50)
|
|
678
|
+
*
|
|
679
|
+
* // Invalid examples
|
|
680
|
+
* await Validator.validate({
|
|
681
|
+
* value: 17,
|
|
682
|
+
* rules: [{NumberGTE: [18]}]
|
|
683
|
+
* }); // ✗ Invalid (17 < 18)
|
|
684
|
+
*
|
|
685
|
+
* await Validator.validate({
|
|
686
|
+
* value: 17.9,
|
|
687
|
+
* rules: [{NumberGTE: [18]}]
|
|
688
|
+
* }); // ✗ Invalid (17.9 < 18)
|
|
689
|
+
*
|
|
690
|
+
* // Class validation
|
|
691
|
+
* class Adult {
|
|
692
|
+
* @IsNumberGTE(18)
|
|
693
|
+
* age: number; // Must be ≥ 18 years
|
|
694
|
+
* }
|
|
695
|
+
*
|
|
696
|
+
* class Account {
|
|
697
|
+
* @IsNumberGTE(0)
|
|
698
|
+
* balance: number; // Must be ≥ $0
|
|
699
|
+
* }
|
|
700
|
+
* ```
|
|
701
|
+
*
|
|
702
|
+
* @param options - Validation options with rule parameters
|
|
703
|
+
* @param options.ruleParams - Array containing the inclusive minimum value
|
|
704
|
+
* @returns true if value ≥ min, rejecting with error message if value < min
|
|
705
|
+
*
|
|
706
|
+
*
|
|
707
|
+
* @public
|
|
708
|
+
*/
|
|
709
|
+
NumberGTE: ValidatorRuleParams<[number]>;
|
|
710
|
+
/**
|
|
711
|
+
* ### NumberGT Rule
|
|
712
|
+
*
|
|
713
|
+
* Validates that the field under validation has a numeric value strictly greater than
|
|
714
|
+
* a specified minimum value. This rule ensures that input values exceed
|
|
715
|
+
* a defined lower limit (exclusive).
|
|
716
|
+
*
|
|
717
|
+
* #### Parameters
|
|
718
|
+
* - `min` - Minimum allowed value (exclusive)
|
|
719
|
+
*
|
|
720
|
+
* @example
|
|
721
|
+
* ```typescript
|
|
722
|
+
* // Age requirement validation (must be over 18)
|
|
723
|
+
* await Validator.validate({
|
|
724
|
+
* value: 19,
|
|
725
|
+
* rules: [{NumberGT: [18]}]
|
|
726
|
+
* }); // ✓ Valid (age > 18)
|
|
727
|
+
*
|
|
728
|
+
* await Validator.validate({
|
|
729
|
+
* value: 18.1,
|
|
730
|
+
* rules: [{NumberGT: [18]}]
|
|
731
|
+
* }); // ✓ Valid (age > 18)
|
|
732
|
+
*
|
|
733
|
+
* // Minimum purchase validation
|
|
734
|
+
* await Validator.validate({
|
|
735
|
+
* value: 100.01,
|
|
736
|
+
* rules: [{NumberGT: [100]}]
|
|
737
|
+
* }); // ✓ Valid (amount > $100)
|
|
738
|
+
*
|
|
739
|
+
* // Invalid examples
|
|
740
|
+
* await Validator.validate({
|
|
741
|
+
* value: 18,
|
|
742
|
+
* rules: [{NumberGT: [18]}]
|
|
743
|
+
* }); // ✗ Invalid (18 is not > 18)
|
|
744
|
+
*
|
|
745
|
+
* await Validator.validate({
|
|
746
|
+
* value: 15,
|
|
747
|
+
* rules: [{NumberGT: [18]}]
|
|
748
|
+
* }); // ✗ Invalid (15 < 18)
|
|
749
|
+
*
|
|
750
|
+
* // Class validation
|
|
751
|
+
* class Senior {
|
|
752
|
+
* @IsNumberGT(65)
|
|
753
|
+
* age: number; // Must be > 65 years
|
|
754
|
+
* }
|
|
755
|
+
*
|
|
756
|
+
* class Premium {
|
|
757
|
+
* @IsNumberGT(1000)
|
|
758
|
+
* purchaseAmount: number; // Must be > $1000
|
|
759
|
+
* }
|
|
760
|
+
* ```
|
|
761
|
+
*
|
|
762
|
+
* @param options - Validation options with rule parameters
|
|
763
|
+
* @param options.ruleParams - Array containing the exclusive minimum value
|
|
764
|
+
* @returns true if value > min, rejecting with error message if value ≤ min
|
|
765
|
+
*
|
|
766
|
+
*
|
|
767
|
+
* @public
|
|
768
|
+
*/
|
|
769
|
+
NumberGT: ValidatorRuleParams<[number]>;
|
|
770
|
+
/**
|
|
771
|
+
* ### NumberEQ Rule
|
|
772
|
+
*
|
|
773
|
+
* Validates that the field under validation has a numeric value exactly equal to
|
|
774
|
+
* a specified target value. This rule ensures that input values match
|
|
775
|
+
* a precise numeric requirement.
|
|
776
|
+
*
|
|
777
|
+
* #### Parameters
|
|
778
|
+
* - `target` - Exact value that the field must equal
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```typescript
|
|
782
|
+
* // PIN code validation (must be exactly 1234)
|
|
783
|
+
* await Validator.validate({
|
|
784
|
+
* value: 1234,
|
|
785
|
+
* rules: [{NumberEQ: [1234]}]
|
|
786
|
+
* }); // ✓ Valid (exact match)
|
|
787
|
+
*
|
|
788
|
+
* // Magic number validation
|
|
789
|
+
* await Validator.validate({
|
|
790
|
+
* value: 42,
|
|
791
|
+
* rules: [{NumberEQ: [42]}]
|
|
792
|
+
* }); // ✓ Valid (exact match)
|
|
793
|
+
*
|
|
794
|
+
* // Version number validation
|
|
795
|
+
* await Validator.validate({
|
|
796
|
+
* value: 1.0,
|
|
797
|
+
* rules: [{NumberEQ: [1.0]}]
|
|
798
|
+
* }); // ✓ Valid (exact match)
|
|
799
|
+
*
|
|
800
|
+
* // Invalid examples
|
|
801
|
+
* await Validator.validate({
|
|
802
|
+
* value: 1235,
|
|
803
|
+
* rules: [{NumberEQ: [1234]}]
|
|
804
|
+
* }); // ✗ Invalid (not equal)
|
|
805
|
+
*
|
|
806
|
+
* await Validator.validate({
|
|
807
|
+
* value: 41.9,
|
|
808
|
+
* rules: [{NumberEQ: [42]}]
|
|
809
|
+
* }); // ✗ Invalid (not equal)
|
|
810
|
+
*
|
|
811
|
+
* // Class validation
|
|
812
|
+
* class AccessCode {
|
|
813
|
+
* @IsNumberEQ(1234)
|
|
814
|
+
* pinCode: number; // Must be exactly 1234
|
|
815
|
+
* }
|
|
816
|
+
*
|
|
817
|
+
* class Version {
|
|
818
|
+
* @IsNumberEQ(1.0)
|
|
819
|
+
* versionNumber: number; // Must be exactly 1.0
|
|
820
|
+
* }
|
|
821
|
+
* ```
|
|
822
|
+
*
|
|
823
|
+
* @param options - Validation options with rule parameters
|
|
824
|
+
* @param options.ruleParams - Array containing the exact target value
|
|
825
|
+
* @returns true if value === target, rejecting with error message if value !== target
|
|
826
|
+
*
|
|
827
|
+
*
|
|
828
|
+
* @public
|
|
829
|
+
*/
|
|
830
|
+
NumberEQ: ValidatorRuleParams<[number]>;
|
|
831
|
+
/**
|
|
832
|
+
* ### NumberNE Rule
|
|
833
|
+
*
|
|
834
|
+
* Validates that the field under validation has a numeric value different from
|
|
835
|
+
* a specified forbidden value. This rule ensures that input values do not match
|
|
836
|
+
* a particular number that should be avoided.
|
|
837
|
+
*
|
|
838
|
+
* #### Parameters
|
|
839
|
+
* - `forbidden` - Value that the field must not equal
|
|
840
|
+
*
|
|
841
|
+
* @example
|
|
842
|
+
* ```typescript
|
|
843
|
+
* // Reserved number validation (cannot be 0)
|
|
844
|
+
* await Validator.validate({
|
|
845
|
+
* value: 5,
|
|
846
|
+
* rules: [{NumberNE: [0]}]
|
|
847
|
+
* }); // ✓ Valid (not 0)
|
|
848
|
+
*
|
|
849
|
+
* await Validator.validate({
|
|
850
|
+
* value: -1,
|
|
851
|
+
* rules: [{NumberNE: [0]}]
|
|
852
|
+
* }); // ✓ Valid (not 0)
|
|
853
|
+
*
|
|
854
|
+
* // Forbidden ID validation
|
|
855
|
+
* await Validator.validate({
|
|
856
|
+
* value: 123,
|
|
857
|
+
* rules: [{NumberNE: [999]}]
|
|
858
|
+
* }); // ✓ Valid (not 999)
|
|
859
|
+
*
|
|
860
|
+
* // Invalid examples
|
|
861
|
+
* await Validator.validate({
|
|
862
|
+
* value: 0,
|
|
863
|
+
* rules: [{NumberNE: [0]}]
|
|
864
|
+
* }); // ✗ Invalid (equals forbidden value)
|
|
865
|
+
*
|
|
866
|
+
* await Validator.validate({
|
|
867
|
+
* value: 999,
|
|
868
|
+
* rules: [{NumberNE: [999]}]
|
|
869
|
+
* }); // ✗ Invalid (equals forbidden value)
|
|
870
|
+
*
|
|
871
|
+
* // Class validation
|
|
872
|
+
* class User {
|
|
873
|
+
* @IsNumberNE(0)
|
|
874
|
+
* userId: number; // Cannot be 0 (reserved)
|
|
875
|
+
* }
|
|
876
|
+
*
|
|
877
|
+
* class Product {
|
|
878
|
+
* @IsNumberNE(999)
|
|
879
|
+
* sku: number; // Cannot be 999 (test value)
|
|
880
|
+
* }
|
|
881
|
+
* ```
|
|
882
|
+
*
|
|
883
|
+
* @param options - Validation options with rule parameters
|
|
884
|
+
* @param options.ruleParams - Array containing the forbidden value
|
|
885
|
+
* @returns true if value !== forbidden, rejecting with error message if value === forbidden
|
|
886
|
+
*
|
|
887
|
+
*
|
|
888
|
+
* @public
|
|
889
|
+
*/
|
|
890
|
+
NumberNE: ValidatorRuleParams<[number]>;
|
|
891
|
+
/**
|
|
892
|
+
* ### NumberBetween Rule (Numeric)
|
|
893
|
+
*
|
|
894
|
+
* Validates that the field under validation has a numeric value between the
|
|
895
|
+
* given minimum and maximum values (inclusive).
|
|
896
|
+
*
|
|
897
|
+
* #### Parameters
|
|
898
|
+
* - `min` - Minimum value (inclusive)
|
|
899
|
+
* - `max` - Maximum value (inclusive)
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* // Age validation
|
|
904
|
+
* await Validator.validate({
|
|
905
|
+
* value: 25,
|
|
906
|
+
* rules: [{NumberBetween:[18,65]}]
|
|
907
|
+
* }); // ✓ Valid
|
|
908
|
+
*
|
|
909
|
+
* // Price range validation
|
|
910
|
+
* await Validator.validate({
|
|
911
|
+
* value: 99.99,
|
|
912
|
+
* rules: [{NumberBetween:[10.00,999.99]}]
|
|
913
|
+
* }); // ✓ Valid
|
|
914
|
+
*
|
|
915
|
+
* // Percentage validation
|
|
916
|
+
* await Validator.validate({
|
|
917
|
+
* value: 85,
|
|
918
|
+
* rules: [{NumberBetween:[0,100]}]
|
|
919
|
+
* }); // ✓ Valid
|
|
920
|
+
*
|
|
921
|
+
* // Invalid examples
|
|
922
|
+
* await Validator.validate({
|
|
923
|
+
* value: 17,
|
|
924
|
+
* rules: [{NumberBetween:[18,65]}]
|
|
925
|
+
* }); // ✗ Invalid (below minimum)
|
|
926
|
+
* ```
|
|
927
|
+
*
|
|
928
|
+
* @param options - Validation options with rule parameters
|
|
929
|
+
* @param options.ruleParams - Array containing [min, max] values
|
|
930
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
931
|
+
*
|
|
932
|
+
*
|
|
933
|
+
* @public
|
|
934
|
+
*/
|
|
935
|
+
NumberBetween: ValidatorRuleParams<[min: number, max: number]>;
|
|
936
|
+
/**
|
|
937
|
+
* ### DecimalPlaces Rule
|
|
938
|
+
*
|
|
939
|
+
* Validates that the field under validation is numeric and contains the
|
|
940
|
+
* specified number of decimal places.
|
|
941
|
+
*
|
|
942
|
+
* #### Parameters
|
|
943
|
+
* - `places` - Exact number of decimal places required
|
|
944
|
+
* - `min,max` (optional) - Range of decimal places allowed
|
|
945
|
+
*
|
|
946
|
+
* @example
|
|
947
|
+
* ```typescript
|
|
948
|
+
* // Exact decimal places
|
|
949
|
+
* await Validator.validate({
|
|
950
|
+
* value: 99.99,
|
|
951
|
+
* rules: [{DecimalPlaces: [2]}]
|
|
952
|
+
* }); // ✓ Valid (exactly 2 decimal places)
|
|
953
|
+
*
|
|
954
|
+
* await Validator.validate({
|
|
955
|
+
* value: 123.456,
|
|
956
|
+
* rules: [{DecimalPlaces: [3]}]
|
|
957
|
+
* }); // ✓ Valid (exactly 3 decimal places)
|
|
958
|
+
*
|
|
959
|
+
* // Range of decimal places
|
|
960
|
+
* await Validator.validate({
|
|
961
|
+
* value: 99.9,
|
|
962
|
+
* rules: [{DecimalPlaces: [1, 3]}]
|
|
963
|
+
* }); // ✓ Valid (1-3 decimal places)
|
|
964
|
+
*
|
|
965
|
+
* // Invalid examples
|
|
966
|
+
* await Validator.validate({
|
|
967
|
+
* value: 99.999,
|
|
968
|
+
* rules: [{DecimalPlaces: [2]}]
|
|
969
|
+
* }); // ✗ Invalid (3 places, expected 2)
|
|
970
|
+
*
|
|
971
|
+
* await Validator.validate({
|
|
972
|
+
* value: 99,
|
|
973
|
+
* rules: [{DecimalPlaces: [2]}]
|
|
974
|
+
* }); // ✗ Invalid (0 places, expected 2)
|
|
975
|
+
* ```
|
|
976
|
+
*
|
|
977
|
+
* @param options - Validation options with rule parameters
|
|
978
|
+
* @param options.ruleParams - Array with decimal places specification
|
|
979
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
980
|
+
*
|
|
981
|
+
*
|
|
982
|
+
* @public
|
|
983
|
+
*/
|
|
984
|
+
DecimalPlaces: ValidatorRuleParams<[
|
|
985
|
+
minDecimalPlaces: number,
|
|
986
|
+
maxDecimalPlaces?: number
|
|
987
|
+
]>;
|
|
988
|
+
/**
|
|
989
|
+
* ### Integer Rule
|
|
990
|
+
*
|
|
991
|
+
* Validates that the field under validation is an Integer. This rule does not
|
|
992
|
+
* verify that the input is of the "Integer" variable type, only that the input
|
|
993
|
+
* is a string or numeric value that contains an Integer.
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* ```typescript
|
|
997
|
+
* // Valid integers
|
|
998
|
+
* await Validator.validate({
|
|
999
|
+
* value: 42,
|
|
1000
|
+
* rules: ['Integer']
|
|
1001
|
+
* }); // ✓ Valid
|
|
1002
|
+
*
|
|
1003
|
+
* await Validator.validate({
|
|
1004
|
+
* value: '123',
|
|
1005
|
+
* rules: ['Integer']
|
|
1006
|
+
* }); // ✓ Valid (numeric string)
|
|
1007
|
+
*
|
|
1008
|
+
* await Validator.validate({
|
|
1009
|
+
* value: -456,
|
|
1010
|
+
* rules: ['Integer']
|
|
1011
|
+
* }); // ✓ Valid (negative Integer)
|
|
1012
|
+
*
|
|
1013
|
+
* // Invalid examples
|
|
1014
|
+
* await Validator.validate({
|
|
1015
|
+
* value: 12.34,
|
|
1016
|
+
* rules: ['Integer']
|
|
1017
|
+
* }); // ✗ Invalid (has decimal places)
|
|
1018
|
+
*
|
|
1019
|
+
* await Validator.validate({
|
|
1020
|
+
* value: 'abc',
|
|
1021
|
+
* rules: ['Integer']
|
|
1022
|
+
* }); // ✗ Invalid (not numeric)
|
|
1023
|
+
* ```
|
|
1024
|
+
*
|
|
1025
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
1026
|
+
*
|
|
1027
|
+
*
|
|
1028
|
+
* @public
|
|
1029
|
+
*/
|
|
1030
|
+
Integer: ValidatorRuleParams<[]>;
|
|
1031
|
+
/**
|
|
1032
|
+
* ### Even Number Rule
|
|
1033
|
+
*
|
|
1034
|
+
* Validates that the field under validation is an integer and even (divisible by 2).
|
|
1035
|
+
* Non-numeric inputs or non-integer numbers will be rejected with precise messages.
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```typescript
|
|
1039
|
+
* // Valid examples
|
|
1040
|
+
* await Validator.validate({ value: 2, rules: ['EvenNumber'] }); // ✓
|
|
1041
|
+
* await Validator.validate({ value: '8', rules: ['EvenNumber'] }); // ✓ numeric string
|
|
1042
|
+
* await Validator.validate({ value: 0, rules: ['EvenNumber'] }); // ✓ zero is even
|
|
1043
|
+
*
|
|
1044
|
+
* // Invalid examples
|
|
1045
|
+
* await Validator.validate({ value: 3, rules: ['EvenNumber'] }); // ✗ odd
|
|
1046
|
+
* await Validator.validate({ value: 2.5, rules: ['EvenNumber'] }); // ✗ not integer
|
|
1047
|
+
* await Validator.validate({ value: 'abc', rules: ['EvenNumber'] }); // ✗ not numeric
|
|
1048
|
+
* ```
|
|
1049
|
+
*
|
|
1050
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
1051
|
+
*
|
|
1052
|
+
* @public
|
|
1053
|
+
*/
|
|
1054
|
+
EvenNumber: ValidatorRuleParams<[]>;
|
|
1055
|
+
/**
|
|
1056
|
+
* ### Multiple Of Rule
|
|
1057
|
+
*
|
|
1058
|
+
* Validates that the field under validation is a multiple of the specified value.
|
|
1059
|
+
* This is useful for ensuring values conform to specific increments.
|
|
1060
|
+
*
|
|
1061
|
+
* #### Parameters
|
|
1062
|
+
* - `multiple` - The value that the field must be a multiple of
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```typescript
|
|
1066
|
+
* // Multiple validation
|
|
1067
|
+
* await Validator.validate({
|
|
1068
|
+
* value: 15,
|
|
1069
|
+
* rules: [{MultipleOf: [5]}]
|
|
1070
|
+
* }); // ✓ Valid (15 is multiple of 5)
|
|
1071
|
+
*
|
|
1072
|
+
* await Validator.validate({
|
|
1073
|
+
* value: 0.25,
|
|
1074
|
+
* rules: [{MultipleOf: [0.05]}]
|
|
1075
|
+
* }); // ✓ Valid (price increment validation)
|
|
1076
|
+
*
|
|
1077
|
+
* // Time interval validation
|
|
1078
|
+
* await Validator.validate({
|
|
1079
|
+
* value: 30,
|
|
1080
|
+
* rules: [{MultipleOf: [15]}]
|
|
1081
|
+
* }); // ✓ Valid (15-minute intervals)
|
|
1082
|
+
*
|
|
1083
|
+
* // Invalid examples
|
|
1084
|
+
* await Validator.validate({
|
|
1085
|
+
* value: 17,
|
|
1086
|
+
* rules: [{MultipleOf: [5]}]
|
|
1087
|
+
* }); // ✗ Invalid (not a multiple of 5)
|
|
1088
|
+
*
|
|
1089
|
+
* // Class validation
|
|
1090
|
+
* class Pricing {
|
|
1091
|
+
* @IsMultipleOf([0.01])
|
|
1092
|
+
* price: number; // Must be in cent increments
|
|
1093
|
+
*
|
|
1094
|
+
* @IsMultipleOf([5])
|
|
1095
|
+
* discountPercent: number; // 5% increments
|
|
1096
|
+
*
|
|
1097
|
+
* @IsMultipleOf([15])
|
|
1098
|
+
* appointmentDuration: number; // 15-minute slots
|
|
1099
|
+
* }
|
|
1100
|
+
* ```
|
|
1101
|
+
*
|
|
1102
|
+
* @param options - Validation options with rule parameters
|
|
1103
|
+
* @param options.ruleParams - Array containing the multiple value
|
|
1104
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
1105
|
+
*
|
|
1106
|
+
*
|
|
1107
|
+
* @public
|
|
1108
|
+
*/
|
|
1109
|
+
MultipleOf: ValidatorRuleParams<[number]>;
|
|
1110
|
+
/**
|
|
1111
|
+
* ### Odd Number Rule
|
|
1112
|
+
*
|
|
1113
|
+
* Validates that the field under validation is an integer and odd (not divisible by 2).
|
|
1114
|
+
* Non-numeric inputs or non-integer numbers will be rejected with precise messages.
|
|
1115
|
+
*
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```typescript
|
|
1118
|
+
* // Valid examples
|
|
1119
|
+
* await Validator.validate({ value: 1, rules: ['OddNumber'] }); // ✓
|
|
1120
|
+
* await Validator.validate({ value: '7', rules: ['OddNumber'] }); // ✓ numeric string
|
|
1121
|
+
* await Validator.validate({ value: -5, rules: ['OddNumber'] }); // ✓ negative odd
|
|
1122
|
+
*
|
|
1123
|
+
* // Invalid examples
|
|
1124
|
+
* await Validator.validate({ value: 4, rules: ['OddNumber'] }); // ✗ even
|
|
1125
|
+
* await Validator.validate({ value: 3.14, rules: ['OddNumber'] }); // ✗ not integer
|
|
1126
|
+
* await Validator.validate({ value: 'abc', rules: ['OddNumber'] }); // ✗ not numeric
|
|
1127
|
+
* ```
|
|
1128
|
+
*
|
|
1129
|
+
* @returns true if valid, rejecting with error message if invalid
|
|
1130
|
+
*
|
|
1131
|
+
* @public
|
|
1132
|
+
*/
|
|
1133
|
+
OddNumber: ValidatorRuleParams<[]>;
|
|
1134
|
+
}
|
|
1135
|
+
}
|