@bolttech/form-engine-core 1.0.10 → 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.
Files changed (64) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/credit-card.d.ts +743 -0
  3. package/credit-card.esm.js +1 -0
  4. package/currency.d.ts +131 -0
  5. package/currency.esm.js +1 -0
  6. package/date.d.ts +582 -0
  7. package/date.esm.js +1 -0
  8. package/document.d.ts +527 -0
  9. package/document.esm.js +1 -0
  10. package/index.d.ts +52 -5
  11. package/index.esm.js +1 -4570
  12. package/lite.d.ts +2393 -0
  13. package/lite.esm.js +1 -0
  14. package/package.json +34 -2
  15. package/src/constants/constants.d.ts +11 -0
  16. package/src/formatters/creditCard.d.ts +23 -0
  17. package/src/formatters/custom.d.ts +29 -0
  18. package/src/formatters/handler.d.ts +2 -0
  19. package/src/formatters/regex.d.ts +47 -0
  20. package/src/formatters/splitter.d.ts +17 -0
  21. package/src/formatters/string.d.ts +88 -0
  22. package/src/helpers/SafeSubject.d.ts +21 -0
  23. package/src/helpers/creditCard.d.ts +95 -0
  24. package/src/helpers/helpers.d.ts +66 -0
  25. package/src/helpers/lodash-replacements.d.ts +41 -0
  26. package/src/helpers/validation.d.ts +28 -0
  27. package/src/index.d.ts +15 -0
  28. package/src/interfaces/schema.d.ts +161 -0
  29. package/src/interfaces/state.d.ts +22 -0
  30. package/src/lite.d.ts +30 -0
  31. package/src/managers/field.d.ts +339 -0
  32. package/src/managers/form.d.ts +357 -0
  33. package/src/managers/formGroup.d.ts +110 -0
  34. package/src/managers/index.d.ts +3 -0
  35. package/src/masks/creditCard.d.ts +60 -0
  36. package/src/masks/currency.d.ts +29 -0
  37. package/src/masks/generic.d.ts +39 -0
  38. package/src/masks/handler.d.ts +2 -0
  39. package/src/masks/string.d.ts +37 -0
  40. package/src/plugins/credit-card.d.ts +4 -0
  41. package/src/plugins/currency.d.ts +2 -0
  42. package/src/plugins/date.d.ts +2 -0
  43. package/src/plugins/document.d.ts +2 -0
  44. package/src/registry.d.ts +20 -0
  45. package/src/types/event.d.ts +175 -0
  46. package/src/types/form.d.ts +55 -0
  47. package/src/types/mapper.d.ts +87 -0
  48. package/src/types/schema.d.ts +1001 -0
  49. package/src/types/template.d.ts +65 -0
  50. package/src/types/utility.d.ts +12 -0
  51. package/src/validations/creditCard.d.ts +52 -0
  52. package/src/validations/custom.d.ts +27 -0
  53. package/src/validations/date.d.ts +79 -0
  54. package/src/validations/document.d.ts +25 -0
  55. package/src/validations/handler.d.ts +2 -0
  56. package/src/validations/length.d.ts +39 -0
  57. package/src/validations/list.d.ts +32 -0
  58. package/src/validations/logical.d.ts +75 -0
  59. package/src/validations/multiple.d.ts +31 -0
  60. package/src/validations/namedRule.d.ts +22 -0
  61. package/src/validations/number.d.ts +145 -0
  62. package/src/validations/object.d.ts +44 -0
  63. package/src/validations/regex.d.ts +217 -0
  64. package/src/validations/string.d.ts +53 -0
