@bolttech/form-engine-core 1.1.0-beta.0 → 1.1.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/CHANGELOG.md +16 -0
- package/credit-card.d.ts +743 -0
- package/credit-card.esm.js +1 -0
- package/currency.d.ts +131 -0
- package/currency.esm.js +1 -0
- package/date.d.ts +582 -0
- package/date.esm.js +1 -0
- package/document.d.ts +527 -0
- package/document.esm.js +1 -0
- package/index.d.ts +2393 -0
- package/index.esm.js +1 -4435
- package/lite.d.ts +2393 -0
- package/lite.esm.js +1 -0
- package/package.json +41 -10
- package/src/constants/constants.d.ts +2 -1
- package/src/helpers/SafeSubject.d.ts +12 -2
- package/src/helpers/helpers.d.ts +6 -6
- package/src/helpers/lodash-replacements.d.ts +41 -0
- package/src/helpers/validation.d.ts +2 -1
- package/src/index.d.ts +5 -0
- package/src/interfaces/schema.d.ts +28 -1
- package/src/lite.d.ts +30 -0
- package/src/managers/field.d.ts +17 -3
- package/src/managers/form.d.ts +7 -2
- package/src/masks/currency.d.ts +29 -0
- package/src/masks/handler.d.ts +1 -1
- package/src/masks/string.d.ts +0 -62
- package/src/plugins/credit-card.d.ts +4 -0
- package/src/plugins/currency.d.ts +2 -0
- package/src/plugins/date.d.ts +2 -0
- package/src/plugins/document.d.ts +2 -0
- package/src/registry.d.ts +20 -0
- package/src/types/schema.d.ts +42 -23
- package/src/types/utility.d.ts +7 -4
- package/src/validations/custom.d.ts +3 -1
- package/index.esm.d.ts +0 -1
package/credit-card.d.ts
ADDED
|
@@ -0,0 +1,743 @@
|
|
|
1
|
+
import { TCurrencyCode, TCurrencyLocalCode } from '@gaignoux/currency';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type TFormValues<T>
|
|
5
|
+
* Represents the values and state of a form. It has a generic type that allows the importer to determine which type values key will return.
|
|
6
|
+
*
|
|
7
|
+
* @property {Generic Type} values - The current values of the form fields.
|
|
8
|
+
* @property {string[]} erroredFields - A list of field names that have errors.
|
|
9
|
+
* @property {boolean} isValid - Indicates whether the form is valid.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const formValues: TFormValues = {
|
|
14
|
+
* values: { name: 'John', age: 30 },
|
|
15
|
+
* erroredFields: ['email'],
|
|
16
|
+
* isValid: false
|
|
17
|
+
* };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
type TFormValues<T> = {
|
|
21
|
+
values: T;
|
|
22
|
+
metadata: unknown;
|
|
23
|
+
erroredFields: string[];
|
|
24
|
+
isValid: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** @virtual */
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @type TLengthValidation
|
|
31
|
+
* Represents the validation rules based on the length of the input.
|
|
32
|
+
*
|
|
33
|
+
* @property {'equal' | 'notEqual' | 'less' | 'lessOrEqual' | 'greater' | 'greaterOrEqual'} rule - The rule to apply.
|
|
34
|
+
* @property {number} target - The target value to compare against.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const lengthValidation: TLengthValidation = { rule: 'greaterOrEqual', target: 8 };
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
type TLengthValidation = {
|
|
42
|
+
rule: 'equal' | 'notEqual' | 'less' | 'lessOrEqual' | 'greater' | 'greaterOrEqual';
|
|
43
|
+
target: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @type TCallbackValidation
|
|
47
|
+
* A custom validation function.
|
|
48
|
+
*
|
|
49
|
+
* @param {unknown} value - The value to validate.
|
|
50
|
+
* @returns {boolean} - The result of the validation.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const callbackValidation: TCallbackValidation = (value) => typeof value === 'string';
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
type TCallbackValidation = (value: unknown, formValues: Pick<TFormValues<unknown>, 'values' | 'metadata'>) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @type TBetweenValidation
|
|
60
|
+
* Represents validation rules that check if a value is between a range.
|
|
61
|
+
*
|
|
62
|
+
* @property {number} start - The start of the range.
|
|
63
|
+
* @property {number} end - The end of the range.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const betweenValidation: TBetweenValidation = { start: 1, end: 10 };
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
type TBetweenValidation = {
|
|
71
|
+
start: number;
|
|
72
|
+
end: number;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* @type TCreditCardMatch
|
|
76
|
+
* Represents the options for credit card matching.
|
|
77
|
+
*
|
|
78
|
+
* @property {string} numberCard - The credit card number.
|
|
79
|
+
* @property {string[]} availableOptions - The available options for matching.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const creditCardMatch: TCreditCardMatch = { numberCard: '1234', availableOptions: ['Visa', 'MasterCard'] };
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
type TCreditCardMatch = {
|
|
87
|
+
numberCard: string;
|
|
88
|
+
availableOptions: string[];
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @type TDocumentValidation
|
|
92
|
+
* Represents validation for specific document types.
|
|
93
|
+
*
|
|
94
|
+
* @property {'NIF' | 'NIE' | 'CIF' | 'IBAN'} type - The type of document.
|
|
95
|
+
* @property {TCurrencyLocalCode} [locale] - The locale code for validation.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const documentValidation: TDocumentValidation = { type: 'NIF', locale: 'ES' };
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
type TDocumentValidation = {
|
|
103
|
+
type: 'NIF' | 'NIE' | 'CIF' | 'IBAN';
|
|
104
|
+
locale?: TCurrencyLocalCode;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* @type TDateOperatorsValidation
|
|
108
|
+
* Represents the operators used for date validation conditions.
|
|
109
|
+
*
|
|
110
|
+
* @property {'<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin'}
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const operator: TDateOperatorsValidation = '<';
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
type TDateOperatorsValidation = '<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin';
|
|
118
|
+
/**
|
|
119
|
+
* @type TConditionsValidationSet
|
|
120
|
+
* Represents a single validation condition set.
|
|
121
|
+
*
|
|
122
|
+
* @property {boolean} [forceDefinedOrigin] - Flag to force the origin value to be defined.
|
|
123
|
+
* @property {boolean} [forceDefinedTarget] - Flag to force the target value to be defined.
|
|
124
|
+
* @property {string | number | boolean} [origin] - The origin value for the condition.
|
|
125
|
+
* @property {TDateOperatorsValidation} condition - The validation condition operator.
|
|
126
|
+
* @property {string | number | boolean} [target] - The target value for the condition.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const conditionSet: TConditionsValidationSet = {
|
|
131
|
+
* forceDefinedOrigin: true,
|
|
132
|
+
* forceDefinedTarget: true,
|
|
133
|
+
* origin: '2023-01-01',
|
|
134
|
+
* condition: '>',
|
|
135
|
+
* target: '2022-01-01'
|
|
136
|
+
* };
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
type TConditionsValidationSet = {
|
|
140
|
+
forceDefinedOrigin?: boolean;
|
|
141
|
+
forceDefinedTarget?: boolean;
|
|
142
|
+
origin?: string | number | boolean | null;
|
|
143
|
+
condition: TDateOperatorsValidation;
|
|
144
|
+
target?: string | number | boolean;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* @type TConditionsValidation
|
|
148
|
+
* Represents a set of validation conditions.
|
|
149
|
+
*
|
|
150
|
+
* @property {'and' | 'or'} rule - The logical rule to combine the conditions (AND/OR).
|
|
151
|
+
* @property {TConditionsValidationSet[]} set - The array of validation condition sets.
|
|
152
|
+
* @property {TConditionsValidation} [conditions] - Nested conditions for more complex validation logic.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const conditionsValidation: TConditionsValidation = {
|
|
157
|
+
* rule: 'and',
|
|
158
|
+
* set: [
|
|
159
|
+
* {
|
|
160
|
+
* forceDefinedOrigin: true,
|
|
161
|
+
* forceDefinedTarget: true,
|
|
162
|
+
* origin: '2023-01-01',
|
|
163
|
+
* condition: '>',
|
|
164
|
+
* target: '2022-01-01'
|
|
165
|
+
* }
|
|
166
|
+
* ],
|
|
167
|
+
* conditions: {
|
|
168
|
+
* rule: 'or',
|
|
169
|
+
* set: [
|
|
170
|
+
* {
|
|
171
|
+
* origin: true,
|
|
172
|
+
* condition: '!!origin',
|
|
173
|
+
* target: false
|
|
174
|
+
* }
|
|
175
|
+
* ]
|
|
176
|
+
* }
|
|
177
|
+
* };
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
type TConditionsValidation = {
|
|
181
|
+
rule: 'and' | 'or';
|
|
182
|
+
set: TConditionsValidationSet[];
|
|
183
|
+
conditions?: TConditionsValidation;
|
|
184
|
+
};
|
|
185
|
+
type TAvailableValidations = Omit<TValidationMethods, 'multipleValidations'> | TGenericValidationRule;
|
|
186
|
+
/**
|
|
187
|
+
* @type TMultipleValidation
|
|
188
|
+
* Represents a set of multiple validation methods combined with a logical rule.
|
|
189
|
+
*
|
|
190
|
+
* @property {'AND' | 'OR' | 'NOT'} rule - The logical rule to combine the validation methods (AND, OR, NOT).
|
|
191
|
+
* @property {TAvailableValidations} validations - The validation methods to be combined.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const multipleValidation: TMultipleValidation = {
|
|
196
|
+
* rule: 'AND',
|
|
197
|
+
* validations: {
|
|
198
|
+
* required: true,
|
|
199
|
+
* min: 5,
|
|
200
|
+
* max: 10
|
|
201
|
+
* }
|
|
202
|
+
* };
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
type TMultipleValidation = {
|
|
206
|
+
rule: 'AND' | 'OR' | 'NOT';
|
|
207
|
+
validations: TAvailableValidations;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* @type TBetweenDatesValidation
|
|
211
|
+
* Represents a validation method to check if a value falls between specified dates.
|
|
212
|
+
*
|
|
213
|
+
* @property {TDateValidation[]} [TBetweenDatesValidation] - An array of date validation methods.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const betweenDatesValidation: TBetweenDatesValidation = [
|
|
218
|
+
* {
|
|
219
|
+
* onlyValidDate: true,
|
|
220
|
+
* operator: '>=',
|
|
221
|
+
* origin: {
|
|
222
|
+
* format: 'MMDDYYYY',
|
|
223
|
+
* intervals: {
|
|
224
|
+
* years: 1
|
|
225
|
+
* }
|
|
226
|
+
* },
|
|
227
|
+
* target: {
|
|
228
|
+
* value: Date.now(),
|
|
229
|
+
* format: 'timestamp',
|
|
230
|
+
* value: '01/01/2023',
|
|
231
|
+
* }
|
|
232
|
+
* },
|
|
233
|
+
* {
|
|
234
|
+
* onlyValidDate: true,
|
|
235
|
+
* operator: '<=',
|
|
236
|
+
* origin: {
|
|
237
|
+
* format: 'MMDDYYYY',
|
|
238
|
+
* intervals: {
|
|
239
|
+
* years: 1
|
|
240
|
+
* }
|
|
241
|
+
* },
|
|
242
|
+
* target: {
|
|
243
|
+
* format: 'timestamp',
|
|
244
|
+
* value: '31/12/2023',
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* ];
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
type TBetweenDatesValidation = TDateValidation[];
|
|
251
|
+
/**
|
|
252
|
+
* @type TDateFormatsValidation
|
|
253
|
+
* Represents the supported date formats for validation.
|
|
254
|
+
*
|
|
255
|
+
* @type {'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp'}
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const dateFormat: TDateFormatsValidation = 'MMDDYYYY';
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
type TDateFormatsValidation = 'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp';
|
|
263
|
+
type TDateInterval = {
|
|
264
|
+
years?: number;
|
|
265
|
+
months?: number;
|
|
266
|
+
days?: number;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* @type TDateValidation
|
|
270
|
+
* Represents a validation method for date values.
|
|
271
|
+
*
|
|
272
|
+
* @property {boolean} [onlyValidDate] - Flag to validate only if the date is valid.
|
|
273
|
+
* @property {TDateOperatorsValidation} operator - The validation operator to be used.
|
|
274
|
+
* @property {Object} origin - The origin date configuration.
|
|
275
|
+
* @property {string | number} [origin.value] - The origin date value.
|
|
276
|
+
* @property {TDateFormatsValidation} origin.format - The format of the origin date.
|
|
277
|
+
* @property {Object} [origin.intervals] - The intervals to add to the origin date for comparison.
|
|
278
|
+
* @property {number} [origin.intervals.years] - The number of years to add.
|
|
279
|
+
* @property {number} [origin.intervals.months] - The number of months to add.
|
|
280
|
+
* @property {number} [origin.intervals.days] - The number of days to add.
|
|
281
|
+
* @property {Object} [target] - The target date configuration.
|
|
282
|
+
* @property {string | number} target.value - The target date value.
|
|
283
|
+
* @property {TDateFormatsValidation} target.format - The format of the target date.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* const dateValidation: TDateValidation = {
|
|
288
|
+
* onlyValidDate: true,
|
|
289
|
+
* operator: '===',
|
|
290
|
+
* origin: {
|
|
291
|
+
* value: '10/10/2022',
|
|
292
|
+
* format: 'MMDDYYYY',
|
|
293
|
+
* intervals: {
|
|
294
|
+
* years: 1
|
|
295
|
+
* }
|
|
296
|
+
* },
|
|
297
|
+
* target: {
|
|
298
|
+
* value: Date.now(),
|
|
299
|
+
* format: 'timestamp'
|
|
300
|
+
* }
|
|
301
|
+
* };
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
type TDateValidation = {
|
|
305
|
+
onlyValidDate?: boolean;
|
|
306
|
+
operator: TDateOperatorsValidation;
|
|
307
|
+
origin: {
|
|
308
|
+
value?: string | number;
|
|
309
|
+
format: TDateFormatsValidation;
|
|
310
|
+
/**
|
|
311
|
+
* Intervals to compare with the original date.
|
|
312
|
+
*
|
|
313
|
+
* It will use today's date for comparison.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* origin date = 10/10/2022
|
|
318
|
+
* interval.year = 1
|
|
319
|
+
* operator = '==='
|
|
320
|
+
* ```
|
|
321
|
+
*
|
|
322
|
+
* It will compare (10/10/2022 + 1) with the current date and check if they are the same
|
|
323
|
+
*/
|
|
324
|
+
intervals?: TDateInterval;
|
|
325
|
+
};
|
|
326
|
+
target?: {
|
|
327
|
+
value: string | number;
|
|
328
|
+
format: TDateFormatsValidation;
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* @type TValidationMethods
|
|
333
|
+
* Represents the various validation methods that can be applied to form fields.
|
|
334
|
+
*
|
|
335
|
+
* @property {number} [max] - Maximum value or length.
|
|
336
|
+
* @property {number} [min] - Minimum value or length.
|
|
337
|
+
* @property {number} [lessThan] - Minimum value or length.
|
|
338
|
+
* @property {number} [greaterThan] - Minimum value or length.
|
|
339
|
+
* @property {TLengthValidation} [length] - Length validation rule.
|
|
340
|
+
* @property {boolean} [required] - Indicates if the field is required.
|
|
341
|
+
* @property {unknown} [value] - Specific value to match.
|
|
342
|
+
* @property {string} [regex] - Regular expression for validation.
|
|
343
|
+
* @property {boolean} [email] - Indicates if the value should be a valid email.
|
|
344
|
+
* @property {boolean} [url] - Indicates if the value should be a valid URL.
|
|
345
|
+
* @property {boolean} [onlyLetters] - Indicates if the value should contain only letters.
|
|
346
|
+
* @property {boolean} [notAllowSpaces] - Indicates if spaces are not allowed.
|
|
347
|
+
* @property {TCallbackValidation} [callback] - Custom validation callback function.
|
|
348
|
+
* @property {boolean} [isNumber] - Indicates if the value should be a number.
|
|
349
|
+
* @property {boolean} [bool] - Indicates if the value should be a boolean or a string that can be converted to a boolean.
|
|
350
|
+
* @property {boolean | string} [exists] - Indicates if the value should exist or match a specific existence condition.
|
|
351
|
+
* @property {boolean} [hasNoExtraSpaces] - Indicates if there should be no extra spaces.
|
|
352
|
+
* @property {boolean} [notEmpty] - Indicates if the field should not be empty.
|
|
353
|
+
* @property {TBetweenValidation} [between] - Validation rule for range between two values.
|
|
354
|
+
* @property {boolean} [sequential] - Indicates if the value should be sequential.
|
|
355
|
+
* @property {boolean} [repeated] - Indicates if the value should not be repeated.
|
|
356
|
+
* @property {string[] | number[]} [includes] - Array of values that should be included.
|
|
357
|
+
* @property {string[]} [isCreditCard] - Array of valid credit card numbers.
|
|
358
|
+
* @property {TCreditCardMatch} [isCreditCodeMatch] - Validation rule for credit card matching.
|
|
359
|
+
* @property {string[]} [isCreditCardAndLength] - Array of valid credit card numbers with length check.
|
|
360
|
+
* @property {TDocumentValidation} [document] - Document validation rule.
|
|
361
|
+
* @property {TConditionsValidation} [conditions] - Conditional validation rules.
|
|
362
|
+
* @property {TMultipleValidation} [multipleValidations] - Multiple validation rules combined with a logical rule.
|
|
363
|
+
* @property {TBetweenDatesValidation} [betweenDates] - Validation rule for checking if a date falls between two dates.
|
|
364
|
+
* @property {TDateValidation} [date] - Validation rule for date values.
|
|
365
|
+
* @property {TDateFormatsValidation} [validDate] - Validation rule for valid date formats.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const validationMethods: TValidationMethods = {
|
|
370
|
+
* max: 100,
|
|
371
|
+
* min: 1,
|
|
372
|
+
* lessThan: 1995,
|
|
373
|
+
* greaterThan: 82000,
|
|
374
|
+
* length: { rule: 'greaterOrEqual', target: 8 },
|
|
375
|
+
* required: true,
|
|
376
|
+
* regex: '^[a-zA-Z0-9]+$',
|
|
377
|
+
* email: true,
|
|
378
|
+
* conditions: {
|
|
379
|
+
* rule: 'and',
|
|
380
|
+
* set: [
|
|
381
|
+
* {
|
|
382
|
+
* forceDefinedOrigin: true,
|
|
383
|
+
* forceDefinedTarget: true,
|
|
384
|
+
* origin: '2023-01-01',
|
|
385
|
+
* condition: '>',
|
|
386
|
+
* target: '2022-01-01'
|
|
387
|
+
* }
|
|
388
|
+
* ]
|
|
389
|
+
* },
|
|
390
|
+
* multipleValidations: {
|
|
391
|
+
* rule: 'AND',
|
|
392
|
+
* validations: {
|
|
393
|
+
* required: true,
|
|
394
|
+
* min: 5,
|
|
395
|
+
* max: 10
|
|
396
|
+
* }
|
|
397
|
+
* },
|
|
398
|
+
* betweenDates: {
|
|
399
|
+
* start: Date.parse('2023-01-01'),
|
|
400
|
+
* end: Date.parse('2023-12-31'),
|
|
401
|
+
* isIncludedBoundaries: true
|
|
402
|
+
* },
|
|
403
|
+
* date: {
|
|
404
|
+
* operator: '===',
|
|
405
|
+
* origin: {
|
|
406
|
+
* value: '10/10/2022',
|
|
407
|
+
* format: 'MMDDYYYY',
|
|
408
|
+
* intervals: {
|
|
409
|
+
* years: 1
|
|
410
|
+
* }
|
|
411
|
+
* },
|
|
412
|
+
* target: {
|
|
413
|
+
* value: Date.now(),
|
|
414
|
+
* format: 'timestamp'
|
|
415
|
+
* }
|
|
416
|
+
* },
|
|
417
|
+
* validDate: 'MMDDYYYY'
|
|
418
|
+
* };
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
type TValidationMethods = {
|
|
422
|
+
/** Maximum value or length. */
|
|
423
|
+
max?: number;
|
|
424
|
+
/** Minimum value or length. */
|
|
425
|
+
min?: number;
|
|
426
|
+
/** Minimum value or length. */
|
|
427
|
+
lessThan?: number;
|
|
428
|
+
/** Minimum value or length. */
|
|
429
|
+
greaterThan?: number;
|
|
430
|
+
/** Length validation rule. */
|
|
431
|
+
length?: TLengthValidation;
|
|
432
|
+
/** Indicates if the field is required. */
|
|
433
|
+
required?: boolean;
|
|
434
|
+
/** Specific value to match. */
|
|
435
|
+
value?: unknown;
|
|
436
|
+
/** Regular expression for validation. */
|
|
437
|
+
regex?: string;
|
|
438
|
+
/** Indicates if the value should be a valid email. */
|
|
439
|
+
email?: boolean;
|
|
440
|
+
/** Indicates if the value should be a valid URL. */
|
|
441
|
+
url?: boolean;
|
|
442
|
+
/** Indicates if the value should contain only letters. */
|
|
443
|
+
onlyLetters?: boolean;
|
|
444
|
+
/** Indicates if spaces are not allowed. */
|
|
445
|
+
notAllowSpaces?: boolean;
|
|
446
|
+
/** Custom validation callback function. */
|
|
447
|
+
callback?: TCallbackValidation;
|
|
448
|
+
/** Indicates if the value should be a number. */
|
|
449
|
+
isNumber?: boolean;
|
|
450
|
+
/** Indicates if the value should be a boolean or a string that can be converted to a boolean. */
|
|
451
|
+
bool?: boolean | string;
|
|
452
|
+
/** Indicates if the value should exist or match a specific existence condition. */
|
|
453
|
+
exists?: boolean | string;
|
|
454
|
+
/** Indicates if there should be no extra spaces. */
|
|
455
|
+
hasNoExtraSpaces?: boolean;
|
|
456
|
+
/** Indicates if the field should not be empty. */
|
|
457
|
+
notEmpty?: boolean;
|
|
458
|
+
/** Validation rule for range between two values. */
|
|
459
|
+
between?: TBetweenValidation;
|
|
460
|
+
/** Indicates if the value should be sequential. */
|
|
461
|
+
sequential?: boolean;
|
|
462
|
+
/** Indicates if the value should not be repeated. */
|
|
463
|
+
repeated?: boolean;
|
|
464
|
+
/** Array of values that should be included. */
|
|
465
|
+
includes?: (string | number)[];
|
|
466
|
+
/** Array of valid credit card numbers. */
|
|
467
|
+
isCreditCard?: string[];
|
|
468
|
+
/** Validation rule for credit card matching. */
|
|
469
|
+
isCreditCodeMatch?: TCreditCardMatch;
|
|
470
|
+
/** Array of valid credit card numbers with length check. */
|
|
471
|
+
isCreditCardAndLength?: string[];
|
|
472
|
+
/** Document validation rule. */
|
|
473
|
+
document?: TDocumentValidation;
|
|
474
|
+
/** Conditional validation rules. */
|
|
475
|
+
conditions?: TConditionsValidation;
|
|
476
|
+
/** Multiple validation rules combined with a logical rule. */
|
|
477
|
+
multipleValidations?: TMultipleValidation;
|
|
478
|
+
/** Validation rule for checking if a date falls between two dates. */
|
|
479
|
+
betweenDates?: TBetweenDatesValidation;
|
|
480
|
+
/** Validation rule for date values. */
|
|
481
|
+
date?: TDateValidation;
|
|
482
|
+
/** Validation rule for valid date formats. */
|
|
483
|
+
validDate?: TDateFormatsValidation;
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* @type {Object.<string, TValidationMethods>} TGenericValidationRule
|
|
487
|
+
* Represents a generic validation rule where each key is associated with a set of validation methods.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* const genericValidationRule = {
|
|
491
|
+
* email: {
|
|
492
|
+
* required: true,
|
|
493
|
+
* email: true,
|
|
494
|
+
* },
|
|
495
|
+
* password: {
|
|
496
|
+
* required: true,
|
|
497
|
+
* minLength: 8,
|
|
498
|
+
* },
|
|
499
|
+
* };
|
|
500
|
+
*/
|
|
501
|
+
type TGenericValidationRule = Record<string, TValidationMethods>;
|
|
502
|
+
/**
|
|
503
|
+
* Formatter types
|
|
504
|
+
* @type TSplitterFormatterValue
|
|
505
|
+
* Represents a value and its position for splitting or formatting purposes.
|
|
506
|
+
*
|
|
507
|
+
* @property {string} value - The value to be split or formatted.
|
|
508
|
+
* @property {number} position - The position for splitting or formatting.
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* ```typescript
|
|
512
|
+
* const splitterFormatter: TSplitterFormatterValue = { value: '-', position: 3 };
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
type TSplitterFormatterValue = {
|
|
516
|
+
value: string;
|
|
517
|
+
position: number;
|
|
518
|
+
};
|
|
519
|
+
/**
|
|
520
|
+
* @type TFormatters
|
|
521
|
+
* Represents the various formatting options that can be applied to form field values.
|
|
522
|
+
*
|
|
523
|
+
* @property {boolean} [dotEvery3chars] - Add a dot every 3 characters.
|
|
524
|
+
* @property {boolean} [capitalize] - Capitalize the value.
|
|
525
|
+
* @property {boolean} [uppercase] - Convert the value to uppercase.
|
|
526
|
+
* @property {boolean} [onlyNumbers] - Allow only numbers.
|
|
527
|
+
* @property {boolean} [onlyLetters] - Allow only letters.
|
|
528
|
+
* @property {Pick<TCurrencyMask, 'precision' | 'decimal'>} [onlyFloatNumber] - Allow only float numbers with specific precision and decimal.
|
|
529
|
+
* @property {string} [regex] - Regular expression for formatting.
|
|
530
|
+
* @property {string[]} [gapsCreditCard] - Gaps to insert in credit card numbers.
|
|
531
|
+
* @property {(value: unknown) => unknown} [callback] - Custom formatter callback function.
|
|
532
|
+
* @property {TSplitterFormatterValue[]} [splitter] - Splitter values for formatting.
|
|
533
|
+
* @property {boolean} [trim] - Removes whitespace from both ends of this string and returns a new string, without modifying the original string.
|
|
534
|
+
* @property {number} [maxLength] - Truncates the input value to a specified maximum length if necessary.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```json
|
|
538
|
+
* {
|
|
539
|
+
* formatters: {
|
|
540
|
+
* dotEvery3chars: true,
|
|
541
|
+
* capitalize: true,
|
|
542
|
+
* uppercase: true,
|
|
543
|
+
* onlyNumbers: true,
|
|
544
|
+
* regex: '^[a-zA-Z0-9]+$',
|
|
545
|
+
* gapsCreditCard: [' ', ' '],
|
|
546
|
+
* callback: (value) => value.toString().toUpperCase(),
|
|
547
|
+
* splitter: [{ value: '-', position: 3 }],
|
|
548
|
+
* trim: true,
|
|
549
|
+
* maxLength: 15
|
|
550
|
+
* }
|
|
551
|
+
* }
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
554
|
+
type TFormatters = {
|
|
555
|
+
/** Add a dot every 3 characters. */
|
|
556
|
+
dotEvery3chars?: boolean;
|
|
557
|
+
/** Capitalize the value. */
|
|
558
|
+
capitalize?: boolean;
|
|
559
|
+
/** Convert the value to uppercase. */
|
|
560
|
+
uppercase?: boolean;
|
|
561
|
+
/** Allow only numbers. */
|
|
562
|
+
onlyNumbers?: boolean;
|
|
563
|
+
/** Allow only letters. */
|
|
564
|
+
onlyLetters?: boolean;
|
|
565
|
+
/** Allow only float numbers with specific precision and decimal. */
|
|
566
|
+
onlyFloatNumber?: Pick<TCurrencyMask, 'precision' | 'decimal'>;
|
|
567
|
+
/** Regular expression for formatting. */
|
|
568
|
+
regex?: string;
|
|
569
|
+
gapsCreditCard?: string[] | boolean;
|
|
570
|
+
callback?: ((value: unknown) => unknown) | null;
|
|
571
|
+
splitter?: TSplitterFormatterValue[];
|
|
572
|
+
/** Removes whitespace from both ends of this string and returns a new string, without modifying the original string. */
|
|
573
|
+
trim?: boolean;
|
|
574
|
+
/** Truncates the input value to a specified maximum length if necessary. */
|
|
575
|
+
maxLength?: number;
|
|
576
|
+
};
|
|
577
|
+
/**
|
|
578
|
+
* Mask types
|
|
579
|
+
* @type TCurrencyMask
|
|
580
|
+
* Represents the mask configuration for currency values.
|
|
581
|
+
*
|
|
582
|
+
* @property {'left' | 'right'} [align] - The alignment of the currency symbol. (default: right)
|
|
583
|
+
* @property {string} [decimal] - The decimal separator. (default: '.')
|
|
584
|
+
* @property {number} [precision] - The number of decimal places. (default: 2)
|
|
585
|
+
* @property {TCurrencyCode} [prefix] - The currency symbol prefix. (default: '$')
|
|
586
|
+
* @property {string} [thousands] - The thousands separator. (default: ',')
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```typescript
|
|
590
|
+
* const currencyMask: TCurrencyMask = {
|
|
591
|
+
* align: 'left',
|
|
592
|
+
* decimal: '.',
|
|
593
|
+
* precision: 2,
|
|
594
|
+
* prefix: '$',
|
|
595
|
+
* thousands: ','
|
|
596
|
+
* };
|
|
597
|
+
* ```
|
|
598
|
+
*/
|
|
599
|
+
type TCurrencyMask = {
|
|
600
|
+
align?: 'left' | 'right';
|
|
601
|
+
decimal?: string;
|
|
602
|
+
precision?: number;
|
|
603
|
+
prefix?: TCurrencyCode;
|
|
604
|
+
thousands?: string;
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Validates if a given value is a valid credit card number based on predefined validation methods.
|
|
609
|
+
*
|
|
610
|
+
* @param value - The value to be validated as a credit card number.
|
|
611
|
+
* @param validations - An object containing validation methods.
|
|
612
|
+
* @returns `true` if the value is either falsy or does not match a valid credit card type, otherwise `false`.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* import { isCreditCard } from './path/to/validationFunctions';
|
|
617
|
+
* import { validationMethods } from './path/to/validationConfig';
|
|
618
|
+
*
|
|
619
|
+
* const isValid = isCreditCard('4111111111111111', validationMethods);
|
|
620
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
declare const isCreditCard: (value: unknown, validations: TValidationMethods) => boolean;
|
|
624
|
+
/**
|
|
625
|
+
* Validates if a given security code matches the expected length for a specified credit card type.
|
|
626
|
+
*
|
|
627
|
+
* @param value - The security code to be validated.
|
|
628
|
+
* @param validations - An object containing validation methods, specifically with `isCreditCodeMatch` details.
|
|
629
|
+
* @returns `true` if the value is either falsy or if the validation methods are not provided. Otherwise, it checks if the security code length matches the expected length for the card type.
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* import { isCreditCodeMatch } from './path/to/validationFunctions';
|
|
634
|
+
* import { validationMethods } from './path/to/validationConfig';
|
|
635
|
+
*
|
|
636
|
+
* const isValid = isCreditCodeMatch('123', validationMethods);
|
|
637
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
638
|
+
* ```
|
|
639
|
+
*/
|
|
640
|
+
declare const isCreditCodeMatch: (value: string, validations: TValidationMethods) => boolean;
|
|
641
|
+
/**
|
|
642
|
+
* Validates if a given value is a valid credit card number and checks if its length matches the expected lengths for the card type.
|
|
643
|
+
*
|
|
644
|
+
* @param value - The credit card number to be validated.
|
|
645
|
+
* @param validations - An object containing validation methods, specifically with `isCreditCardAndLength` details.
|
|
646
|
+
* @returns `true` if the value is either falsy or if the card number does not match any valid lengths for the card type, otherwise `false`.
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```typescript
|
|
650
|
+
* import { isCreditCardAndLength } from './path/to/validationFunctions';
|
|
651
|
+
* import { validationMethods } from './path/to/validationConfig';
|
|
652
|
+
*
|
|
653
|
+
* const isValid = isCreditCardAndLength('4111111111111111', validationMethods);
|
|
654
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
655
|
+
* ```
|
|
656
|
+
*/
|
|
657
|
+
declare const isCreditCardAndLength: (value: string, validations: TValidationMethods) => boolean;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Formats a credit card number by adding gaps based on the card type.
|
|
661
|
+
*
|
|
662
|
+
* @param {unknown} value - The input value to be formatted, expected to be a string representing a credit card number.
|
|
663
|
+
* @param {TFormatters} formatters - An object containing formatting options.
|
|
664
|
+
* @param {boolean} formatters.gapsCreditCard - A flag indicating whether to apply credit card gap formatting.
|
|
665
|
+
* @returns {unknown} - The formatted credit card number with appropriate gaps, or the original value if formatting is not applied.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* const formatters = { gapsCreditCard: true };
|
|
670
|
+
* const result = gapsCreditCard('4111111111111111', formatters);
|
|
671
|
+
* console.log(result); // "4111 1111 1111 1111" (formatted based on card type, e.g., Visa)
|
|
672
|
+
* ```
|
|
673
|
+
* @example
|
|
674
|
+
* ```typescript
|
|
675
|
+
* const formatters = { gapsCreditCard: false };
|
|
676
|
+
* const result = gapsCreditCard('4111111111111111', formatters);
|
|
677
|
+
* console.log(result); // "4111111111111111" (no formatting applied)
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
declare const gapsCreditCard: (value: unknown, formatters: TFormatters) => unknown;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Applies a secure mask to a credit card number, hiding most of its digits.
|
|
684
|
+
*
|
|
685
|
+
* @param value - The credit card number to be masked.
|
|
686
|
+
* @returns The masked credit card number.
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* import { secureCreditCard } from './path/to/creditCardFunctions';
|
|
691
|
+
*
|
|
692
|
+
* const maskedCardNumber = secureCreditCard('1234567890123456');
|
|
693
|
+
* console.log(maskedCardNumber); // Output: '1xxxxxxxxxxxx456'
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
declare const secureCreditCard: (value: string) => string;
|
|
697
|
+
/**
|
|
698
|
+
* Formats a credit card number by inserting spaces every four characters.
|
|
699
|
+
*
|
|
700
|
+
* @param value - The credit card number to be formatted.
|
|
701
|
+
* @returns The formatted credit card number.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* ```typescript
|
|
705
|
+
* import { card } from './path/to/creditCardFunctions';
|
|
706
|
+
*
|
|
707
|
+
* const formattedCardNumber = card('1234567890123456');
|
|
708
|
+
* console.log(formattedCardNumber); // Output: '1234 5678 9012 3456'
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
711
|
+
declare const card: (value: string) => string;
|
|
712
|
+
/**
|
|
713
|
+
* Formats a credit card expiration date (MM/YY).
|
|
714
|
+
*
|
|
715
|
+
* @param value - The expiration date to be formatted (in MMYY or MM/YY format).
|
|
716
|
+
* @returns The formatted expiration date.
|
|
717
|
+
*
|
|
718
|
+
* @example
|
|
719
|
+
* ```typescript
|
|
720
|
+
* import { cardDate } from './path/to/creditCardFunctions';
|
|
721
|
+
*
|
|
722
|
+
* const formattedCardDate = cardDate('1223');
|
|
723
|
+
* console.log(formattedCardDate); // Output: '12/23'
|
|
724
|
+
* ```
|
|
725
|
+
*/
|
|
726
|
+
declare const cardDate: (value: string) => string;
|
|
727
|
+
/**
|
|
728
|
+
* Formats a credit card FEIN (Federal Employer Identification Number) in a specific format.
|
|
729
|
+
*
|
|
730
|
+
* @param value - The FEIN to be formatted.
|
|
731
|
+
* @returns The formatted FEIN.
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```typescript
|
|
735
|
+
* import { fein } from './path/to/creditCardFunctions';
|
|
736
|
+
*
|
|
737
|
+
* const formattedFEIN = fein('123456789');
|
|
738
|
+
* console.log(formattedFEIN); // Output: '12-3456789'
|
|
739
|
+
* ```
|
|
740
|
+
*/
|
|
741
|
+
declare const fein: (value: string) => string;
|
|
742
|
+
|
|
743
|
+
export { card, cardDate, fein, gapsCreditCard, isCreditCard, isCreditCardAndLength, isCreditCodeMatch, secureCreditCard };
|