@bolttech/form-engine-core 0.0.1-beta.1

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 (40) hide show
  1. package/index.esm.d.ts +1 -0
  2. package/index.esm.js +3518 -0
  3. package/package.json +14 -0
  4. package/src/formatters/creditCard.d.ts +23 -0
  5. package/src/formatters/custom.d.ts +29 -0
  6. package/src/formatters/handler.d.ts +2 -0
  7. package/src/formatters/regex.d.ts +47 -0
  8. package/src/formatters/splitter.d.ts +17 -0
  9. package/src/formatters/string.d.ts +88 -0
  10. package/src/helpers/creditCard.d.ts +95 -0
  11. package/src/helpers/helpers.d.ts +64 -0
  12. package/src/index.d.ts +10 -0
  13. package/src/interfaces/schema.d.ts +82 -0
  14. package/src/interfaces/state.d.ts +27 -0
  15. package/src/managers/field.d.ts +294 -0
  16. package/src/managers/form.d.ts +224 -0
  17. package/src/managers/formGroup.d.ts +64 -0
  18. package/src/masks/creditCard.d.ts +60 -0
  19. package/src/masks/generic.d.ts +39 -0
  20. package/src/masks/handler.d.ts +2 -0
  21. package/src/masks/string.d.ts +97 -0
  22. package/src/types/event.d.ts +43 -0
  23. package/src/types/form.d.ts +51 -0
  24. package/src/types/mapper.d.ts +94 -0
  25. package/src/types/schema.d.ts +742 -0
  26. package/src/types/template.d.ts +32 -0
  27. package/src/types/utility.d.ts +4 -0
  28. package/src/validations/creditCard.d.ts +52 -0
  29. package/src/validations/custom.d.ts +25 -0
  30. package/src/validations/date.d.ts +78 -0
  31. package/src/validations/document.d.ts +25 -0
  32. package/src/validations/handler.d.ts +2 -0
  33. package/src/validations/length.d.ts +39 -0
  34. package/src/validations/list.d.ts +32 -0
  35. package/src/validations/logical.d.ts +75 -0
  36. package/src/validations/multiple.d.ts +31 -0
  37. package/src/validations/number.d.ts +115 -0
  38. package/src/validations/object.d.ts +44 -0
  39. package/src/validations/regex.d.ts +217 -0
  40. package/src/validations/string.d.ts +53 -0