@@ -0,0 +1,357 @@
1
+ import { IFormField } from './field';
2
+ import { Subject, Subscription } from 'rxjs';
3
+ import { IComponentSchema, IComponentSchemaAsFormField, IFormSchema, TPrefetchedFieldData } from '../interfaces/schema';
4
+ import { TSchemaFormConfig } from '../types/schema';
5
+ import { TSubscribedTemplates, TTemplateAvaliableScopes, TTemplateEvent } from '../types/template';
6
+ import { TEvents, TFieldEvent, TFieldValidationPayload, TFormDataPayload, TFormSubmitPayload, TFormValidationPayload, TMutationEvents } from '../types/event';
7
+ import { TFormEntry, TFormValues } from '../types/form';
8
+ import { TMapper } from '../types/mapper';
9
+ import { SafeBehaviourSubject } from '../helpers/SafeSubject';
10
+ /**
11
+ * Represents the core logic for managing a form, including field management, validation, and submission.
12
+ */
13
+ declare class FormCore {
14
+ index: string;
15
+ schema?: IFormSchema;
16
+ fields: Map<string, IFormField>;
17
+ private _iVars;
18
+ templateSubject$: Subject<TTemplateEvent>;
19
+ templateSubscription$: Subscription;
20
+ submitSubject$: Subject<TFormSubmitPayload<unknown>>;
21
+ mountSubject$: Subject<{
22
+ key: string;
23
+ status: boolean;
24
+ }>;
25
+ fieldEventSubject$: Subject<TFieldEvent>;
26
+ dataSubject$: Subject<TFormDataPayload>;
27
+ formValidSubject$: Subject<TFormValidationPayload>;
28
+ fieldValidNotification$: Subject<TFieldValidationPayload>;
29
+ formValuesStateSubject$: SafeBehaviourSubject<TFormValues<unknown>>;
30
+ subscribedTemplates: TSubscribedTemplates[];
31
+ action?: string;
32
+ method?: string;
33
+ config: Required<TSchemaFormConfig>;
34
+ mappers: Map<string, TMapper<unknown>>;
35
+ queuedFieldVisibilityEvents: Map<string, {
36
+ hasError: boolean;
37
+ showOnlyIfTrue?: boolean;
38
+ }>;
39
+ queuedFieldResetValuesEvents: Map<string, {
40
+ value: unknown;
41
+ }>;
42
+ queuedFieldResetPropertyEvents: Map<string, {
43
+ property: string;
44
+ path: string;
45
+ value: unknown;
46
+ }>;
47
+ queuedInitialValues: Map<string, unknown>;
48
+ prefetchedData?: Record<string, TPrefetchedFieldData>;
49
+ _valid: boolean;
50
+ stopEventsOnSubmit: boolean;
51
+ submitted: boolean;
52
+ getFormValues: () => TFormValues<unknown>;
53
+ isolatedFormInstance: boolean;
54
+ /**
55
+ * Creates an instance of FormCore.
56
+ *
57
+ * @param {TFormEntry & Omit<IFormSchema, 'components'>} entry - Configuration options for the form.
58
+ * @param {IFormSchema} entry.schema - The schema definition for the form.
59
+ * @param {Record<string, unknown> | IFormSchema.initialValues} [entry.initialValues] - Initial values for the form fields.
60
+ * @param {string} [entry.action] - The action attribute of the form.
61
+ * @param {string} [entry.method] - The method attribute of the form.
62
+ * @param {IFormSchema.iVars} [entry.iVars] - The internal variables of the form.
63
+ * @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
64
+ */
65
+ constructor(entry: TFormEntry & Omit<IFormSchema, 'components'>);
66
+ /**
67
+ * mock function to simulate form mount onto the adapter
68
+ */
69
+ generateFields(): void;
70
+ /**
71
+ *flag utility to prevent Subjects from emitting after form submission and stopEventsOnSubmit
72
+ * @returns {boolean} - result of the flag utility.
73
+ */
74
+ private submitChecker;
75
+ /**
76
+ * callback function passed to field instance to notify field adapter mount status
77
+ * once the field has all field instance properties set, this function will handle all
78
+ * field routines
79
+ *
80
+ * @param { string } entry.key field unique identifier
81
+ * @param { boolean } entry.status mount status notified from field
82
+ */
83
+ mountActions({ key, status }: {
84
+ key: string;
85
+ status: boolean;
86
+ }): void;
87
+ /**
88
+ * initialValues setter to handle field values set externally from the adapter
89
+ *
90
+ * @param { Record<string, unknown> | undefined } payload initialValues to set onto fields
91
+ */
92
+ set initialValues(payload: Record<string, unknown> | undefined);
93
+ /**
94
+ * Retrieves the internal variables (iVars) of the form.
95
+ *
96
+ * @returns {Record<string, unknown>} - The internal variables of the form.
97
+ */
98
+ get iVars(): Record<string, unknown>;
99
+ /**
100
+ * Sets the internal variables (iVars) of the form and notifies subscribers about the change.
101
+ *
102
+ * @param {Record<string, unknown>} payload - The new internal variables to be set.
103
+ */
104
+ set iVars(payload: Record<string, unknown>);
105
+ /**
106
+ * Validates all form fields and sets the form valid flag
107
+ *
108
+ */
109
+ validateForm(): boolean;
110
+ get valid(): boolean;
111
+ set valid(valid: boolean);
112
+ /**
113
+ * Subscribes to templates for dynamic updates.
114
+ */
115
+ subscribeTemplates(): void;
116
+ /**
117
+ * Gets the value of a property from a field.
118
+ *
119
+ * @param {object} options - Options for getting the value.
120
+ * @param {string} options.key - The key of the field.
121
+ * @param {string} options.property - The property to retrieve.
122
+ * @param {string[]} options.path - The path to the property if it's nested.
123
+ * @returns {unknown | undefined} The value of the property, or undefined if the field doesn't exist.
124
+ */
125
+ getValue({ scope, key, property, path, }: {
126
+ scope: TTemplateAvaliableScopes;
127
+ key: string;
128
+ property: string;
129
+ path: string[];
130
+ }): unknown | undefined;
131
+ /**
132
+ * Sets the value of a property in a field.
133
+ *
134
+ * @param {object} options - Options for setting the value.
135
+ * @param {string} options.key - The key of the field.
136
+ * @param {string} options.property - The property to set.
137
+ * @param {string[]} options.path - The path to the property if it's nested.
138
+ * @param {unknown} options.originKey - field that called templating
139
+ * @param {unknown} options.value - The value to set.
140
+ * @param {TMutationEvents} options.event - Internal Event for template Handling.
141
+ */
142
+ setValue({ key, property, path, originKey, value, }: {
143
+ key: string;
144
+ property: string;
145
+ path: string[];
146
+ originKey?: string;
147
+ value: unknown;
148
+ event: TMutationEvents;
149
+ }): void;
150
+ /**
151
+ * Extracts parameters from an expression.
152
+ *
153
+ * @param {string} expression - The expression containing parameters.
154
+ * @returns {string[]} An array of extracted parameters.
155
+ */
156
+ extractParams(expression: string): unknown[];
157
+ /**
158
+ * Replaces expressions marked by ${...} in the expression string with the provided values.
159
+ *
160
+ * @param {string} expression - The expression string containing the marked expressions.
161
+ * @param {string[]} values - The values to be inserted into the marked expressions.
162
+ * @returns {string} The expression string with the replacements made.
163
+ */
164
+ replaceExpression(expression: string, values: unknown[]): string;
165
+ /**
166
+ * Checks if an expression string contains string concatenation within a marked expression.
167
+ *
168
+ * @param {string} expression - The expression string to be checked.
169
+ * @returns {boolean} True if the expression contains string concatenation, otherwise false.
170
+ */
171
+ hasStringConcatenation(expression: string): boolean;
172
+ /**
173
+ * Refreshes templates with updated values.
174
+ *
175
+ * @param {object} options - Options for refreshing templates.
176
+ * @param {string} options.key - The key of the field triggering the update.
177
+ * @param {TMutationEvents} options.event - Internal event descriptor to handle templating.
178
+ */
179
+ refreshTemplates({ key, event }: TTemplateEvent): void;
180
+ /**
181
+ * executes events that were stored due to field unavaliability
182
+ *
183
+ * @param {string} field field to check
184
+ */
185
+ checkFieldEventQueues(field: string): void;
186
+ /**
187
+ * Validates and collects the names of form fields in the provided schema structure.
188
+ *
189
+ * @param {IComponentSchema[]} [struct] - The schema structure of the form components.
190
+ * @param {string[]} [indexes=[]] - An array to collect the names of the form fields.
191
+ * @returns {string[]} - An array of form field names.
192
+ * @throws {Error} - Throws an error if a field name matches the reserved name defined by `IVARPROPNAME`.
193
+ * @private
194
+ */
195
+ private static checkIndexes;
196
+ /**
197
+ * @internal
198
+ * Update field visibility accordingly.
199
+ *
200
+ * @param {object} options - options to set field visibility
201
+ * @param {string} options.field - Field name to be updated.
202
+ * @param {boolean} options.hasError - Condition to be used as visibility.
203
+ * @param {boolean|undefined} options.showOnlyIfTrue - Flag to be considered when update field visibility. If it's true, then considered error, if it's false, always considered the opposite.
204
+ */
205
+ private setFieldVisibility;
206
+ /**
207
+ * Validates visibility conditions for a given event and updates field visibility accordingly.
208
+ *
209
+ * @param {object} options - Options for validating visibility.
210
+ * @param {TEvents} options.event - The event triggering visibility validation.
211
+ * @param {string} options.key - The key of the field.
212
+ */
213
+ validateVisibility({ event, key }: {
214
+ event: TEvents;
215
+ key: string;
216
+ }): void;
217
+ /**
218
+ * @internal
219
+ * Update field value and emit change and cleared event.
220
+ *
221
+ * @param {options} options to reset the field value
222
+ * @param {string} options.key - Field name to be updated.
223
+ * @param {unknown} options.value - Value to be inserted into field.
224
+ */
225
+ private setResetFieldValue;
226
+ /**
227
+ * Resets field values based on reset conditions defined in the schema.
228
+ *
229
+ * @param {object} options - Options for resetting field values.
230
+ * @param {TEvents} options.event - The event triggering the reset.
231
+ * @param {string} options.key - The key of the field.
232
+ */
233
+ resetValue({ event, key }: {
234
+ event: TEvents;
235
+ key: string;
236
+ }): void;
237
+ /**
238
+ * @internal
239
+ * Update field property and emit template change.
240
+ *
241
+ * @param {object} options - Options for resetting field property
242
+ * @param {string} options.key - Field name to be updated.
243
+ * @param {string} options.property - field property to change.
244
+ * @param {string} options.path - field property path to change.
245
+ * @param {unknown} options.value - Value to be inserted into field.
246
+ */
247
+ private setResetPathValue;
248
+ /**
249
+ * Resets field properties based on reset conditions defined in the schema.
250
+ *
251
+ * @param {object} options - Options for resetting field property.
252
+ * @param {TEvents} options.event - The event triggering the reset.
253
+ * @param {string} options.key - The key of the field.
254
+ */
255
+ resetProperty({ event, key }: {
256
+ event: TEvents;
257
+ key: string;
258
+ }): void;
259
+ /**
260
+ * Adds a field onto the form instance regardless there is a schema or not
261
+ *
262
+ * @param fieldSchema
263
+ * @param mapperElement
264
+ */
265
+ addField({ fieldSchema, mapperElement, path, }: {
266
+ fieldSchema: IComponentSchema;
267
+ mapperElement?: TMapper<unknown>;
268
+ path?: string;
269
+ }): void;
270
+ /**
271
+ * function to be called from the adapter to remove a field when a field is removed from it
272
+ *
273
+ * @param {{ key: string }} entry.key
274
+ */
275
+ removeField({ key }: {
276
+ key: string;
277
+ }): void;
278
+ /**
279
+ * Serializes the schema structure to create form fields.
280
+ *
281
+ * @param {IComponentSchema[]} [struct] - The schema structure to serialize.
282
+ * @param {string} [path] - The path of the parent component.
283
+ */
284
+ serializeStructure(struct?: IComponentSchemaAsFormField<unknown>[], path?: string): void;
285
+ /**
286
+ * Refreshes form fields based on changes in the schema structure.
287
+ *
288
+ * @param {IComponentSchema[]} struct - The updated schema structure.
289
+ */
290
+ refreshFields(struct: IComponentSchemaAsFormField<unknown>[]): void;
291
+ /**
292
+ * Gets a form field by its key.
293
+ *
294
+ * @param {object} options - Options for getting the form field.
295
+ * @param {string} options.key - The key of the form field.
296
+ * @returns {IFormField | undefined} The form field, or undefined if not found.
297
+ */
298
+ getField({ key }: {
299
+ key: string;
300
+ }): IFormField | undefined;
301
+ /**
302
+ * Prints the current values of all form fields.
303
+ */
304
+ printValues(): void;
305
+ /**
306
+ * Gets the current values of all form fields.
307
+ *
308
+ * @returns {TFormValues} The current form values.
309
+ */
310
+ getFormState<T>(): TFormValues<T>;
311
+ /**
312
+ * function to be called to events sent from the adapter
313
+ *
314
+ * @param {{callback: (payload: TFieldEvent) => void}} entry.callback callback function from the adapter
315
+ * @returns
316
+ */
317
+ subscribeFieldEvent({ callback, }: {
318
+ callback: (payload: TFieldEvent) => void;
319
+ }): Subscription;
320
+ /**
321
+ * to be called from the adapter when the form mounts
322
+ *
323
+ * @param {(payload: TFormValues<T>) => void} callback
324
+ * @returns Subscription
325
+ */
326
+ subscribeOnMount<T>(callback: (payload: TFormValues<T>) => void): Subscription;
327
+ /**
328
+ *
329
+ * @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call onData
330
+ */
331
+ subscribeData<T>(callback: (payload: {
332
+ field: string;
333
+ data: TFormValues<T>;
334
+ }) => void): Subscription;
335
+ /**
336
+ * method to register a callback function to be called when the form is valid
337
+ *
338
+ * @param {(payload: TFormValues<T>) => void} callback callback function to call when the submit action occurs
339
+ */
340
+ subscribeOnSubmit<T>(callback: (payload: TFormValues<T>) => void): Subscription;
341
+ /**
342
+ * method to check whenever the validity status of the form changes, only emits on status change
343
+ *
344
+ * @param {(payload: TFormValidationPayload) => void} callback callback function to call onValid
345
+ */
346
+ subscribeFormValidation(callback: (payload: TFormValidationPayload) => void): Subscription;
347
+ /**
348
+ * Submits the form by triggering form field events and invoking the onSubmit callback.
349
+ */
350
+ submit<T>(): void;
351
+ /**
352
+ * recycles all the Suscriptions, to be called from the adapter when the form leaves the page
353
+ */
354
+ destroy(): void;
355
+ }
356
+ type TFormCore = FormCore;
357
+ export { TFormCore, FormCore };
@@ -0,0 +1,110 @@
1
+ import { Subject } from 'rxjs';
2
+ import { TFormEntry, TFormValues } from '../types/form';
3
+ import { TMapper } from '../types/mapper';
4
+ import { TFormCore } from './form';
5
+ import { TSchemaFormConfig } from '../types/schema';
6
+ import { TFormDataPayload, TFormGroupOnDataEventPayload, TFormGroupOnSubmitEventPayload, TFormGroupOnValidEventPayload, TFormSubmitPayload, TFormValidationPayload } from '../types/event';
7
+ /**
8
+ * Represents a group that manages multiple forms.
9
+ */
10
+ declare class FormGroup<ComponentElementType> {
11
+ forms: Map<string, TFormCore>;
12
+ config: Required<TSchemaFormConfig>;
13
+ dataSubject$: Subject<TFormDataPayload>;
14
+ formValidSubject$: Subject<TFormValidationPayload>;
15
+ submitSubject$: Subject<TFormSubmitPayload<unknown>>;
16
+ mappers?: TMapper<ComponentElementType>[];
17
+ /**
18
+ * Creates an instance of FormGroup.
19
+ */
20
+ constructor(entry?: {
21
+ mappers?: TMapper<ComponentElementType>[];
22
+ config?: TSchemaFormConfig;
23
+ });
24
+ /**
25
+ * Creates an empty form with given index
26
+ *
27
+ * @param {string} options.index
28
+ * @param {TMapper<unknown>} options.mappers
29
+ */
30
+ createFormWithIndex({ index, mappers, }: {
31
+ index: string;
32
+ mappers?: TMapper<unknown>[];
33
+ }): void;
34
+ /**
35
+ * Adds a form instance to the form group.
36
+ *
37
+ * @param {object} options - Options for adding a form.
38
+ * @param {string} options.key - The key associated with the form instance.
39
+ * @param {TFormCore} options.formInstance - The instance of the form to add.
40
+ */
41
+ addForm({ key, params }: {
42
+ key: string;
43
+ params: TFormEntry;
44
+ }): void;
45
+ /**
46
+ * Retrieves a form instance from the form group.
47
+ *
48
+ * @param {object} options - Options for retrieving a form.
49
+ * @param {string} options.key - The key associated with the form instance.
50
+ * @returns {TFormCore | undefined} The instance of the form, if found; otherwise, undefined.
51
+ */
52
+ getForm({ key }: {
53
+ key: string;
54
+ }): TFormCore | undefined;
55
+ /**
56
+ * Removes a form instance from the form group.
57
+ *
58
+ * @param {object} options - Options for removing a form.
59
+ * @param {string} options.key - The key associated with the form instance to remove.
60
+ */
61
+ removeForm({ key }: {
62
+ key: string;
63
+ }): void;
64
+ /**
65
+ * removes a field given a form and field index
66
+ *
67
+ * @param {string} options.formIndex
68
+ * @param {string} options.fieldIndex
69
+ */
70
+ removeField({ formIndex, fieldIndex, }: {
71
+ formIndex: string;
72
+ fieldIndex: string;
73
+ }): void;
74
+ /**
75
+ * Checks if the specified key already exists in the form group.
76
+ *
77
+ * @param {object} options - Options for checking the key.
78
+ * @param {string} options.key - The key to check.
79
+ * @throws {Error} Throws an error if the key already exists in the form group.
80
+ */
81
+ checkIndexes({ key }: {
82
+ key: string;
83
+ }): void;
84
+ /**
85
+ * Prints the form group instance to the console.
86
+ */
87
+ printFormGroupInstance(): void;
88
+ /**
89
+ * Prototype submit function to multiple forms
90
+ * @param {string[]} indexes form indexes to be submitted
91
+ * @param callback
92
+ * @returns
93
+ */
94
+ submitMultipleFormsByIndex<T>(indexes: string[], callback?: (payload: TFormValues<T>) => void): void;
95
+ onDataSubscription<T>({ ids, callback, }: {
96
+ ids: string[];
97
+ callback: (payload: TFormGroupOnDataEventPayload<T>) => void;
98
+ }): import("rxjs").Subscription;
99
+ onValidSubscription({ ids, callback, }: {
100
+ ids: string[];
101
+ callback: (payload: TFormGroupOnValidEventPayload) => void;
102
+ }): import("rxjs").Subscription;
103
+ onSubmitSubscription<T>({ ids, callback, }: {
104
+ ids: string[];
105
+ callback: (payload: TFormGroupOnSubmitEventPayload<T>) => void;
106
+ }): import("rxjs").Subscription;
107
+ destroy: () => void;
108
+ }
109
+ type TFormGroup<T> = FormGroup<T>;
110
+ export { TFormGroup, FormGroup };
@@ -0,0 +1,3 @@
1
+ export * from './form';
2
+ export * from './field';
3
+ export * from './formGroup';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Applies a secure mask to a credit card number, hiding most of its digits.
3
+ *
4
+ * @param value - The credit card number to be masked.
5
+ * @returns The masked credit card number.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { secureCreditCard } from './path/to/creditCardFunctions';
10
+ *
11
+ * const maskedCardNumber = secureCreditCard('1234567890123456');
12
+ * console.log(maskedCardNumber); // Output: '1xxxxxxxxxxxx456'
13
+ * ```
14
+ */
15
+ export declare const secureCreditCard: (value: string) => string;
16
+ /**
17
+ * Formats a credit card number by inserting spaces every four characters.
18
+ *
19
+ * @param value - The credit card number to be formatted.
20
+ * @returns The formatted credit card number.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { card } from './path/to/creditCardFunctions';
25
+ *
26
+ * const formattedCardNumber = card('1234567890123456');
27
+ * console.log(formattedCardNumber); // Output: '1234 5678 9012 3456'
28
+ * ```
29
+ */
30
+ export declare const card: (value: string) => string;
31
+ /**
32
+ * Formats a credit card expiration date (MM/YY).
33
+ *
34
+ * @param value - The expiration date to be formatted (in MMYY or MM/YY format).
35
+ * @returns The formatted expiration date.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * import { cardDate } from './path/to/creditCardFunctions';
40
+ *
41
+ * const formattedCardDate = cardDate('1223');
42
+ * console.log(formattedCardDate); // Output: '12/23'
43
+ * ```
44
+ */
45
+ export declare const cardDate: (value: string) => string;
46
+ /**
47
+ * Formats a credit card FEIN (Federal Employer Identification Number) in a specific format.
48
+ *
49
+ * @param value - The FEIN to be formatted.
50
+ * @returns The formatted FEIN.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { fein } from './path/to/creditCardFunctions';
55
+ *
56
+ * const formattedFEIN = fein('123456789');
57
+ * console.log(formattedFEIN); // Output: '12-3456789'
58
+ * ```
59
+ */
60
+ export declare const fein: (value: string) => string;
@@ -0,0 +1,29 @@
1
+ import { TMasks } from '../types/schema';
2
+ /**
3
+ * Formats a numeric value as a currency string based on the provided mask configuration.
4
+ *
5
+ * @param value - The numeric value to be formatted.
6
+ * @param masks - An object containing the mask configuration.
7
+ * @returns The formatted currency string.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { currency } from './path/to/maskFunctions';
12
+ *
13
+ * const masks = {
14
+ * currency: {
15
+ * align: 'right',
16
+ * decimal: ',',
17
+ * precision: 2,
18
+ * prefix: 'USD',
19
+ * thousands: '.'
20
+ * }
21
+ * };
22
+ *
23
+ * const formattedValue = currency(12345.67, masks);
24
+ * console.log(formattedValue); // Output: '12.345,67 $'
25
+ *
26
+ * PS: To unCurrency this value, usage onlyFloatNumber formatter
27
+ * ```
28
+ */
29
+ export declare const currency: (value: string | number, masks: TMasks) => unknown;
@@ -0,0 +1,39 @@
1
+ import { TMasks } from '../types/schema';
2
+ /**
3
+ * Applies multiple generic masks to a string based on the provided mask configuration.
4
+ *
5
+ * @param value - The value to be masked.
6
+ * @param masks - An object containing the mask configuration.
7
+ * @returns The masked value.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import maskValue from './path/to/maskFunctions';
12
+ *
13
+ * const masks = {
14
+ * generic: [
15
+ * { from: 2, to: 4, mask: '*' },
16
+ * { from: 7, to: 9, mask: '#' }
17
+ * ]
18
+ * };
19
+ *
20
+ * const maskedValue = maskValue('123456789', masks);
21
+ * console.log(maskedValue); // Output: '1**45###9'
22
+ *
23
+ * // Using from a JSON config
24
+ * const config = {
25
+ * value: 'abcdefghij',
26
+ * masks: {
27
+ * generic: [
28
+ * { from: 3, to: 6, mask: '*' },
29
+ * { from: 8, to: 10, mask: '#' }
30
+ * ]
31
+ * }
32
+ * };
33
+ *
34
+ * const maskedValue = maskValue(config.value, config.masks);
35
+ * console.log(maskedValue); // Output: 'ab***gh###'
36
+ * ```
37
+ */
38
+ declare const _default: (value: string, masks: TMasks | null) => string;
39
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { TMasks } from '../types/schema';
2
+ export declare const masks: Record<string, (value: unknown, masks?: TMasks | null) => unknown>;
@@ -0,0 +1,37 @@
1
+ import { TMasks } from '../types/schema';
2
+ /**
3
+ * Replaces all characters in a string with a specified replacement string or character.
4
+ *
5
+ * @param value - The value to be masked.
6
+ * @param masks - An object containing the mask configuration.
7
+ * @returns The masked value.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { replaceAll } from './path/to/maskFunctions';
12
+ *
13
+ * const masks = { replaceAll: '*' };
14
+ *
15
+ * const maskedValue = replaceAll('12345', masks);
16
+ * console.log(maskedValue); // Output: '*****'
17
+ * ```
18
+ */
19
+ export declare const replaceAll: (value: string | number, masks: TMasks) => unknown;
20
+ /**
21
+ * Applies a custom mask to a string based on the provided mask configuration.
22
+ *
23
+ * @param value - The value to be masked.
24
+ * @param masks - An object containing the mask configuration.
25
+ * @returns The masked value.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * import { custom } from './path/to/maskFunctions';
30
+ *
31
+ * const masks = { custom: '##-##' };
32
+ *
33
+ * const maskedValue = custom('123456', masks);
34
+ * console.log(maskedValue); // Output: '12-34'
35
+ * ```
36
+ */
37
+ export declare const custom: (value: string, masks: TMasks) => string;
@@ -0,0 +1,4 @@
1
+ import { isCreditCard, isCreditCardAndLength, isCreditCodeMatch } from '../validations/creditCard';
2
+ import { gapsCreditCard } from '../formatters/creditCard';
3
+ import { secureCreditCard, card, cardDate, fein } from '../masks/creditCard';
4
+ export { isCreditCard, isCreditCardAndLength, isCreditCodeMatch, gapsCreditCard, secureCreditCard, card, cardDate, fein, };
@@ -0,0 +1,2 @@
1
+ import { currency } from '../masks/currency';
2
+ export { currency };
@@ -0,0 +1,2 @@
1
+ import { date, betweenDates, validDate } from '../validations/date';
2
+ export { date, betweenDates, validDate };
@@ -0,0 +1,2 @@
1
+ import document from '../validations/document';
2
+ export { document };
@@ -0,0 +1,20 @@
1
+ import { TValidationHandler } from './types/utility';
2
+ /**
3
+ * Global mutable registries for validations, formatters, and masks.
4
+ * Plugins (sub-path exports) can extend these at import time.
5
+ */
6
+ export declare const validationRegistry: TValidationHandler;
7
+ export declare const formatterRegistry: Record<string, (value: unknown, formatters?: any) => unknown>;
8
+ export declare const maskRegistry: Record<string, (value: unknown, masks?: any) => unknown>;
9
+ /**
10
+ * Registers additional validation methods into the global registry.
11
+ */
12
+ export declare function registerValidations(methods: TValidationHandler): void;
13
+ /**
14
+ * Registers additional formatter methods into the global registry.
15
+ */
16
+ export declare function registerFormatters(methods: Record<string, (value: unknown, formatters?: any) => unknown>): void;
17
+ /**
18
+ * Registers additional mask methods into the global registry.
19
+ */
20
+ export declare function registerMasks(methods: Record<string, (value: unknown, masks?: any) => unknown>): void;