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

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 +2314 -0
  2. package/index.esm.js +131 -81
  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,88 +0,0 @@
1
- import { TFormatters } from '../types/schema';
2
- /**
3
- * Capitalizes the first letter of a string.
4
- *
5
- * @param value - The value to be capitalized.
6
- * @returns The value with the first letter capitalized.
7
- *
8
- * @example
9
- * ```typescript
10
- * import { capitalize } from './path/to/formatterFunctions';
11
- *
12
- * const capitalizedValue = capitalize('hello world');
13
- * console.log(capitalizedValue); // Output: 'Hello world'
14
- * ```
15
- */
16
- export declare const capitalize: (value: unknown) => string;
17
- /**
18
- * Converts a string to uppercase.
19
- *
20
- * @param value - The value to be converted.
21
- * @returns The value in uppercase.
22
- *
23
- * @example
24
- * ```typescript
25
- * import { uppercase } from './path/to/formatterFunctions';
26
- *
27
- * const uppercasedValue = uppercase('hello world');
28
- * console.log(uppercasedValue); // Output: 'HELLO WORLD'
29
- * ```
30
- */
31
- export declare const uppercase: (value: unknown) => string;
32
- /**
33
- * Formats a string as a float number with a specific precision and decimal separator.
34
- *
35
- * @param value - The value to be formatted.
36
- * @param formatters - An object containing formatting options.
37
- * @returns The formatted float number.
38
- *
39
- * @example
40
- * ```typescript
41
- * import { onlyFloatNumber } from './path/to/formatterFunctions';
42
- *
43
- * const formattedNumber = onlyFloatNumber('1234567.89', { onlyFloatNumber: { precision: 2, decimal: '.' } });
44
- * console.log(formattedNumber); // Output: '1234567.89'
45
- * ```
46
- */
47
- export declare const onlyFloatNumber: (value: unknown, formatters: TFormatters) => unknown;
48
- /**
49
- * Trims whitespace from the beginning and end of a string.
50
- *
51
- * @param value - The value to be trimmed.
52
- * @param formatters - An object containing formatting options.
53
- * @returns The trimmed value.
54
- *
55
- * @example
56
- * ```typescript
57
- * import { trim } from './path/to/formatterFunctions';
58
- *
59
- * const trimmedValue = trim(' hello world ');
60
- * console.log(trimmedValue); // Output: 'hello world'
61
- * ```
62
- */
63
- export declare const trim: (value: unknown, formatters: TFormatters) => unknown;
64
- /**
65
- * Truncates the input value to a specified maximum length if necessary.
66
- *
67
- * @param {string | number} value - The input value to be formatted.
68
- * @param {TFormatters} formatters - An object containing formatting options.
69
- * @param {number} formatters.maxLength - The maximum allowed length for the input value.
70
- * @returns {string | number} - The formatted value truncated to the maximum length, if applicable.
71
- *
72
- * @example
73
- * ```typescript
74
- * const result = maxLength('Hello, World!', { maxLength: 5 });
75
- * console.log(result); // "Hello"
76
- * ```
77
- * @example
78
- * ```typescript
79
- * const result = maxLength(123456789, { maxLength: 4 });
80
- * console.log(result); // "1234"
81
- * ```
82
- * @example
83
- * ```typescript
84
- * const result = maxLength('Short', { maxLength: 10 });
85
- * console.log(result); // "Short" (no truncation since input is shorter than maxLength)
86
- * ```
87
- */
88
- export declare const maxLength: (value: string | number, formatters: TFormatters) => string | number;
@@ -1,11 +0,0 @@
1
- import { Subject } from 'rxjs';
2
- /**
3
- * Custom RXJS Subject to gracefully handle errors on unsubscribed Subjects
4
- * that were unmounted due to adapter external handling such as visibility
5
- */
6
- declare class SafeSubject<T> extends Subject<T> {
7
- private isMounted;
8
- constructor(isMounted: () => boolean);
9
- next(value: T): void;
10
- }
11
- export { SafeSubject };
@@ -1,95 +0,0 @@
1
- /**
2
- * Represents the properties of a credit card type.
3
- */
4
- export interface ICreditCardType {
5
- /**
6
- * A human-readable name for the credit card type.
7
- * For example, "Visa", "Mastercard", "American Express", etc.
8
- */
9
- niceType: string;
10
- /**
11
- * A unique identifier for the credit card type.
12
- * Typically, follows industry standards such as "visa", "mastercard", "amex", etc.
13
- */
14
- type: string;
15
- /**
16
- * An array of patterns (regular expressions) that match valid card numbers for this type.
17
- * Each pattern corresponds to a specific length of card number.
18
- */
19
- patterns: number[] | [number[]];
20
- /**
21
- * An array representing the positions in the card number where spaces (gaps) should be added
22
- * to format the number nicely. These positions are counted from the beginning of the number.
23
- */
24
- gaps: number[];
25
- /**
26
- * An array of possible lengths for valid card numbers of this type.
27
- * Typically, this array contains only one element, but some card types may have multiple lengths.
28
- */
29
- lengths: number[];
30
- /**
31
- * Information about the card's security code (CVV/CVC/CID).
32
- */
33
- code: {
34
- /**
35
- * The size (length) of the security code for this card type.
36
- */
37
- size: number;
38
- /**
39
- * A descriptive name for the security code, such as "CVV" or "CVC".
40
- */
41
- name: string;
42
- };
43
- /**
44
- * An optional value representing the match strength of the card type detection.
45
- * Higher values indicate stronger matches, while lower values indicate weaker matches.
46
- * This property is typically provided by the credit card type detection library.
47
- */
48
- matchStrength?: number;
49
- }
50
- /**
51
- * Represents the return type of the `getTypeCard` function.
52
- */
53
- export type TGetTypeCard = [ICreditCardType, string];
54
- /**
55
- * Retrieves the type of the credit card and the raw value without spaces.
56
- *
57
- * @param value - The credit card number as a string.
58
- * @param availableOptions - An optional array of credit card types to consider.
59
- * @returns An array containing the detected credit card type and the raw value without spaces.
60
- *
61
- * @example
62
- * ```typescript
63
- * import { getTypeCard } from './path/to/helperFunctions';
64
- *
65
- * const [creditCardType, rawValue] = getTypeCard('4111 1111 1111 1111');
66
- * console.log(creditCardType); // Output: { niceType: 'Visa', type: 'visa', ... }
67
- * console.log(rawValue); // Output: '4111111111111111'
68
- * ```
69
- */
70
- export declare const getTypeCard: (value: string, availableOptions?: string[]) => TGetTypeCard;
71
- /**
72
- * Formats a credit card number according to its type's gaps and lengths.
73
- *
74
- * @param value - The credit card number as a string.
75
- * @param type - The type of the credit card.
76
- * @returns The formatted credit card number.
77
- */
78
- export declare const formatValue: (value: string, type: ICreditCardType) => string;
79
- /**
80
- * Formats a date string by adding a prefix and/or trimming the string based on its length.
81
- *
82
- * @param value - The date string to be formatted.
83
- * @param end - The ending index to slice the string to.
84
- * @param prefix - The prefix to add between date components.
85
- * @returns The formatted date string.
86
- *
87
- * @example
88
- * ```typescript
89
- * import { formatDateCard } from './path/to/helperFunctions';
90
- *
91
- * const formattedDate = formatDateCard('1223', 4, '/');
92
- * console.log(formattedDate); // Output: '12/23'
93
- * ```
94
- */
95
- export declare const formatDateCard: (value: string, end?: number, prefix?: string) => string;
@@ -1,67 +0,0 @@
1
- /// <reference types="node" />
2
- import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
3
- import { TApiResponsePayload } from '../types/schema';
4
- import { TSubscribedTemplates } from '../types/template';
5
- import { OutgoingHttpHeaders } from 'http2';
6
- /**
7
- * Makes an HTTP request using XMLHttpRequest.
8
- *
9
- * @param {string} method - The HTTP method (GET, POST, PUT, DELETE, etc.).
10
- * @param {string} url - The URL to which the request is sent.
11
- * @param {OutgoingHttpHeaders} [headers] - Optional request headers.
12
- * @param {Record<string,unknown>} [body] - Optional object body.
13
- * @returns {Promise<string>} A promise that resolves with the response text if the request is successful, otherwise rejects with an error message.
14
- *
15
- * @example
16
- * ```typescript
17
- * const response = await makeRequest('GET', 'https://api.example.com/data');
18
- * ```
19
- */
20
- declare function makeRequest(method: string, url: string, headers?: OutgoingHttpHeaders, body?: Record<string, unknown>, queryParams?: Record<string, string>): Promise<TApiResponsePayload>;
21
- /**
22
- * Extracts keys enclosed in `${}` from a given expression.
23
- *
24
- * @param {string} expression - The expression to extract keys from.
25
- * @returns {
26
- * originFieldKeys: string[];
27
- * originPropertyKeys: string[];
28
- * } An object containing the field names and properties from the template expression.
29
- *
30
- * @example
31
- * ```typescript
32
- * const keys = extractFieldKeys('Hello ${name.value}, your age is ${age.props.label}.');
33
- * // keys will be {originFieldKeys:['name', 'age'],originPropertyKeys:[value,props]}
34
- * ```
35
- */
36
- declare function extractFieldKeys(expression: string): {
37
- originScopeKeys: (typeof TEMPLATE_AVALIABLE_SCOPES)[number][];
38
- originFieldKeys: string[];
39
- originPropertyKeys: string[];
40
- };
41
- /**
42
- * Traverses an object and extracts expressions containing keys.
43
- *
44
- * @param {any} obj - The object to traverse.
45
- * @param {string} [path] - Optional path within the object (used internally during recursion).
46
- * @returns {TSubscribedTemplates[]} An array of extracted expressions along with their keys and paths.
47
- *
48
- * @example
49
- * ```typescript
50
- * const data = {
51
- * user: {
52
- * name: 'John',
53
- * age: 30,
54
- * address: {
55
- * street: '123 Main St',
56
- * city: 'Example City'
57
- * }
58
- * },
59
- * message: 'Hello ${user.name}, your age is ${user.age}.'
60
- * };
61
- *
62
- * const expressions = traverseObject(data);
63
- * // expressions will contain an array of objects with origin expressions, field keys, and destination paths.
64
- * ```
65
- */
66
- declare function traverseObject(element: any, path?: string): TSubscribedTemplates[];
67
- export { makeRequest, traverseObject, extractFieldKeys };
@@ -1,27 +0,0 @@
1
- import { TSchemaValidation, TValidationMethods } from '../types/schema';
2
- import { TValidationHandler } from '../types/utility';
3
- /**
4
- * @internal
5
- * Handles the validation of a given value based on specified validation methods and rules.
6
- *
7
- * @param {string | number | boolean | unknown} value - The value to be validated.
8
- * @param {TSchemaValidation} validations - The schema validations to be applied.
9
- * @param {TValidationHandler} methods - The validation handler methods.
10
- * @param {keyof TValidationMethods} key - The specific key of the validation method to be used.
11
- * @returns {boolean} - Returns true if the value passes the validation, otherwise false.
12
- *
13
- * @example
14
- * const value = 'example@example.com';
15
- * const validations = {
16
- * required: true,
17
- * customName: { email: true }
18
- * };
19
- * const methods = {
20
- * email: (value) => /\S+@\S+\.\S+/.test(value)
21
- * };
22
- * const key = 'required';
23
- *
24
- * const isValid = handleValidation(value, validations, methods, key);
25
- * console.log(isValid); // Output: true
26
- */
27
- export default function handleValidation(value: string | number | boolean | unknown, validations: TSchemaValidation, methods: TValidationHandler, key: keyof TValidationMethods): boolean;
package/src/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export * from './types/event';
2
- export * from './types/form';
3
- export * from './types/schema';
4
- export * from './types/template';
5
- export * from './types/mapper';
6
- export * from './interfaces/schema';
7
- export * from './interfaces/state';
8
- export * from './managers/form';
9
- export * from './managers/formGroup';
10
- export * from './managers/field';
@@ -1,112 +0,0 @@
1
- import { TMapper } from '../types/mapper';
2
- import { TApiEvent, TFormatters, TMasks, TProps, TResetPathMethods, TResetValueMethods, TSchemaFormConfig, TValidations, TVisibility } from '../types/schema';
3
- /**
4
- * @interface IComponentSchema
5
- * Represents the schema for a component within a form.
6
- *
7
- * @property {string} component - The type of component (e.g., 'input', 'button').
8
- * @property {TProps} props - The properties of the component.
9
- * @property {string} name - The name of the component.
10
- * @property {string} nameToSubmit - The name of the field when submit values (optional).
11
- * @property {TValidations} [validations] - The validation methods for the component.
12
- * @property {TVisibility[]} [visibilityConditions] - The visibility conditions for the component.
13
- * @property {TResetValueMethods[]} [resetValues] - The reset value methods for the component.
14
- * @property {TApiEvent} [api] - The API configuration for the component.
15
- * @property {TFormatters} [formatters] - The formatters for the component.
16
- * @property {TMasks} [masks] - The masks for the component.
17
- * @property {IComponentSchema[]} [children] - The child components.
18
- * @property {boolean} visibility - visibility status the component will mount (to avoid SSR blinking)
19
- * @property {boolean} persistValue - check this if you want the last visible value to be restored after a visiblity schema rule applied
20
- *
21
- * @example
22
- * ```typescript
23
- * const schema: IComponentSchema = {
24
- * component: 'input',
25
- * props: { type: 'text', placeholder: 'Enter your name' },
26
- * name: 'name',
27
- * nameToSubmit: 'applicant.firstName',
28
- * validations: {
29
- * methods: {
30
- * required: true,
31
- * regex: '^([0-9]+)*$',
32
- * max: 5,
33
- * },
34
- * eventMessages: {
35
- * ON_FIELD_MOUNT: ['required'],
36
- * ON_FIELD_CHANGE: ['regex', 'required'],
37
- * ON_FIELD_BLUR: ['max', 'required'],
38
- * },
39
- * messages: {
40
- * default: 'This field is required',
41
- * regex: 'Only numbers are available.',
42
- * max: 'Max of 5',
43
- * },
44
- * },
45
- * visibilityConditions: [{ conditions: { field: 'age', value: 18 } }],
46
- * resetValues: [{ field: 'age', resetTo: '' }],
47
- * api: { defaultConfig: { config: { method: 'POST', url: 'https://api.example.com/submit' }, events: [{ eventName: 'ON_FORM_SUBMIT' }] } },
48
- * formatters: { capitalize: true },
49
- * masks: { currency: { align: 'left', decimal: '.', precision: 2, prefix: '$', thousands: ',' } },
50
- * children: [],
51
- * visibility: true,
52
- * persistValue: true,
53
- * };
54
- * ```
55
- */
56
- interface IComponentSchema {
57
- component: string;
58
- props?: TProps;
59
- name: string;
60
- nameToSubmit?: string;
61
- validations?: TValidations;
62
- api?: TApiEvent;
63
- visibilityConditions?: TVisibility[];
64
- resetValues?: TResetValueMethods[];
65
- resetPropertyValues?: TResetPathMethods[];
66
- formatters?: TFormatters;
67
- masks?: TMasks;
68
- children?: IComponentSchema[];
69
- visibility?: boolean;
70
- persistValue?: boolean;
71
- }
72
- interface IComponentSchemaAsFormField<T> extends IComponentSchema {
73
- mapper?: TMapper<T>;
74
- order?: number;
75
- children?: IComponentSchemaAsFormField<T>[];
76
- }
77
- /**
78
- * @interface IFormSchema
79
- * Represents the schema for a form.
80
- *
81
- * @property {string} index - The unique index or identifier for the form.
82
- * @property {string} [action] - The URL to which the form data will be submitted.
83
- * @property {string} [method] - The HTTP method used to submit the form (e.g., 'POST', 'GET').
84
- * @property {Record<string, unknown>} [initialValues] - The initial values for the form fields.
85
- * @property {Record<string, unknown>} [iVars] - Dynamic key value pairs that change from any external source
86
- * @property {IComponentSchema[]} [components] - The list of components included in the form.
87
- *
88
- * @example
89
- * ```typescript
90
- * const formSchema: IFormSchema = {
91
- * index: 'userForm',
92
- * action: 'https://api.example.com/submit',
93
- * method: 'POST',
94
- * initialValues: { name: '', email: '' },
95
- * iVars: iVarsState,
96
- * components: [
97
- * { component: 'input', name: 'name', props: { placeholder: 'Enter your name' } },
98
- * { component: 'input', name: 'email', props: { placeholder: 'Enter your email' } }
99
- * ]
100
- * };
101
- * ```
102
- */
103
- interface IFormSchema {
104
- index: string;
105
- action?: string;
106
- method?: string;
107
- config?: TSchemaFormConfig;
108
- initialValues?: Record<string, unknown>;
109
- iVars?: Record<string, unknown>;
110
- components?: IComponentSchema[];
111
- }
112
- export { IFormSchema, IComponentSchema, IComponentSchemaAsFormField };
@@ -1,22 +0,0 @@
1
- /**
2
- * @interface IState
3
- * Represents the state of a form component.
4
- *
5
- * @property {string[]} errors - The list of error messages.
6
- * @property {boolean} visibility - The visibility state of the component.
7
- * @property {Record<string, unknown>} props - The properties of the component.
8
- *
9
- * @example
10
- * ```typescript
11
- * const state: IState = {
12
- * visibility: true,
13
- * props: { type: 'text', value: 'John' }
14
- * };
15
- * ```
16
- */
17
- interface IState {
18
- visibility: boolean;
19
- props: Record<string, unknown>;
20
- errors: Record<string, unknown>;
21
- }
22
- export { IState };