@@ -0,0 +1,294 @@
1
+ import { Observable, Subject, Subscription } from 'rxjs';
2
+ import { TApiConfig, TApiEvent, TApiResponse, TErrorMessages, TEvent, TFormatters, TMasks, TResetValueMethods, TValidationMethods, TVisibility } from '../types/schema';
3
+ import { IComponentSchema } from '../interfaces/schema';
4
+ import { IState } from '../interfaces/state';
5
+ import { TEvents, TMutationEvents, TValueChangeEvent } from '../types/event';
6
+ import { TMapper } from '../types/mapper';
7
+ /**
8
+ * Represents a form field with observables for managing form state, validations, and API requests.
9
+ */
10
+ declare class FormField {
11
+ name: string;
12
+ component: string;
13
+ path?: string;
14
+ children: string[];
15
+ validations?: TEvent<TValidationMethods>;
16
+ visibilityConditions?: TVisibility[];
17
+ resetValues?: TResetValueMethods[];
18
+ errorMessages?: TErrorMessages;
19
+ apiSchema?: TApiEvent;
20
+ formatters?: TFormatters;
21
+ masks?: TMasks;
22
+ valuePropName?: string;
23
+ errorMessagePropName?: string;
24
+ initialValue?: unknown;
25
+ mapper: TMapper<unknown>;
26
+ private _props;
27
+ private _value;
28
+ private _stateValue;
29
+ private _metadata;
30
+ private _visibility;
31
+ private _errors;
32
+ private _errorsString;
33
+ private _api;
34
+ private _valid;
35
+ propsSubject$: Subject<Record<string, unknown>>;
36
+ errorSubject$: Subject<string[]>;
37
+ valueSubject$: Subject<unknown>;
38
+ visibilitySubject$: Subject<boolean>;
39
+ apiSubject$: Subject<TApiResponse>;
40
+ apiResponseSubject$: Subject<{
41
+ key: string;
42
+ }>;
43
+ apiEventQueueSubject$: Subject<{
44
+ event: TEvents;
45
+ }>;
46
+ fieldState$: Observable<IState>;
47
+ fieldStateSubscription$: Subscription;
48
+ templateSubject$: Subject<{
49
+ key: string;
50
+ event: TMutationEvents;
51
+ }>;
52
+ dataSubject$: Subject<{
53
+ key: string;
54
+ event: TEvents;
55
+ }>;
56
+ validateVisibility: (payload: {
57
+ event: TEvents;
58
+ key: string;
59
+ }) => void;
60
+ resetValue: (payload: {
61
+ event: TEvents;
62
+ key: string;
63
+ }) => void;
64
+ valueChangeEvent: TValueChangeEvent;
65
+ /**
66
+ * Creates an instance of FormField.
67
+ *
68
+ * @param {object} options - Configuration options for the form field.
69
+ * @param {IComponentSchema} options.schemaComponent - The schema definition for the form field.
70
+ * @param {string} [options.path] - The path within the form field (used internally during recursion).
71
+ * @param {string[]} options.children - An array of children fields names.
72
+ * @param {Function} options.validateVisibility - A function to validate the visibility of the field.
73
+ * @param {Function} options.resetValue - A function to reset the field value.
74
+ * @param {unknown} [options.initialValue] - The initial value of the form field.
75
+ * @param {Subject<{ key: string }>} options.templateSubject$ - A subject for template updates.
76
+ */
77
+ constructor({ schemaComponent, path, children, validateVisibility, resetValue, initialValue, templateSubject$, apiResponseSubject$, dataSubject$, mapper, }: {
78
+ schemaComponent: IComponentSchema;
79
+ path?: string;
80
+ children: string[];
81
+ validateVisibility: (payload: {
82
+ event: TEvents;
83
+ key: string;
84
+ }) => void;
85
+ resetValue: (payload: {
86
+ event: TEvents;
87
+ key: string;
88
+ }) => void;
89
+ initialValue?: unknown;
90
+ templateSubject$: Subject<{
91
+ key: string;
92
+ event: TMutationEvents;
93
+ }>;
94
+ apiResponseSubject$: Subject<{
95
+ key: string;
96
+ }>;
97
+ dataSubject$: Subject<{
98
+ key: string;
99
+ event: TEvents;
100
+ }>;
101
+ mapper: TMapper<unknown>;
102
+ });
103
+ /**
104
+ * method to initialize all recycled Subjects and initialize Observers on field instance creation or rerender
105
+ */
106
+ initializeObservers(): void;
107
+ /**
108
+ * Observable function to emit api events debounced and distinct for each event type,
109
+ * avoiding previous events being cancelled by new events if they occur inside the debounce time interval
110
+ *
111
+ * @param {(event: { event: TEvents }) => TEvents} keyExtractor function that will pass the event key to the groupBy operator
112
+ * @param {number} debounceTimeMs time to wait for each individual event emmited
113
+ * @returns
114
+ */
115
+ debounceDistinct(keyExtractor: (event: {
116
+ event: TEvents;
117
+ }) => TEvents, debounceTimeMs: number): (source$: Observable<{
118
+ event: TEvents;
119
+ }>) => Observable<{
120
+ event: TEvents;
121
+ }>;
122
+ /**
123
+ * Retrieves the properties associated with the form field.
124
+ *
125
+ * @returns {Record<string, unknown>} - The properties of the form field.
126
+ */
127
+ get props(): Record<string, unknown>;
128
+ /**
129
+ * Sets the properties of the form field and notifies subscribers about the change.
130
+ *
131
+ * @param {Record<string, unknown>} props - The new properties to be set.
132
+ */
133
+ set props(props: Record<string, unknown>);
134
+ /**
135
+ * Retrieves the current state value of the form field.
136
+ *
137
+ * @returns {unknown} - The current state value of the form field.
138
+ */
139
+ get stateValue(): unknown;
140
+ get metadata(): unknown;
141
+ /**
142
+ * Retrieves the concatenated string of errors associated with the form field.
143
+ *
144
+ * @returns {string} - The concatenated string of errors.
145
+ */
146
+ get errorsString(): string;
147
+ /**
148
+ * Retrieves the current value of the form field.
149
+ *
150
+ * @returns {unknown} - The current value of the form field.
151
+ */
152
+ get value(): unknown;
153
+ /**
154
+ * Sets the value of the form field and notifies subscribers about the change.
155
+ *
156
+ * @param {unknown} value - The new value to be set.
157
+ */
158
+ set value(value: unknown);
159
+ /**
160
+ * Retrieves the visibility status of the form field.
161
+ *
162
+ * @returns {boolean} - The visibility status of the form field.
163
+ */
164
+ get visibility(): boolean;
165
+ /**
166
+ * Sets the visibility status of the form field and notifies subscribers about the change.
167
+ *
168
+ * @param {boolean} visible - The new visibility status to be set.
169
+ */
170
+ set visibility(visible: boolean);
171
+ /**
172
+ * Retrieves the validity status of the form field.
173
+ *
174
+ * @returns {boolean} - The validity status of the form field.
175
+ */
176
+ get valid(): boolean;
177
+ /**
178
+ * Retrieves the error messages associated with the form field.
179
+ *
180
+ * @returns {TErrorMessages} - The error messages associated with the form field.
181
+ */
182
+ get errors(): TErrorMessages;
183
+ /**
184
+ * Sets the error messages associated with the form field and notifies subscribers about the change.
185
+ *
186
+ * @param {TErrorMessages} errors - The new error messages to be set.
187
+ */
188
+ set errors(errors: TErrorMessages);
189
+ /**
190
+ * Retrieves the API response data associated with the form field.
191
+ *
192
+ * @returns {TApiResponse} - The API response data associated with the form field.
193
+ */
194
+ get api(): TApiResponse;
195
+ /**
196
+ * Sets the API response data associated with the form field and notifies subscribers about the change.
197
+ *
198
+ * @param {TApiResponse} response - The new API response data to be set.
199
+ */
200
+ set api(response: TApiResponse);
201
+ /**
202
+ * Mounts the form field by initializing necessary subjects and combining their streams.
203
+ *
204
+ * @param {object} mountOpts - Adapter mount options.
205
+ * @param {string} prop.valuePropName - Adapter value property name.
206
+ * @param {(event: unknown) => unknown} prop.valueChangeEvent - Adapter change event handler function
207
+ * @param {(value: unknown) => unknown} prop.valueSubscription - Adapter value change function
208
+ * @param {(payload: Partial<IState>) => unknown} prop.propsSubscription - Adapter prop change function
209
+ * @param {string} prop.errorMessagePropName - error message property name to set errors onto component
210
+ * @returns {void}
211
+ */
212
+ mountField({ valueSubscription, propsSubscription, }: {
213
+ valueSubscription: (value: unknown) => void;
214
+ propsSubscription: (payload: Partial<IState>) => void;
215
+ }): void;
216
+ /**
217
+ * Sets the value of the form field and emits associated events.
218
+ *
219
+ * @param {unknown} prop.value - The new value to be set.
220
+ * @param {TEvents} prop.event - The event associated with setting the value.
221
+ * @returns {void}
222
+ */
223
+ emitValue(prop: {
224
+ value: unknown | {
225
+ _value: unknown;
226
+ _stateValue: unknown;
227
+ };
228
+ event: TEvents;
229
+ }): void;
230
+ /**
231
+ * Emits events to trigger field-related actions such as validation, visibility checks, value resets, and API requests.
232
+ *
233
+ * @param {TEvents} event - The event type that triggers the field actions.
234
+ * @returns {void}
235
+ */
236
+ emitEvents({ event }: {
237
+ event: TEvents;
238
+ }): void;
239
+ /**
240
+ * Sets the validity state of the field based on the provided validation rules and triggers error message updates.
241
+ *
242
+ * @param {TEvents} event - The event type associated with the field action.
243
+ * @returns {void}
244
+ */
245
+ setFieldValidity({ event }: {
246
+ event: TEvents;
247
+ }): void;
248
+ /**
249
+ * Formats the field value using the specified formatters, if available.
250
+ *
251
+ * @param {unknown} value - The value to be formatted.
252
+ * @returns {unknown} - The formatted value.
253
+ */
254
+ formatValue(value: unknown): unknown;
255
+ /**
256
+ * Masks the field value using the specified masks, if available.
257
+ *
258
+ * @param {unknown} value - The value to be masked.
259
+ * @returns {unknown} - The masked value.
260
+ */
261
+ maskValue(value: unknown): unknown;
262
+ checkApiRequestValidations(config: TApiConfig): boolean;
263
+ /**
264
+ * Makes an API request based on the field's API configuration and event type, updating the field's API response data.
265
+ *
266
+ * @param {TEvents} event - The event type associated with the API request.
267
+ * @returns {Promise<void>}
268
+ */
269
+ apiRequest({ event }: {
270
+ event: TEvents;
271
+ }): Promise<void>;
272
+ /**
273
+ * Unsubscribes from all subject subscriptions associated with the field, cleaning up resources.
274
+ *
275
+ * @returns {void}
276
+ */
277
+ destroyField(): void;
278
+ /**
279
+ * Subscribes to changes in the field state and executes the provided callback function.
280
+ *
281
+ * @param {Function} callback - The callback function to be executed when the field state changes.
282
+ * @returns {void}
283
+ */
284
+ subscribeState(callback: (payload: Partial<IState>) => void): void;
285
+ /**
286
+ * Subscribes to changes in the field value and executes the provided callback function.
287
+ *
288
+ * @param {Function} callback - The callback function to be executed when the field value changes.
289
+ * @returns {void}
290
+ */
291
+ subscribeValue(callback: (value: unknown) => void): void;
292
+ }
293
+ type IFormField = FormField;
294
+ export { IFormField, FormField };
@@ -0,0 +1,224 @@
1
+ import { IFormField } from './field';
2
+ import { Subject, Subscription } from 'rxjs';
3
+ import { IComponentSchema, IFormSchema } from '../interfaces/schema';
4
+ import { TSubscribedTemplates } from '../types/template';
5
+ import { TEvents, TMutationEvents } from '../types/event';
6
+ import { TFormEntry, TFormValues } from '../types/form';
7
+ import { TMapper } from '../types/mapper';
8
+ /**
9
+ * Represents the core logic for managing a form, including field management, validation, and submission.
10
+ */
11
+ declare class FormCore {
12
+ schema?: IFormSchema;
13
+ fields: Map<string, IFormField>;
14
+ initialValues?: Record<string, unknown>;
15
+ private _iVars;
16
+ templateSubject$: Subject<{
17
+ key: string;
18
+ event: TMutationEvents;
19
+ }>;
20
+ submitSubject$: Subject<TFormValues>;
21
+ apiResponseSubject$: Subject<{
22
+ key: string;
23
+ }>;
24
+ dataSubject$: Subject<{
25
+ key: string;
26
+ event: TEvents;
27
+ }>;
28
+ dataCallbackSubscription$: Subscription;
29
+ subscribedTemplates: TSubscribedTemplates[];
30
+ action?: string;
31
+ method?: string;
32
+ mappers: TMapper<unknown>[];
33
+ onSubmit?: (data: TFormValues) => void;
34
+ /**
35
+ * Creates an instance of FormCore.
36
+ *
37
+ * @param {TFormEntry & Omit<IFormSchema, 'components'>} entry - Configuration options for the form.
38
+ * @param {IFormSchema} entry.schema - The schema definition for the form.
39
+ * @param {Record<string, unknown> | IFormSchema.initialValues} [entry.initialValues] - Initial values for the form fields.
40
+ * @param {string} [entry.action] - The action attribute of the form.
41
+ * @param {string} [entry.method] - The method attribute of the form.
42
+ * @param {IFormSchema.iVars} [entry.iVars] - The internal variables of the form.
43
+ * @param {(data: TFormValues) => void} [entry.onSubmit] - A callback function to handle form submission.
44
+ * @param {((payload: {field: string;data: TFormValues;}) => void) | undefined} [entry.onData] - A callback function to handle data emission.
45
+ */
46
+ constructor(entry: TFormEntry & Omit<IFormSchema, 'components'>);
47
+ /**
48
+ * Retrieves the internal variables (iVars) of the form.
49
+ *
50
+ * @returns {Record<string, unknown>} - The internal variables of the form.
51
+ */
52
+ get iVars(): Record<string, unknown>;
53
+ /**
54
+ * Sets the internal variables (iVars) of the form and notifies subscribers about the change.
55
+ *
56
+ * @param {Record<string, unknown>} payload - The new internal variables to be set.
57
+ */
58
+ set iVars(payload: Record<string, unknown>);
59
+ /**
60
+ * Checks if the form is valid by validating all form fields.
61
+ *
62
+ * @returns {boolean} True if the form is valid; otherwise, false.
63
+ */
64
+ get isValid(): boolean;
65
+ /**
66
+ * Subscribes to templates for dynamic updates.
67
+ */
68
+ subscribeTemplates(): void;
69
+ /**
70
+ *
71
+ * @param {(payload: { field: string; data: TFormValues }) => void} callback callback function to call on data
72
+ */
73
+ subscribeData(callback: (payload: {
74
+ field: string;
75
+ data: TFormValues;
76
+ }) => void): void;
77
+ /**
78
+ * Gets the value of a property from a field.
79
+ *
80
+ * @param {object} options - Options for getting the value.
81
+ * @param {string} options.key - The key of the field.
82
+ * @param {string} options.property - The property to retrieve.
83
+ * @param {string[]} options.path - The path to the property if it's nested.
84
+ * @returns {unknown | undefined} The value of the property, or undefined if the field doesn't exist.
85
+ */
86
+ getValue({ key, property, path, }: {
87
+ key: string;
88
+ property: string;
89
+ path: string[];
90
+ }): unknown | undefined;
91
+ /**
92
+ * Sets the value of a property in a field.
93
+ *
94
+ * @param {object} options - Options for setting the value.
95
+ * @param {string} options.key - The key of the field.
96
+ * @param {string} options.property - The property to set.
97
+ * @param {string[]} options.path - The path to the property if it's nested.
98
+ * @param {unknown} options.originKey - field that called templating
99
+ * @param {unknown} options.value - The value to set.
100
+ * @param {TMutationEvents} options.event - Internal Event for template Handling.
101
+ */
102
+ setValue({ key, property, path, originKey, value, }: {
103
+ key: string;
104
+ property: string;
105
+ path: string[];
106
+ originKey: string;
107
+ value: unknown;
108
+ event: TMutationEvents;
109
+ }): void;
110
+ /**
111
+ * Extracts parameters from an expression.
112
+ *
113
+ * @param {string} expression - The expression containing parameters.
114
+ * @returns {string[]} An array of extracted parameters.
115
+ */
116
+ extractParams(expression: string): string[];
117
+ /**
118
+ * Replaces expressions marked by ${...} in the expression string with the provided values.
119
+ *
120
+ * @param {string} expression - The expression string containing the marked expressions.
121
+ * @param {string[]} values - The values to be inserted into the marked expressions.
122
+ * @returns {string} The expression string with the replacements made.
123
+ */
124
+ replaceExpression(expression: string, values: string[]): string;
125
+ /**
126
+ * Checks if an expression string contains string concatenation within a marked expression.
127
+ *
128
+ * @param {string} expression - The expression string to be checked.
129
+ * @returns {boolean} True if the expression contains string concatenation, otherwise false.
130
+ */
131
+ hasStringConcatenation(expression: string): boolean;
132
+ /**
133
+ * Refreshes templates with updated values.
134
+ *
135
+ * @param {object} options - Options for refreshing templates.
136
+ * @param {string} options.key - The key of the field triggering the update.
137
+ * @param {TMutationEvents} options.event - Internal event descriptor to handle templating.
138
+ */
139
+ refreshTemplates({ key, event }: {
140
+ key: string;
141
+ event: TMutationEvents;
142
+ }): void;
143
+ /**
144
+ * Refreshes api observed fields.
145
+ *
146
+ * @param {object} options - Options for refreshing api.
147
+ * @param {string} options.key - The key of the field triggering the update.
148
+ */
149
+ refreshApi({ key }: {
150
+ key: string;
151
+ }): string;
152
+ /**
153
+ * Validates and collects the names of form fields in the provided schema structure.
154
+ *
155
+ * @param {IComponentSchema[]} [struct] - The schema structure of the form components.
156
+ * @param {string[]} [indexes=[]] - An array to collect the names of the form fields.
157
+ * @returns {string[]} - An array of form field names.
158
+ * @throws {Error} - Throws an error if a field name matches the reserved name defined by `IVARPROPNAME`.
159
+ * @private
160
+ */
161
+ private static checkIndexes;
162
+ /**
163
+ * Validates visibility conditions for a given event and updates field visibility accordingly.
164
+ *
165
+ * @param {object} options - Options for validating visibility.
166
+ * @param {TEvents} options.event - The event triggering visibility validation.
167
+ * @param {string} options.key - The key of the field.
168
+ */
169
+ validateVisibility({ event, key }: {
170
+ event: TEvents;
171
+ key: string;
172
+ }): void;
173
+ /**
174
+ * Resets field values based on reset conditions defined in the schema.
175
+ *
176
+ * @param {object} options - Options for resetting field values.
177
+ * @param {TEvents} options.event - The event triggering the reset.
178
+ * @param {string} options.key - The key of the field.
179
+ */
180
+ resetValue({ event, key }: {
181
+ event: TEvents;
182
+ key: string;
183
+ }): void;
184
+ /**
185
+ * Serializes the schema structure to create form fields.
186
+ *
187
+ * @param {IComponentSchema[]} [struct] - The schema structure to serialize.
188
+ * @param {string} [path] - The path of the parent component.
189
+ */
190
+ serializeStructure(struct?: IComponentSchema[], path?: string): void;
191
+ /**
192
+ * Refreshes form fields based on changes in the schema structure.
193
+ *
194
+ * @param {IComponentSchema[]} struct - The updated schema structure.
195
+ */
196
+ refreshFields(struct: IComponentSchema[]): void;
197
+ /**
198
+ * Gets a form field by its key.
199
+ *
200
+ * @param {object} options - Options for getting the form field.
201
+ * @param {string} options.key - The key of the form field.
202
+ * @returns {IFormField | undefined} The form field, or undefined if not found.
203
+ */
204
+ getField({ key }: {
205
+ key: string;
206
+ }): IFormField | undefined;
207
+ /**
208
+ * Prints the current values of all form fields.
209
+ */
210
+ printValues(): void;
211
+ /**
212
+ * Gets the current values of all form fields.
213
+ *
214
+ * @returns {TFormValues} The current form values.
215
+ */
216
+ getFormValues(): TFormValues;
217
+ /**
218
+ * Submits the form by triggering form field events and invoking the onSubmit callback.
219
+ */
220
+ submit(): void;
221
+ destroy(): void;
222
+ }
223
+ type TFormCore = FormCore;
224
+ export { TFormCore, FormCore };
@@ -0,0 +1,64 @@
1
+ import { TFormValues } from '../types/form';
2
+ import { TFormCore } from './form';
3
+ /**
4
+ * Represents a group that manages multiple forms.
5
+ */
6
+ declare class FormGroup {
7
+ forms: Map<string, TFormCore>;
8
+ /**
9
+ * Creates an instance of FormGroup.
10
+ */
11
+ constructor();
12
+ /**
13
+ * Adds a form instance to the form group.
14
+ *
15
+ * @param {object} options - Options for adding a form.
16
+ * @param {string} options.key - The key associated with the form instance.
17
+ * @param {TFormCore} options.formInstance - The instance of the form to add.
18
+ */
19
+ addForm({ key, formInstance }: {
20
+ key: string;
21
+ formInstance: TFormCore;
22
+ }): void;
23
+ /**
24
+ * Retrieves a form instance from the form group.
25
+ *
26
+ * @param {object} options - Options for retrieving a form.
27
+ * @param {string} options.key - The key associated with the form instance.
28
+ * @returns {TFormCore | undefined} The instance of the form, if found; otherwise, undefined.
29
+ */
30
+ getForm({ key }: {
31
+ key: string;
32
+ }): import("./form").FormCore | undefined;
33
+ /**
34
+ * Removes a form instance from the form group.
35
+ *
36
+ * @param {object} options - Options for removing a form.
37
+ * @param {string} options.key - The key associated with the form instance to remove.
38
+ */
39
+ removeForm({ key }: {
40
+ key: string;
41
+ }): void;
42
+ /**
43
+ * Checks if the specified key already exists in the form group.
44
+ *
45
+ * @param {object} options - Options for checking the key.
46
+ * @param {string} options.key - The key to check.
47
+ * @throws {Error} Throws an error if the key already exists in the form group.
48
+ */
49
+ checkIndexes({ key }: {
50
+ key: string;
51
+ }): void;
52
+ /**
53
+ * Prints the form group instance to the console.
54
+ */
55
+ printFormGroupInstance(): void;
56
+ /**
57
+ * Prototype submit function to multiple forms
58
+ * @param {string[]} indexes form indexes to be submitted
59
+ * @returns
60
+ */
61
+ submitMultipleFormsByIndex(indexes: string[]): TFormValues;
62
+ }
63
+ type TFormGroup = FormGroup;
64
+ export { TFormGroup, 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,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) => string;
39
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { TMasks } from '../types/schema';
2
+ export declare const masks: Record<keyof TMasks, (value: unknown, masks?: TMasks) => unknown>;