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,551 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary A validation decorator that ensures a property contains a valid date value.
|
|
3
|
+
* @description
|
|
4
|
+
* Validates that the decorated property represents a date that can be parsed into a JavaScript Date object.
|
|
5
|
+
* Accepts Date instances, ISO date strings, and numeric timestamps as valid inputs.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* class Event {
|
|
10
|
+
* @IsDate()
|
|
11
|
+
* eventDate: Date;
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* const event = new Event();
|
|
15
|
+
* event.eventDate = new Date(); // ✓ Valid
|
|
16
|
+
* event.eventDate = '2024-01-01'; // ✓ Valid
|
|
17
|
+
* event.eventDate = 1640995200000; // ✓ Valid (timestamp)
|
|
18
|
+
* event.eventDate = 'invalid'; // ✗ Invalid
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @returns A property decorator function for date validation.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const IsDate: () => PropertyDecorator;
|
|
26
|
+
/**
|
|
27
|
+
* @summary A validation decorator that ensures a date property occurs after a specified reference date.
|
|
28
|
+
* @description
|
|
29
|
+
* Validates that the decorated property's date value is strictly greater than the provided comparison date.
|
|
30
|
+
* Useful for ensuring events or deadlines occur after a minimum date.
|
|
31
|
+
*
|
|
32
|
+
* @param date - The reference date to compare against. Accepts Date object, ISO string, or timestamp.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* class Event {
|
|
37
|
+
* @IsDateAfter(new Date('2024-01-01'))
|
|
38
|
+
* eventDate: Date;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* const event = new Event();
|
|
42
|
+
* event.eventDate = new Date('2024-01-02'); // ✓ Valid (after reference)
|
|
43
|
+
* event.eventDate = '2024-06-15'; // ✓ Valid
|
|
44
|
+
* event.eventDate = new Date('2023-12-31'); // ✗ Invalid (before reference)
|
|
45
|
+
* event.eventDate = '2024-01-01'; // ✗ Invalid (same date, not after)
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @returns A property decorator function for date-after validation.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare const IsDateAfter: (date: ValidatorDate) => PropertyDecorator;
|
|
53
|
+
/**
|
|
54
|
+
* @summary A validation decorator that ensures a date property occurs before a specified reference date.
|
|
55
|
+
* @description
|
|
56
|
+
* Validates that the decorated property's date value is strictly less than the provided comparison date.
|
|
57
|
+
* Useful for ensuring submissions or events occur before a maximum deadline.
|
|
58
|
+
*
|
|
59
|
+
* @param date - The reference date to compare against. Accepts Date object, ISO string, or timestamp.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* class Deadline {
|
|
64
|
+
* @IsDateBefore(new Date('2024-12-31'))
|
|
65
|
+
* submissionDate: Date;
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* const deadline = new Deadline();
|
|
69
|
+
* deadline.submissionDate = new Date('2024-12-30'); // ✓ Valid (before reference)
|
|
70
|
+
* deadline.submissionDate = '2024-06-15'; // ✓ Valid
|
|
71
|
+
* deadline.submissionDate = new Date('2025-01-01'); // ✗ Invalid (after reference)
|
|
72
|
+
* deadline.submissionDate = '2024-12-31'; // ✗ Invalid (same date, not before)
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @returns A property decorator function for date-before validation.
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export declare const IsDateBefore: (date: ValidatorDate) => PropertyDecorator;
|
|
80
|
+
/**
|
|
81
|
+
* @summary A validation decorator that ensures a date property falls within a specified date range.
|
|
82
|
+
* @description
|
|
83
|
+
* Validates that the decorated property's date value is between the start and end dates (inclusive).
|
|
84
|
+
* Useful for restricting dates to specific periods like vacation seasons or business quarters.
|
|
85
|
+
*
|
|
86
|
+
* @param minDate - The earliest allowed date in the range. Accepts Date object, ISO string, or timestamp.
|
|
87
|
+
* @param maxDate - The latest allowed date in the range. Accepts Date object, ISO string, or timestamp.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* class Vacation {
|
|
92
|
+
* @IsDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
|
|
93
|
+
* vacationDate: Date;
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* const vacation = new Vacation();
|
|
97
|
+
* vacation.vacationDate = new Date('2024-06-15'); // ✓ Valid (within range)
|
|
98
|
+
* vacation.vacationDate = '2024-01-01'; // ✓ Valid (inclusive start)
|
|
99
|
+
* vacation.vacationDate = '2024-12-31'; // ✓ Valid (inclusive end)
|
|
100
|
+
* vacation.vacationDate = new Date('2023-12-31'); // ✗ Invalid (before range)
|
|
101
|
+
* vacation.vacationDate = '2025-01-01'; // ✗ Invalid (after range)
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @returns A property decorator function for date-between validation.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
export declare const IsDateBetween: (minDate: ValidatorDate, maxDate: ValidatorDate) => PropertyDecorator;
|
|
109
|
+
/**
|
|
110
|
+
* @summary A validation decorator that ensures a date property matches a specific date (ignoring time).
|
|
111
|
+
* @description
|
|
112
|
+
* Validates that the decorated property's date value matches the reference date, comparing only
|
|
113
|
+
* year, month, and day components while ignoring hours, minutes, seconds, and milliseconds.
|
|
114
|
+
* Useful for date-only equality checks like birthdays or anniversaries.
|
|
115
|
+
*
|
|
116
|
+
* @param date - The reference date to match against. Accepts Date object, ISO string, or timestamp.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* class Birthday {
|
|
121
|
+
* @IsSameDate(new Date('1990-01-01'))
|
|
122
|
+
* birthDate: Date;
|
|
123
|
+
* }
|
|
124
|
+
*
|
|
125
|
+
* const birthday = new Birthday();
|
|
126
|
+
* birthday.birthDate = new Date('1990-01-01T10:30:00Z'); // ✓ Valid (time ignored)
|
|
127
|
+
* birthday.birthDate = '1990-01-01'; // ✓ Valid
|
|
128
|
+
* birthday.birthDate = new Date('1990-01-02T00:00:00Z'); // ✗ Invalid (different date)
|
|
129
|
+
* birthday.birthDate = '1990-01-02'; // ✗ Invalid
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @returns A property decorator function for same-date validation.
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
export declare const IsSameDate: (date: ValidatorDate) => PropertyDecorator;
|
|
137
|
+
/**
|
|
138
|
+
* @summary A validation decorator that ensures a date property is in the future.
|
|
139
|
+
* @description
|
|
140
|
+
* Validates that the decorated property's date value occurs after the current moment.
|
|
141
|
+
* Useful for validating future events, appointments, or deadlines that haven't passed yet.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* class Appointment {
|
|
146
|
+
* @IsFutureDate()
|
|
147
|
+
* appointmentDate: Date;
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* const appointment = new Appointment();
|
|
151
|
+
* appointment.appointmentDate = new Date(Date.now() + 86400000); // Tomorrow - ✓ Valid
|
|
152
|
+
* appointment.appointmentDate = '2025-01-01'; // ✓ Valid
|
|
153
|
+
* appointment.appointmentDate = new Date(Date.now() - 86400000); // Yesterday - ✗ Invalid
|
|
154
|
+
* appointment.appointmentDate = new Date(); // Now - ✗ Invalid (not strictly future)
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @returns A property decorator function for future-date validation.
|
|
158
|
+
*
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
export declare const IsFutureDate: () => PropertyDecorator;
|
|
162
|
+
/**
|
|
163
|
+
* @summary A validation decorator that ensures a date property is in the past.
|
|
164
|
+
* @description
|
|
165
|
+
* Validates that the decorated property's date value occurs before the current moment.
|
|
166
|
+
* Useful for validating historical events, past occurrences, or completed deadlines.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* class HistoricalEvent {
|
|
171
|
+
* @IsPastDate()
|
|
172
|
+
* eventDate: Date;
|
|
173
|
+
* }
|
|
174
|
+
*
|
|
175
|
+
* const event = new HistoricalEvent();
|
|
176
|
+
* event.eventDate = new Date(Date.now() - 86400000); // Yesterday - ✓ Valid
|
|
177
|
+
* event.eventDate = '2020-01-01'; // ✓ Valid
|
|
178
|
+
* event.eventDate = new Date(Date.now() + 86400000); // Tomorrow - ✗ Invalid
|
|
179
|
+
* event.eventDate = new Date(); // Now - ✗ Invalid (not strictly past)
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @returns A property decorator function for past-date validation.
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
export declare const IsPastDate: () => PropertyDecorator;
|
|
187
|
+
declare module '../types' {
|
|
188
|
+
interface ValidatorRuleParamTypes {
|
|
189
|
+
/**
|
|
190
|
+
* @summary Validates that the field contains a valid date value.
|
|
191
|
+
* @description
|
|
192
|
+
* Ensures the input represents a valid date that can be parsed into a JavaScript Date object.
|
|
193
|
+
* Accepts Date instances, ISO date strings, and numeric timestamps.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* // Valid date inputs
|
|
198
|
+
* await Validator.validate({
|
|
199
|
+
* value: new Date(),
|
|
200
|
+
* rules: ['Date']
|
|
201
|
+
* }); // ✓ Valid
|
|
202
|
+
*
|
|
203
|
+
* await Validator.validate({
|
|
204
|
+
* value: '2024-01-01T10:30:00Z',
|
|
205
|
+
* rules: ['Date']
|
|
206
|
+
* }); // ✓ Valid
|
|
207
|
+
*
|
|
208
|
+
* await Validator.validate({
|
|
209
|
+
* value: 1640995200000, // Unix timestamp
|
|
210
|
+
* rules: ['Date']
|
|
211
|
+
* }); // ✓ Valid
|
|
212
|
+
*
|
|
213
|
+
* // Invalid inputs
|
|
214
|
+
* await Validator.validate({
|
|
215
|
+
* value: 'invalid-date-string',
|
|
216
|
+
* rules: ['Date']
|
|
217
|
+
* }); // ✗ Invalid
|
|
218
|
+
*
|
|
219
|
+
* await Validator.validate({
|
|
220
|
+
* value: null,
|
|
221
|
+
* rules: ['Date']
|
|
222
|
+
* }); // ✗ Invalid
|
|
223
|
+
*
|
|
224
|
+
* await Validator.validate({
|
|
225
|
+
* value: {},
|
|
226
|
+
* rules: ['Date']
|
|
227
|
+
* }); // ✗ Invalid
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Class validation usage
|
|
233
|
+
* class Event {
|
|
234
|
+
* @IsRequired()
|
|
235
|
+
* @IsDate()
|
|
236
|
+
* eventDate: Date;
|
|
237
|
+
* }
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @public
|
|
241
|
+
*/
|
|
242
|
+
Date: ValidatorRuleParams<[]>;
|
|
243
|
+
/**
|
|
244
|
+
* @summary Validates that the date occurs after a specified reference date.
|
|
245
|
+
* @description
|
|
246
|
+
* Checks if the input date is strictly greater than the provided comparison date.
|
|
247
|
+
* Both dates are converted to Date objects for comparison.
|
|
248
|
+
*
|
|
249
|
+
* @param date - The reference date to compare against. Accepts Date object, ISO string, or timestamp.
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* // Valid examples (date must be after reference)
|
|
254
|
+
* await Validator.validate({
|
|
255
|
+
* value: new Date('2024-01-02'),
|
|
256
|
+
* rules: ['DateAfter[2024-01-01]']
|
|
257
|
+
* }); // ✓ Valid
|
|
258
|
+
*
|
|
259
|
+
* await Validator.validate({
|
|
260
|
+
* value: '2024-06-15T12:00:00Z',
|
|
261
|
+
* rules: ['DateAfter[2024-01-01]']
|
|
262
|
+
* }); // ✓ Valid
|
|
263
|
+
*
|
|
264
|
+
* // Invalid examples
|
|
265
|
+
* await Validator.validate({
|
|
266
|
+
* value: new Date('2023-12-31'),
|
|
267
|
+
* rules: ['DateAfter[2024-01-01]']
|
|
268
|
+
* }); // ✗ Invalid (before reference)
|
|
269
|
+
*
|
|
270
|
+
* await Validator.validate({
|
|
271
|
+
* value: '2024-01-01T23:59:59Z',
|
|
272
|
+
* rules: ['DateAfter[2024-01-01]']
|
|
273
|
+
* }); // ✗ Invalid (same date, not after)
|
|
274
|
+
*
|
|
275
|
+
* await Validator.validate({
|
|
276
|
+
* value: 'invalid-date',
|
|
277
|
+
* rules: ['DateAfter[2024-01-01]']
|
|
278
|
+
* }); // ✗ Invalid (invalid input date)
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* // Class validation with dynamic reference
|
|
284
|
+
* class Event {
|
|
285
|
+
* @IsDateAfter(new Date('2024-01-01'))
|
|
286
|
+
* eventDate: Date;
|
|
287
|
+
* }
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
DateAfter: ValidatorRuleParams<[date: ValidatorDate]>;
|
|
293
|
+
/**
|
|
294
|
+
* @summary Validates that the date occurs before a specified reference date.
|
|
295
|
+
* @description
|
|
296
|
+
* Checks if the input date is strictly less than the provided comparison date.
|
|
297
|
+
* Both dates are converted to Date objects for comparison.
|
|
298
|
+
*
|
|
299
|
+
* @param date - The reference date to compare against. Accepts Date object, ISO string, or timestamp.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```typescript
|
|
303
|
+
* // Valid examples (date must be before reference)
|
|
304
|
+
* await Validator.validate({
|
|
305
|
+
* value: new Date('2023-12-31'),
|
|
306
|
+
* rules: ['DateBefore[2024-01-01]']
|
|
307
|
+
* }); // ✓ Valid
|
|
308
|
+
*
|
|
309
|
+
* await Validator.validate({
|
|
310
|
+
* value: '2023-06-15T12:00:00Z',
|
|
311
|
+
* rules: ['DateBefore[2024-01-01]']
|
|
312
|
+
* }); // ✓ Valid
|
|
313
|
+
*
|
|
314
|
+
* // Invalid examples
|
|
315
|
+
* await Validator.validate({
|
|
316
|
+
* value: new Date('2024-01-02'),
|
|
317
|
+
* rules: ['DateBefore[2024-01-01]']
|
|
318
|
+
* }); // ✗ Invalid (after reference)
|
|
319
|
+
*
|
|
320
|
+
* await Validator.validate({
|
|
321
|
+
* value: '2024-01-01T00:00:01Z',
|
|
322
|
+
* rules: ['DateBefore[2024-01-01]']
|
|
323
|
+
* }); // ✗ Invalid (same date, not before)
|
|
324
|
+
*
|
|
325
|
+
* await Validator.validate({
|
|
326
|
+
* value: 'invalid-date',
|
|
327
|
+
* rules: ['DateBefore[2024-01-01]']
|
|
328
|
+
* }); // ✗ Invalid (invalid input date)
|
|
329
|
+
* ```
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* // Class validation with deadline
|
|
334
|
+
* class Deadline {
|
|
335
|
+
* @IsDateBefore(new Date('2024-12-31'))
|
|
336
|
+
* submissionDate: Date;
|
|
337
|
+
* }
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @public
|
|
341
|
+
*/
|
|
342
|
+
DateBefore: ValidatorRuleParams<[date: ValidatorDate]>;
|
|
343
|
+
/**
|
|
344
|
+
* @summary Validates that the date falls within a specified date range (inclusive).
|
|
345
|
+
* @description
|
|
346
|
+
* Checks if the input date is greater than or equal to the start date and
|
|
347
|
+
* less than or equal to the end date. All dates are converted to Date objects.
|
|
348
|
+
*
|
|
349
|
+
* @param minDate - The minimum/earliest allowed date. Accepts Date object, ISO string, or timestamp.
|
|
350
|
+
* @param maxDate - The maximum/latest allowed date. Accepts Date object, ISO string, or timestamp.
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```typescript
|
|
354
|
+
* // Valid examples (within range inclusive)
|
|
355
|
+
* await Validator.validate({
|
|
356
|
+
* value: new Date('2024-06-15'),
|
|
357
|
+
* rules: ['DateBetween[2024-01-01,2024-12-31]']
|
|
358
|
+
* }); // ✓ Valid
|
|
359
|
+
*
|
|
360
|
+
* await Validator.validate({
|
|
361
|
+
* value: '2024-01-01T00:00:00Z', // Start boundary
|
|
362
|
+
* rules: ['DateBetween[2024-01-01,2024-12-31]']
|
|
363
|
+
* }); // ✓ Valid
|
|
364
|
+
*
|
|
365
|
+
* await Validator.validate({
|
|
366
|
+
* value: '2024-12-31T23:59:59Z', // End boundary
|
|
367
|
+
* rules: ['DateBetween[2024-01-01,2024-12-31]']
|
|
368
|
+
* }); // ✓ Valid
|
|
369
|
+
*
|
|
370
|
+
* // Invalid examples
|
|
371
|
+
* await Validator.validate({
|
|
372
|
+
* value: new Date('2023-12-31'),
|
|
373
|
+
* rules: ['DateBetween[2024-01-01,2024-12-31]']
|
|
374
|
+
* }); // ✗ Invalid (before range)
|
|
375
|
+
*
|
|
376
|
+
* await Validator.validate({
|
|
377
|
+
* value: '2025-01-01',
|
|
378
|
+
* rules: ['DateBetween[2024-01-01,2024-12-31]']
|
|
379
|
+
* }); // ✗ Invalid (after range)
|
|
380
|
+
*
|
|
381
|
+
* await Validator.validate({
|
|
382
|
+
* value: 'invalid-date',
|
|
383
|
+
* rules: ['DateBetween[2024-01-01,2024-12-31]']
|
|
384
|
+
* }); // ✗ Invalid (invalid input date)
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* // Class validation for vacation period
|
|
390
|
+
* class Vacation {
|
|
391
|
+
* @IsDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
|
|
392
|
+
* vacationDate: Date;
|
|
393
|
+
* }
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* @public
|
|
397
|
+
*/
|
|
398
|
+
DateBetween: ValidatorRuleParams<[
|
|
399
|
+
minDate: ValidatorDate,
|
|
400
|
+
maxDate: ValidatorDate
|
|
401
|
+
]>;
|
|
402
|
+
/**
|
|
403
|
+
* @summary Validates that the date matches a specific date (ignoring time components).
|
|
404
|
+
* @description
|
|
405
|
+
* Compares only the date parts (year, month, day) of the input and reference dates,
|
|
406
|
+
* ignoring hours, minutes, seconds, and milliseconds. Useful for date-only equality checks.
|
|
407
|
+
*
|
|
408
|
+
* @param date - The reference date to match against. Accepts Date object, ISO string, or timestamp.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```typescript
|
|
412
|
+
* // Valid examples (same date regardless of time)
|
|
413
|
+
* await Validator.validate({
|
|
414
|
+
* value: new Date('2024-01-01T10:30:45Z'),
|
|
415
|
+
* rules: ['SameDate[2024-01-01]']
|
|
416
|
+
* }); // ✓ Valid (time ignored)
|
|
417
|
+
*
|
|
418
|
+
* await Validator.validate({
|
|
419
|
+
* value: '2024-01-01',
|
|
420
|
+
* rules: ['SameDate[2024-01-01T23:59:59Z]']
|
|
421
|
+
* }); // ✓ Valid (time ignored)
|
|
422
|
+
*
|
|
423
|
+
* // Invalid examples
|
|
424
|
+
* await Validator.validate({
|
|
425
|
+
* value: new Date('2024-01-02T00:00:00Z'),
|
|
426
|
+
* rules: ['SameDate[2024-01-01]']
|
|
427
|
+
* }); // ✗ Invalid (different date)
|
|
428
|
+
*
|
|
429
|
+
* await Validator.validate({
|
|
430
|
+
* value: '2024-01-01T10:30:00Z',
|
|
431
|
+
* rules: ['SameDate[2024-01-02]']
|
|
432
|
+
* }); // ✗ Invalid (different date)
|
|
433
|
+
*
|
|
434
|
+
* await Validator.validate({
|
|
435
|
+
* value: 'invalid-date',
|
|
436
|
+
* rules: ['SameDate[2024-01-01]']
|
|
437
|
+
* }); // ✗ Invalid (invalid input date)
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* // Class validation for specific birthday
|
|
443
|
+
* class Birthday {
|
|
444
|
+
* @IsSameDate(new Date('1990-01-01'))
|
|
445
|
+
* birthDate: Date;
|
|
446
|
+
* }
|
|
447
|
+
* ```
|
|
448
|
+
*
|
|
449
|
+
* @public
|
|
450
|
+
*/
|
|
451
|
+
SameDate: ValidatorRuleParams<[date: ValidatorDate]>;
|
|
452
|
+
/**
|
|
453
|
+
* @summary Validates that the date is in the future relative to the current time.
|
|
454
|
+
* @description
|
|
455
|
+
* Checks if the input date occurs after the current moment (now).
|
|
456
|
+
* Useful for validating future events, deadlines, or appointments.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* // Valid examples (future dates)
|
|
461
|
+
* await Validator.validate({
|
|
462
|
+
* value: new Date(Date.now() + 86400000), // Tomorrow
|
|
463
|
+
* rules: ['FutureDate']
|
|
464
|
+
* }); // ✓ Valid
|
|
465
|
+
*
|
|
466
|
+
* await Validator.validate({
|
|
467
|
+
* value: '2025-01-01T00:00:00Z',
|
|
468
|
+
* rules: ['FutureDate']
|
|
469
|
+
* }); // ✓ Valid
|
|
470
|
+
*
|
|
471
|
+
* // Invalid examples
|
|
472
|
+
* await Validator.validate({
|
|
473
|
+
* value: new Date(Date.now() - 86400000), // Yesterday
|
|
474
|
+
* rules: ['FutureDate']
|
|
475
|
+
* }); // ✗ Invalid (past date)
|
|
476
|
+
*
|
|
477
|
+
* await Validator.validate({
|
|
478
|
+
* value: new Date(), // Current time
|
|
479
|
+
* rules: ['FutureDate']
|
|
480
|
+
* }); // ✗ Invalid (not strictly future)
|
|
481
|
+
*
|
|
482
|
+
* await Validator.validate({
|
|
483
|
+
* value: 'invalid-date',
|
|
484
|
+
* rules: ['FutureDate']
|
|
485
|
+
* }); // ✗ Invalid (invalid input date)
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* // Class validation for future appointments
|
|
491
|
+
* class Appointment {
|
|
492
|
+
* @IsFutureDate()
|
|
493
|
+
* appointmentDate: Date;
|
|
494
|
+
* }
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* @public
|
|
498
|
+
*/
|
|
499
|
+
FutureDate: ValidatorRuleParams<[]>;
|
|
500
|
+
/**
|
|
501
|
+
* @summary Validates that the date is in the past relative to the current time.
|
|
502
|
+
* @description
|
|
503
|
+
* Checks if the input date occurs before the current moment (now).
|
|
504
|
+
* Useful for validating historical events or past occurrences.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* // Valid examples (past dates)
|
|
509
|
+
* await Validator.validate({
|
|
510
|
+
* value: new Date(Date.now() - 86400000), // Yesterday
|
|
511
|
+
* rules: ['PastDate']
|
|
512
|
+
* }); // ✓ Valid
|
|
513
|
+
*
|
|
514
|
+
* await Validator.validate({
|
|
515
|
+
* value: '2020-01-01T00:00:00Z',
|
|
516
|
+
* rules: ['PastDate']
|
|
517
|
+
* }); // ✓ Valid
|
|
518
|
+
*
|
|
519
|
+
* // Invalid examples
|
|
520
|
+
* await Validator.validate({
|
|
521
|
+
* value: new Date(Date.now() + 86400000), // Tomorrow
|
|
522
|
+
* rules: ['PastDate']
|
|
523
|
+
* }); // ✗ Invalid (future date)
|
|
524
|
+
*
|
|
525
|
+
* await Validator.validate({
|
|
526
|
+
* value: new Date(), // Current time
|
|
527
|
+
* rules: ['PastDate']
|
|
528
|
+
* }); // ✗ Invalid (not strictly past)
|
|
529
|
+
*
|
|
530
|
+
* await Validator.validate({
|
|
531
|
+
* value: 'invalid-date',
|
|
532
|
+
* rules: ['PastDate']
|
|
533
|
+
* }); // ✗ Invalid (invalid input date)
|
|
534
|
+
* ```
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* // Class validation for historical events
|
|
539
|
+
* class HistoricalEvent {
|
|
540
|
+
* @IsPastDate()
|
|
541
|
+
* eventDate: Date;
|
|
542
|
+
* }
|
|
543
|
+
* ```
|
|
544
|
+
*
|
|
545
|
+
* @public
|
|
546
|
+
*/
|
|
547
|
+
PastDate: ValidatorRuleParams<[]>;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
type ValidatorDate = string | Date | number;
|
|
551
|
+
export {};
|