@bolttech/form-engine-core 1.0.2-beta.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/index.d.ts +2327 -0
  2. package/index.esm.js +154 -82
  3. package/package.json +9 -10
  4. package/index.esm.d.ts +0 -1
  5. package/src/constants/constants.d.ts +0 -10
  6. package/src/formatters/creditCard.d.ts +0 -23
  7. package/src/formatters/custom.d.ts +0 -29
  8. package/src/formatters/handler.d.ts +0 -2
  9. package/src/formatters/regex.d.ts +0 -47
  10. package/src/formatters/splitter.d.ts +0 -17
  11. package/src/formatters/string.d.ts +0 -88
  12. package/src/helpers/SafeSubject.d.ts +0 -11
  13. package/src/helpers/creditCard.d.ts +0 -95
  14. package/src/helpers/helpers.d.ts +0 -67
  15. package/src/helpers/validation.d.ts +0 -27
  16. package/src/index.d.ts +0 -10
  17. package/src/interfaces/schema.d.ts +0 -112
  18. package/src/interfaces/state.d.ts +0 -22
  19. package/src/managers/field.d.ts +0 -326
  20. package/src/managers/form.d.ts +0 -346
  21. package/src/managers/formGroup.d.ts +0 -110
  22. package/src/managers/index.d.ts +0 -3
  23. package/src/masks/creditCard.d.ts +0 -60
  24. package/src/masks/generic.d.ts +0 -39
  25. package/src/masks/handler.d.ts +0 -2
  26. package/src/masks/string.d.ts +0 -99
  27. package/src/types/event.d.ts +0 -109
  28. package/src/types/form.d.ts +0 -55
  29. package/src/types/mapper.d.ts +0 -95
  30. package/src/types/schema.d.ts +0 -835
  31. package/src/types/template.d.ts +0 -50
  32. package/src/types/utility.d.ts +0 -6
  33. package/src/validations/creditCard.d.ts +0 -52
  34. package/src/validations/custom.d.ts +0 -25
  35. package/src/validations/date.d.ts +0 -79
  36. package/src/validations/document.d.ts +0 -25
  37. package/src/validations/handler.d.ts +0 -2
  38. package/src/validations/length.d.ts +0 -39
  39. package/src/validations/list.d.ts +0 -32
  40. package/src/validations/logical.d.ts +0 -75
  41. package/src/validations/multiple.d.ts +0 -31
  42. package/src/validations/namedRule.d.ts +0 -22
  43. package/src/validations/number.d.ts +0 -145
  44. package/src/validations/object.d.ts +0 -44
  45. package/src/validations/regex.d.ts +0 -217
  46. package/src/validations/string.d.ts +0 -53
@@ -1,835 +0,0 @@
1
- /// <reference types="node" />
2
- /** @virtual */
3
- import { TCurrencyCode, TCurrencyLocalCode } from '@gaignoux/currency';
4
- import { OutgoingHttpHeaders } from 'http2';
5
- import { TEvents } from './event';
6
- import { TFormValues } from './form';
7
- import { ALLOWED_RESET_PROPS_MUTATIONS } from '../constants/constants';
8
- /**
9
- * @type TLengthValidation
10
- * Represents the validation rules based on the length of the input.
11
- *
12
- * @property {'equal' | 'notEqual' | 'less' | 'lessOrEqual' | 'greater' | 'greaterOrEqual'} rule - The rule to apply.
13
- * @property {number} target - The target value to compare against.
14
- *
15
- * @example
16
- * ```typescript
17
- * const lengthValidation: TLengthValidation = { rule: 'greaterOrEqual', target: 8 };
18
- * ```
19
- */
20
- type TLengthValidation = {
21
- rule: 'equal' | 'notEqual' | 'less' | 'lessOrEqual' | 'greater' | 'greaterOrEqual';
22
- target: number;
23
- };
24
- /**
25
- * @type TCallbackValidation
26
- * A custom validation function.
27
- *
28
- * @param {unknown} value - The value to validate.
29
- * @returns {boolean} - The result of the validation.
30
- *
31
- * @example
32
- * ```typescript
33
- * const callbackValidation: TCallbackValidation = (value) => typeof value === 'string';
34
- * ```
35
- */
36
- type TCallbackValidation = (value: unknown) => boolean;
37
- /**
38
- * @type TBetweenValidation
39
- * Represents validation rules that check if a value is between a range.
40
- *
41
- * @property {number} start - The start of the range.
42
- * @property {number} end - The end of the range.
43
- *
44
- * @example
45
- * ```typescript
46
- * const betweenValidation: TBetweenValidation = { start: 1, end: 10 };
47
- * ```
48
- */
49
- type TBetweenValidation = {
50
- start: number;
51
- end: number;
52
- };
53
- /**
54
- * @type TCreditCardMatch
55
- * Represents the options for credit card matching.
56
- *
57
- * @property {string} numberCard - The credit card number.
58
- * @property {string[]} availableOptions - The available options for matching.
59
- *
60
- * @example
61
- * ```typescript
62
- * const creditCardMatch: TCreditCardMatch = { numberCard: '1234', availableOptions: ['Visa', 'MasterCard'] };
63
- * ```
64
- */
65
- type TCreditCardMatch = {
66
- numberCard: string;
67
- availableOptions: string[];
68
- };
69
- /**
70
- * @type TDocumentValidation
71
- * Represents validation for specific document types.
72
- *
73
- * @property {'NIF' | 'NIE' | 'CIF' | 'IBAN'} type - The type of document.
74
- * @property {TCurrencyLocalCode} [locale] - The locale code for validation.
75
- *
76
- * @example
77
- * ```typescript
78
- * const documentValidation: TDocumentValidation = { type: 'NIF', locale: 'ES' };
79
- * ```
80
- */
81
- type TDocumentValidation = {
82
- type: 'NIF' | 'NIE' | 'CIF' | 'IBAN';
83
- locale?: TCurrencyLocalCode;
84
- };
85
- /**
86
- * @type TDateOperatorsValidation
87
- * Represents the operators used for date validation conditions.
88
- *
89
- * @property {'<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin'}
90
- *
91
- * @example
92
- * ```typescript
93
- * const operator: TDateOperatorsValidation = '<';
94
- * ```
95
- */
96
- type TDateOperatorsValidation = '<' | '>' | '===' | '>=' | '<=' | '!==' | '!!origin';
97
- /**
98
- * @type TConditionsValidationSet
99
- * Represents a single validation condition set.
100
- *
101
- * @property {boolean} [forceDefinedOrigin] - Flag to force the origin value to be defined.
102
- * @property {boolean} [forceDefinedTarget] - Flag to force the target value to be defined.
103
- * @property {string | number | boolean} [origin] - The origin value for the condition.
104
- * @property {TDateOperatorsValidation} condition - The validation condition operator.
105
- * @property {string | number | boolean} [target] - The target value for the condition.
106
- *
107
- * @example
108
- * ```typescript
109
- * const conditionSet: TConditionsValidationSet = {
110
- * forceDefinedOrigin: true,
111
- * forceDefinedTarget: true,
112
- * origin: '2023-01-01',
113
- * condition: '>',
114
- * target: '2022-01-01'
115
- * };
116
- * ```
117
- */
118
- type TConditionsValidationSet = {
119
- forceDefinedOrigin?: boolean;
120
- forceDefinedTarget?: boolean;
121
- origin?: string | number | boolean;
122
- condition: TDateOperatorsValidation;
123
- target?: string | number | boolean;
124
- };
125
- /**
126
- * @type TConditionsValidation
127
- * Represents a set of validation conditions.
128
- *
129
- * @property {'and' | 'or'} rule - The logical rule to combine the conditions (AND/OR).
130
- * @property {TConditionsValidationSet[]} set - The array of validation condition sets.
131
- * @property {TConditionsValidation} [conditions] - Nested conditions for more complex validation logic.
132
- *
133
- * @example
134
- * ```typescript
135
- * const conditionsValidation: TConditionsValidation = {
136
- * rule: 'and',
137
- * set: [
138
- * {
139
- * forceDefinedOrigin: true,
140
- * forceDefinedTarget: true,
141
- * origin: '2023-01-01',
142
- * condition: '>',
143
- * target: '2022-01-01'
144
- * }
145
- * ],
146
- * conditions: {
147
- * rule: 'or',
148
- * set: [
149
- * {
150
- * origin: true,
151
- * condition: '!!origin',
152
- * target: false
153
- * }
154
- * ]
155
- * }
156
- * };
157
- * ```
158
- */
159
- type TConditionsValidation = {
160
- rule: 'and' | 'or';
161
- set: TConditionsValidationSet[];
162
- conditions?: TConditionsValidation;
163
- };
164
- type TAvailableValidations = Omit<TValidationMethods, 'multipleValidations'> | TGenericValidationRule;
165
- /**
166
- * @type TMultipleValidation
167
- * Represents a set of multiple validation methods combined with a logical rule.
168
- *
169
- * @property {'AND' | 'OR' | 'NOT'} rule - The logical rule to combine the validation methods (AND, OR, NOT).
170
- * @property {TAvailableValidations} validations - The validation methods to be combined.
171
- *
172
- * @example
173
- * ```typescript
174
- * const multipleValidation: TMultipleValidation = {
175
- * rule: 'AND',
176
- * validations: {
177
- * required: true,
178
- * min: 5,
179
- * max: 10
180
- * }
181
- * };
182
- * ```
183
- */
184
- type TMultipleValidation = {
185
- rule: 'AND' | 'OR' | 'NOT';
186
- validations: TAvailableValidations;
187
- };
188
- /**
189
- * @type TBetweenDatesValidation
190
- * Represents a validation method to check if a value falls between specified dates.
191
- *
192
- * @property {TDateValidation[]} [TBetweenDatesValidation] - An array of date validation methods.
193
- *
194
- * @example
195
- * ```typescript
196
- * const betweenDatesValidation: TBetweenDatesValidation = [
197
- * {
198
- * onlyValidDate: true,
199
- * operator: '>=',
200
- * origin: {
201
- * format: 'MMDDYYYY',
202
- * intervals: {
203
- * years: 1
204
- * }
205
- * },
206
- * target: {
207
- * value: Date.now(),
208
- * format: 'timestamp',
209
- * value: '01/01/2023',
210
- * }
211
- * },
212
- * {
213
- * onlyValidDate: true,
214
- * operator: '<=',
215
- * origin: {
216
- * format: 'MMDDYYYY',
217
- * intervals: {
218
- * years: 1
219
- * }
220
- * },
221
- * target: {
222
- * format: 'timestamp',
223
- * value: '31/12/2023',
224
- * }
225
- * }
226
- * ];
227
- * ```
228
- */
229
- type TBetweenDatesValidation = TDateValidation[];
230
- /**
231
- * @type TDateFormatsValidation
232
- * Represents the supported date formats for validation.
233
- *
234
- * @type {'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp'}
235
- *
236
- * @example
237
- * ```typescript
238
- * const dateFormat: TDateFormatsValidation = 'MMDDYYYY';
239
- * ```
240
- */
241
- type TDateFormatsValidation = 'MMDDYYYY' | 'DDMMYYYY' | 'YYYYMMDD' | 'YYYYDDMM' | 'timestamp';
242
- type TDateInterval = {
243
- years?: number;
244
- months?: number;
245
- days?: number;
246
- };
247
- /**
248
- * @type TDateValidation
249
- * Represents a validation method for date values.
250
- *
251
- * @property {boolean} [onlyValidDate] - Flag to validate only if the date is valid.
252
- * @property {TDateOperatorsValidation} operator - The validation operator to be used.
253
- * @property {Object} origin - The origin date configuration.
254
- * @property {string | number} [origin.value] - The origin date value.
255
- * @property {TDateFormatsValidation} origin.format - The format of the origin date.
256
- * @property {Object} [origin.intervals] - The intervals to add to the origin date for comparison.
257
- * @property {number} [origin.intervals.years] - The number of years to add.
258
- * @property {number} [origin.intervals.months] - The number of months to add.
259
- * @property {number} [origin.intervals.days] - The number of days to add.
260
- * @property {Object} [target] - The target date configuration.
261
- * @property {string | number} target.value - The target date value.
262
- * @property {TDateFormatsValidation} target.format - The format of the target date.
263
- *
264
- * @example
265
- * ```typescript
266
- * const dateValidation: TDateValidation = {
267
- * onlyValidDate: true,
268
- * operator: '===',
269
- * origin: {
270
- * value: '10/10/2022',
271
- * format: 'MMDDYYYY',
272
- * intervals: {
273
- * years: 1
274
- * }
275
- * },
276
- * target: {
277
- * value: Date.now(),
278
- * format: 'timestamp'
279
- * }
280
- * };
281
- * ```
282
- */
283
- type TDateValidation = {
284
- onlyValidDate?: boolean;
285
- operator: TDateOperatorsValidation;
286
- origin: {
287
- value?: string | number;
288
- format: TDateFormatsValidation;
289
- /**
290
- * Intervals to compare with the original date.
291
- *
292
- * It will use today's date for comparison.
293
- *
294
- * @example
295
- * ```typescript
296
- * origin date = 10/10/2022
297
- * interval.year = 1
298
- * operator = '==='
299
- * ```
300
- *
301
- * It will compare (10/10/2022 + 1) with the current date and check if they are the same
302
- */
303
- intervals?: TDateInterval;
304
- };
305
- target?: {
306
- value: string | number;
307
- format: TDateFormatsValidation;
308
- };
309
- };
310
- /**
311
- * @type TValidationMethods
312
- * Represents the various validation methods that can be applied to form fields.
313
- *
314
- * @property {number} [max] - Maximum value or length.
315
- * @property {number} [min] - Minimum value or length.
316
- * @property {number} [lessThan] - Minimum value or length.
317
- * @property {number} [greaterThan] - Minimum value or length.
318
- * @property {TLengthValidation} [length] - Length validation rule.
319
- * @property {boolean} [required] - Indicates if the field is required.
320
- * @property {unknown} [value] - Specific value to match.
321
- * @property {string} [regex] - Regular expression for validation.
322
- * @property {boolean} [email] - Indicates if the value should be a valid email.
323
- * @property {boolean} [url] - Indicates if the value should be a valid URL.
324
- * @property {boolean} [onlyLetters] - Indicates if the value should contain only letters.
325
- * @property {boolean} [notAllowSpaces] - Indicates if spaces are not allowed.
326
- * @property {TCallbackValidation} [callback] - Custom validation callback function.
327
- * @property {boolean} [isNumber] - Indicates if the value should be a number.
328
- * @property {boolean} [bool] - Indicates if the value should be a boolean or a string that can be converted to a boolean.
329
- * @property {boolean | string} [exists] - Indicates if the value should exist or match a specific existence condition.
330
- * @property {boolean} [hasNoExtraSpaces] - Indicates if there should be no extra spaces.
331
- * @property {boolean} [notEmpty] - Indicates if the field should not be empty.
332
- * @property {TBetweenValidation} [between] - Validation rule for range between two values.
333
- * @property {boolean} [sequential] - Indicates if the value should be sequential.
334
- * @property {boolean} [repeated] - Indicates if the value should not be repeated.
335
- * @property {string[] | number[]} [includes] - Array of values that should be included.
336
- * @property {string[]} [isCreditCard] - Array of valid credit card numbers.
337
- * @property {TCreditCardMatch} [isCreditCodeMatch] - Validation rule for credit card matching.
338
- * @property {string[]} [isCreditCardAndLength] - Array of valid credit card numbers with length check.
339
- * @property {TDocumentValidation} [document] - Document validation rule.
340
- * @property {TConditionsValidation} [conditions] - Conditional validation rules.
341
- * @property {TMultipleValidation} [multipleValidations] - Multiple validation rules combined with a logical rule.
342
- * @property {TBetweenDatesValidation} [betweenDates] - Validation rule for checking if a date falls between two dates.
343
- * @property {TDateValidation} [date] - Validation rule for date values.
344
- * @property {TDateFormatsValidation} [validDate] - Validation rule for valid date formats.
345
- *
346
- * @example
347
- * ```typescript
348
- * const validationMethods: TValidationMethods = {
349
- * max: 100,
350
- * min: 1,
351
- * lessThan: 1995,
352
- * greaterThan: 82000,
353
- * length: { rule: 'greaterOrEqual', target: 8 },
354
- * required: true,
355
- * regex: '^[a-zA-Z0-9]+$',
356
- * email: true,
357
- * conditions: {
358
- * rule: 'and',
359
- * set: [
360
- * {
361
- * forceDefinedOrigin: true,
362
- * forceDefinedTarget: true,
363
- * origin: '2023-01-01',
364
- * condition: '>',
365
- * target: '2022-01-01'
366
- * }
367
- * ]
368
- * },
369
- * multipleValidations: {
370
- * rule: 'AND',
371
- * validations: {
372
- * required: true,
373
- * min: 5,
374
- * max: 10
375
- * }
376
- * },
377
- * betweenDates: {
378
- * start: Date.parse('2023-01-01'),
379
- * end: Date.parse('2023-12-31'),
380
- * isIncludedBoundaries: true
381
- * },
382
- * date: {
383
- * operator: '===',
384
- * origin: {
385
- * value: '10/10/2022',
386
- * format: 'MMDDYYYY',
387
- * intervals: {
388
- * years: 1
389
- * }
390
- * },
391
- * target: {
392
- * value: Date.now(),
393
- * format: 'timestamp'
394
- * }
395
- * },
396
- * validDate: 'MMDDYYYY'
397
- * };
398
- * ```
399
- */
400
- type TValidationMethods = {
401
- max?: number;
402
- min?: number;
403
- lessThan?: number;
404
- greaterThan?: number;
405
- length?: TLengthValidation;
406
- required?: boolean;
407
- value?: unknown;
408
- regex?: string;
409
- email?: boolean;
410
- url?: boolean;
411
- onlyLetters?: boolean;
412
- notAllowSpaces?: boolean;
413
- callback?: TCallbackValidation;
414
- isNumber?: boolean;
415
- bool?: boolean | string;
416
- exists?: boolean | string;
417
- hasNoExtraSpaces?: boolean;
418
- notEmpty?: boolean;
419
- between?: TBetweenValidation;
420
- sequential?: boolean;
421
- repeated?: boolean;
422
- includes?: (string | number)[];
423
- isCreditCard?: string[];
424
- isCreditCodeMatch?: TCreditCardMatch;
425
- isCreditCardAndLength?: string[];
426
- document?: TDocumentValidation;
427
- conditions?: TConditionsValidation;
428
- multipleValidations?: TMultipleValidation;
429
- betweenDates?: TBetweenDatesValidation;
430
- date?: TDateValidation;
431
- validDate?: TDateFormatsValidation;
432
- };
433
- /**
434
- * @type {Object.<string, TValidationMethods>} TGenericValidationRule
435
- * Represents a generic validation rule where each key is associated with a set of validation methods.
436
- *
437
- * @example
438
- * const genericValidationRule = {
439
- * email: {
440
- * required: true,
441
- * email: true,
442
- * },
443
- * password: {
444
- * required: true,
445
- * minLength: 8,
446
- * },
447
- * };
448
- */
449
- type TGenericValidationRule = {
450
- [key: string]: TValidationMethods;
451
- };
452
- /**
453
- * @type {TValidationMethods | TGenericValidationRule} TSchemaValidation
454
- * Represents the schema validation which can be either a set of validation methods or a generic validation rule.
455
- *
456
- * @example
457
- * const schemaValidation = {
458
- * required: true,
459
- * maxLength: 10,
460
- * };
461
- *
462
- * const genericSchemaValidation = {
463
- * email: {
464
- * required: true,
465
- * email: true,
466
- * },
467
- * password: {
468
- * required: true,
469
- * minLength: 8,
470
- * },
471
- * };
472
- */
473
- type TSchemaValidation = TValidationMethods | TGenericValidationRule;
474
- /**
475
- * Formatter types
476
- * @type TSplitterFormatterValue
477
- * Represents a value and its position for splitting or formatting purposes.
478
- *
479
- * @property {string} value - The value to be split or formatted.
480
- * @property {number} position - The position for splitting or formatting.
481
- *
482
- * @example
483
- * ```typescript
484
- * const splitterFormatter: TSplitterFormatterValue = { value: '-', position: 3 };
485
- * ```
486
- */
487
- type TSplitterFormatterValue = {
488
- value: string;
489
- position: number;
490
- };
491
- /**
492
- * @type TFormatters
493
- * Represents the various formatting options that can be applied to form field values.
494
- *
495
- * @property {boolean} [dotEvery3chars] - Add a dot every 3 characters.
496
- * @property {boolean} [capitalize] - Capitalize the value.
497
- * @property {boolean} [uppercase] - Convert the value to uppercase.
498
- * @property {boolean} [onlyNumbers] - Allow only numbers.
499
- * @property {boolean} [onlyLetters] - Allow only letters.
500
- * @property {Pick<TCurrencyMask, 'precision' | 'decimal'>} [onlyFloatNumber] - Allow only float numbers with specific precision and decimal.
501
- * @property {string} [regex] - Regular expression for formatting.
502
- * @property {string[]} [gapsCreditCard] - Gaps to insert in credit card numbers.
503
- * @property {(value: unknown) => unknown} [callback] - Custom formatter callback function.
504
- * @property {TSplitterFormatterValue[]} [splitter] - Splitter values for formatting.
505
- * @property {boolean} [trim] - Removes whitespace from both ends of this string and returns a new string, without modifying the original string.
506
- * @property {number} [maxLength] - Truncates the input value to a specified maximum length if necessary.
507
- *
508
- * @example
509
- * ```typescript
510
- * const formatters: TFormatters = {
511
- * dotEvery3chars: true,
512
- * capitalize: true,
513
- * uppercase: true,
514
- * onlyNumbers: true,
515
- * regex: '^[a-zA-Z0-9]+$',
516
- * gapsCreditCard: [' ', ' '],
517
- * callback: (value) => value.toString().toUpperCase(),
518
- * splitter: [{ value: '-', position: 3 }],
519
- * trim: true,
520
- * maxLength: 15
521
- * };
522
- * ```
523
- */
524
- type TFormatters = {
525
- dotEvery3chars?: boolean;
526
- capitalize?: boolean;
527
- uppercase?: boolean;
528
- onlyNumbers?: boolean;
529
- onlyLetters?: boolean;
530
- onlyFloatNumber?: Pick<TCurrencyMask, 'precision' | 'decimal'>;
531
- regex?: string;
532
- gapsCreditCard?: string[];
533
- callback?: (value: unknown) => unknown;
534
- splitter?: TSplitterFormatterValue[];
535
- trim?: boolean;
536
- maxLength?: number;
537
- };
538
- /**
539
- * Mask types
540
- * @type TCurrencyMask
541
- * Represents the mask configuration for currency values.
542
- *
543
- * @property {'left' | 'right'} [align] - The alignment of the currency symbol. (default: right)
544
- * @property {string} [decimal] - The decimal separator. (default: '.')
545
- * @property {number} [precision] - The number of decimal places. (default: 2)
546
- * @property {TCurrencyCode} [prefix] - The currency symbol prefix. (default: '$')
547
- * @property {string} [thousands] - The thousands separator. (default: ',')
548
- *
549
- * @example
550
- * ```typescript
551
- * const currencyMask: TCurrencyMask = {
552
- * align: 'left',
553
- * decimal: '.',
554
- * precision: 2,
555
- * prefix: '$',
556
- * thousands: ','
557
- * };
558
- * ```
559
- */
560
- type TCurrencyMask = {
561
- align?: 'left' | 'right';
562
- decimal?: string;
563
- precision?: number;
564
- prefix?: TCurrencyCode;
565
- thousands?: string;
566
- };
567
- /**
568
- * @type TMaskGeneric
569
- * Represents a generic mask configuration.
570
- *
571
- * @property {number} to - The ending position of the mask.
572
- * @property {number} from - The starting position of the mask.
573
- * @property {string} mask - The mask pattern to apply.
574
- *
575
- * @example
576
- * ```typescript
577
- * const maskGeneric: TMaskGeneric = { to: 4, from: 0, mask: '****' };
578
- * ```
579
- */
580
- type TMaskGeneric = {
581
- to: number;
582
- from: number;
583
- mask: string;
584
- };
585
- /**
586
- * @type TMasks
587
- * Represents the different types of masks that can be applied to form field values.
588
- *
589
- * @property {TCurrencyMask} [currency] - Mask for currency values.
590
- * @property {TMaskGeneric[]} [generic] - Array of generic masks.
591
- * @property {string} [custom] - Custom mask pattern.
592
- * @property {boolean} [secureCreditCard] - Mask for securing credit card values.
593
- * @property {boolean} [card] - Mask for card values.
594
- * @property {boolean} [cardDate] - Mask for card date values.
595
- * @property {boolean} [fein] - Mask for FEIN (Federal Employer Identification Number).
596
- * @property {string | number} [replaceAll] - Value to replace all matches.
597
- * @property {(value: unknown) => string} [callback] - Custom mask callback function.
598
- *
599
- * @example
600
- * ```typescript
601
- * const masks: TMasks = {
602
- * currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' },
603
- * generic: [{ to: 4, from: 0, mask: '****' }],
604
- * custom: '###-##-####',
605
- * secureCreditCard: true,
606
- * card: true,
607
- * cardDate: true,
608
- * fein: true,
609
- * replaceAll: '*',
610
- * callback: (value) => value.toString().replace(/\d/g, '*')
611
- * };
612
- * ```
613
- */
614
- type TMasks = {
615
- currency?: TCurrencyMask;
616
- generic?: TMaskGeneric[];
617
- custom?: string;
618
- secureCreditCard?: boolean;
619
- card?: boolean;
620
- cardDate?: boolean;
621
- fein?: boolean;
622
- replaceAll?: string | number;
623
- callback?(value: unknown): string;
624
- };
625
- /**
626
- * @type TVisibility
627
- * Represents the visibility conditions for form fields based on validations.
628
- *
629
- * @property {boolean} showOnlyIfTrue - Enables visibility of fields only if any or all validation conditions are positive.
630
- * @property {TSchemaValidation} validations - The validation methods to determine visibility.
631
- * @property {string[] | string} fields - The fields to be shown or hidden based on validations.
632
- * @property {string[]} events - Events where visibility will occur.
633
- *
634
- * @example
635
- * ```typescript
636
- * const visibility: TVisibility = {
637
- * showOnlyIfTrue: false,
638
- * validations: { required: true },
639
- * fields: ['fieldName'],
640
- * events: ['ON_FIELD_CHANGE']
641
- * };
642
- * ```
643
- */
644
- type TVisibility = {
645
- showOnlyIfTrue?: boolean;
646
- validations: TSchemaValidation;
647
- fields: string[] | string;
648
- events: Partial<TEvents>[];
649
- };
650
- /**
651
- * @type TResetValueMethods
652
- * Extends TVisibility with methods to reset values.
653
- *
654
- * @property {string[] | string} resettledValue - The values to reset.
655
- *
656
- * @example
657
- * ```typescript
658
- * const resetValueMethods: TResetValueMethods = {
659
- * validations: { required: true },
660
- * fields: ['fieldName'],
661
- * resettledValue: ['']
662
- * };
663
- * ```
664
- */
665
- type TResetValueMethods = Omit<TVisibility, 'showOnlyIfTrue' | 'validations'> & {
666
- resettledValue: unknown[] | unknown;
667
- validations?: TSchemaValidation;
668
- };
669
- type TResetPathMethods = {
670
- property: (typeof ALLOWED_RESET_PROPS_MUTATIONS)[number];
671
- path: string;
672
- field: string;
673
- resettledValue: unknown;
674
- validations: TSchemaValidation;
675
- events: Partial<TEvents>[];
676
- };
677
- /**
678
- * @type TApiConfig
679
- * Represents the configuration for an API request.
680
- *
681
- * @property {'GET' | 'POST'} method - The HTTP method for the request.
682
- * @property {string} url - The URL for the request.
683
- * @property {OutgoingHttpHeaders} [headers] - The headers for the request.
684
- * @property {Record<string, string>} queryParams - query parameters for request.
685
- * @property {string} [resultPath] - The path to extract the result from the response.
686
- * @property {unknown} [fallbackValue] - The fallback value if the request fails.
687
- * @property {TSchemaValidation} preConditions - validation conditions to execute the API call
688
- * @property {boolean} blockRequestWhenInvalid - blocks request when field validation fails
689
- *
690
- * @example
691
- * ```typescript
692
- * const apiConfig: TApiConfig = {
693
- * method: 'POST',
694
- * url: 'https://api.example.com/data',
695
- * headers: { 'Content-Type': 'application/json' },
696
- * resultPath: 'data.results',
697
- * fallbackValue: [],
698
- * preConditions: {
699
- * required: true,
700
- * }
701
- * blockRequestWhenInvalid: true,
702
- * };
703
- * ```
704
- */
705
- type TApiConfig = {
706
- method: 'GET' | 'POST';
707
- url: string;
708
- body?: Record<string, unknown>;
709
- headers?: OutgoingHttpHeaders;
710
- queryParams?: Record<string, string>;
711
- resultPath?: string;
712
- fallbackValue?: unknown;
713
- preConditions?: TSchemaValidation;
714
- blockRequestWhenInvalid?: boolean;
715
- transform?: {
716
- callback(callbackPayload: {
717
- payload: unknown;
718
- formValues: TFormValues<unknown>;
719
- }): unknown;
720
- };
721
- };
722
- /**
723
- * @type TProps
724
- * Represents the properties for a component.
725
- */
726
- type TProps = Record<string, unknown>;
727
- /**
728
- * @type TValidations
729
- * Represents the validation configuration for form fields, including methods, event-specific messages, and error messages.
730
- *
731
- * @property {TSchemaValidation} methods - The validation methods to be applied.
732
- * @property {Partial<Record<TEvents, string[]>>} eventMessages - The messages to be displayed for specific validation events.
733
- * @property {TErrorMessages} messages - The general error messages for validation methods.
734
- *
735
- * @example
736
- * const validations: TValidations = {
737
- * methods: {
738
- * max: 100,
739
- * required: true,
740
- * regex: '^[a-zA-Z0-9]+$',
741
- * },
742
- * eventMessages: {
743
- * ON_FIELD_MOUNT: ['required'],
744
- * ON_FIELD_CHANGE: ['regex', 'required'],
745
- * ON_FIELD_BLUR: ['max', 'required'],
746
- * },
747
- * messages: {
748
- * default: 'This field is required',
749
- * max: 'Value exceeds the maximum limit',
750
- * regex: 'Value does not match the pattern',
751
- * },
752
- * };
753
- */
754
- type TValidations = {
755
- methods: TSchemaValidation;
756
- eventMessages?: Partial<Record<TEvents, Partial<keyof TValidationMethods | (string & NonNullable<unknown>)>[]>>;
757
- messages?: TErrorMessages;
758
- };
759
- /**
760
- * @type TErrorMessages
761
- * Represents the error messages for different validation methods.
762
- *
763
- * @example
764
- * ```typescript
765
- * const errorMessages: TErrorMessages = {
766
- * required: 'This field is required.',
767
- * max: 'The value cannot exceed the maximum limit.'
768
- * default: 'Default error message'
769
- * };
770
- * ```
771
- */
772
- type TErrorMessages = {
773
- [K in keyof TSchemaValidation]?: string;
774
- } & {
775
- default?: string;
776
- } & {
777
- [key: string]: string;
778
- };
779
- /**
780
- * Represents an event configuration with a specific type.
781
- *
782
- * @template T
783
- * @property {T} config - The configuration of the event.
784
- * @property {Partial<TEvents>[]} events - The events associated with the configuration.
785
- */
786
- type TEvent<T> = {
787
- config: T;
788
- events: Partial<TEvents>[];
789
- };
790
- /**
791
- * Represents the API event configurations.
792
- *
793
- * @property {TEvent<TApiConfig>} [defaultConfig] - The default event configuration.
794
- * @property {Record<string, TEvent<TApiConfig>>} [configs] - Named event configurations.
795
- */
796
- type TApiEvent = {
797
- defaultConfig?: TEvent<TApiConfig>;
798
- configs?: Record<string, TEvent<TApiConfig>>;
799
- };
800
- /**
801
- * Represents the API response return payload for handling.
802
- *
803
- * @property {unknown} response - The default response.
804
- * @property {number | null} status - response http status number.
805
- */
806
- type TApiResponsePayload = {
807
- response: unknown;
808
- status: number | null;
809
- };
810
- /**
811
- * Represents the API response structure.
812
- *
813
- * @property {TApiResponsePayload} default - The default response.
814
- * @property {Record<string, TApiResponsePayload>} [named] - Named responses.
815
- */
816
- type TApiResponse = {
817
- default: TApiResponsePayload;
818
- named?: Record<string, TApiResponsePayload>;
819
- apiState: {
820
- loading: boolean;
821
- lastEvent?: TEvents;
822
- };
823
- };
824
- /**
825
- * Represents the schema config structure
826
- *
827
- * @property {number} defaultAPIdebounceTimeMS - default API debounce time between request events.
828
- * @property {number} [defaultStateRefreshTimeMS] - default state refresh between events side effects.
829
- */
830
- type TSchemaFormConfig = {
831
- defaultAPIdebounceTimeMS?: number;
832
- defaultStateRefreshTimeMS?: number;
833
- defaultLogVerbose?: boolean;
834
- };
835
- export { TApiConfig, TErrorMessages, TValidations, TMasks, TProps, TResetValueMethods, TResetPathMethods, TFormatters, TValidationMethods, TGenericValidationRule, TSchemaValidation, TEvent, TVisibility, TApiEvent, TApiResponsePayload, TApiResponse, TSchemaFormConfig, TLengthValidation, TCreditCardMatch, TDocumentValidation, TCallbackValidation, TBetweenValidation, TMaskGeneric, TSplitterFormatterValue, TCurrencyMask, TDateOperatorsValidation, TConditionsValidationSet, TConditionsValidation, TMultipleValidation, TAvailableValidations, TDateValidation, TBetweenDatesValidation, TDateFormatsValidation, TDateInterval, };