@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.
- package/CHANGELOG.md +16 -0
- package/credit-card.d.ts +743 -0
- package/credit-card.esm.js +1 -0
- package/currency.d.ts +131 -0
- package/currency.esm.js +1 -0
- package/date.d.ts +582 -0
- package/date.esm.js +1 -0
- package/document.d.ts +527 -0
- package/document.esm.js +1 -0
- package/index.d.ts +52 -5
- package/index.esm.js +1 -4570
- package/lite.d.ts +2393 -0
- package/lite.esm.js +1 -0
- package/package.json +34 -2
- package/src/constants/constants.d.ts +11 -0
- package/src/formatters/creditCard.d.ts +23 -0
- package/src/formatters/custom.d.ts +29 -0
- package/src/formatters/handler.d.ts +2 -0
- package/src/formatters/regex.d.ts +47 -0
- package/src/formatters/splitter.d.ts +17 -0
- package/src/formatters/string.d.ts +88 -0
- package/src/helpers/SafeSubject.d.ts +21 -0
- package/src/helpers/creditCard.d.ts +95 -0
- package/src/helpers/helpers.d.ts +66 -0
- package/src/helpers/lodash-replacements.d.ts +41 -0
- package/src/helpers/validation.d.ts +28 -0
- package/src/index.d.ts +15 -0
- package/src/interfaces/schema.d.ts +161 -0
- package/src/interfaces/state.d.ts +22 -0
- package/src/lite.d.ts +30 -0
- package/src/managers/field.d.ts +339 -0
- package/src/managers/form.d.ts +357 -0
- package/src/managers/formGroup.d.ts +110 -0
- package/src/managers/index.d.ts +3 -0
- package/src/masks/creditCard.d.ts +60 -0
- package/src/masks/currency.d.ts +29 -0
- package/src/masks/generic.d.ts +39 -0
- package/src/masks/handler.d.ts +2 -0
- package/src/masks/string.d.ts +37 -0
- package/src/plugins/credit-card.d.ts +4 -0
- package/src/plugins/currency.d.ts +2 -0
- package/src/plugins/date.d.ts +2 -0
- package/src/plugins/document.d.ts +2 -0
- package/src/registry.d.ts +20 -0
- package/src/types/event.d.ts +175 -0
- package/src/types/form.d.ts +55 -0
- package/src/types/mapper.d.ts +87 -0
- package/src/types/schema.d.ts +1001 -0
- package/src/types/template.d.ts +65 -0
- package/src/types/utility.d.ts +12 -0
- package/src/validations/creditCard.d.ts +52 -0
- package/src/validations/custom.d.ts +27 -0
- package/src/validations/date.d.ts +79 -0
- package/src/validations/document.d.ts +25 -0
- package/src/validations/handler.d.ts +2 -0
- package/src/validations/length.d.ts +39 -0
- package/src/validations/list.d.ts +32 -0
- package/src/validations/logical.d.ts +75 -0
- package/src/validations/multiple.d.ts +31 -0
- package/src/validations/namedRule.d.ts +22 -0
- package/src/validations/number.d.ts +145 -0
- package/src/validations/object.d.ts +44 -0
- package/src/validations/regex.d.ts +217 -0
- package/src/validations/string.d.ts +53 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { TMutationEvents } from './event';
|
|
2
|
+
import { TEMPLATE_AVALIABLE_SCOPES } from '../constants/constants';
|
|
3
|
+
type TTemplateAvaliableScopes = (typeof TEMPLATE_AVALIABLE_SCOPES)[number];
|
|
4
|
+
/**
|
|
5
|
+
* @type TTemplateAvaliableScopesEnum
|
|
6
|
+
* Represents the different types of events that can occur on form fields.
|
|
7
|
+
* @property {never} fields - scope related to field content ex: '${fields.fieldName.value}'
|
|
8
|
+
* @property {never} iVars - scope related to iVars content ex: '${iVars.test}'
|
|
9
|
+
* @property {never} form - scope related to form content ex: '${form.valid}'
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const scope: TTemplateAvaliableScopesEnum = 'fields';
|
|
14
|
+
* ```
|
|
15
|
+
* @interface
|
|
16
|
+
*/
|
|
17
|
+
type TTemplateAvaliableScopesEnum = Record<TTemplateAvaliableScopes, never>;
|
|
18
|
+
/**
|
|
19
|
+
* @type TSubscribedTemplates
|
|
20
|
+
* Represents the subscribed templates for dynamic updates.
|
|
21
|
+
*
|
|
22
|
+
* @property {string} originExpression - The expression to evaluate.
|
|
23
|
+
* @property {TTemplateAvaliableScopes[]} originScopeKeys - Origin scope of the updated template value
|
|
24
|
+
* @property {string[]} originPropertyKeys - The properties of the origin fields.
|
|
25
|
+
* @property {string[]} originFieldKeys - The keys of the origin fields.
|
|
26
|
+
* @property {string} destinationKey - The key of the destination field.
|
|
27
|
+
* @property {string} destinationProperty - The property of the destination field.
|
|
28
|
+
* @property {string[]} destinationPath - The path to the destination property.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const subscribedTemplates: TSubscribedTemplates = {
|
|
33
|
+
* originExpression: 'originField1 + originField2',
|
|
34
|
+
* originScopeKeys: ['field','field'],
|
|
35
|
+
* originPropertyKeys: ['value', 'props'],
|
|
36
|
+
* originFieldKeys: ['originField1', 'originField2'],
|
|
37
|
+
* destinationKey: 'resultField',
|
|
38
|
+
* destinationProperty: 'value',
|
|
39
|
+
* destinationPath: ['path', 'to', 'resultField']
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type TSubscribedTemplates = {
|
|
44
|
+
originExpression: string;
|
|
45
|
+
originScopeKeys: TTemplateAvaliableScopes[];
|
|
46
|
+
originPropertyKeys: string[];
|
|
47
|
+
originFieldKeys: string[];
|
|
48
|
+
destinationKey: string;
|
|
49
|
+
destinationProperty: string;
|
|
50
|
+
destinationPath: string[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @type TTemplateEvent
|
|
54
|
+
* Represents the event occuring on templates that changes property values.
|
|
55
|
+
*
|
|
56
|
+
* @property {TTemplateAvaliableScopes} scope - template scope triggering the event.
|
|
57
|
+
* @property {string} key - field triggering the template refresh
|
|
58
|
+
* @property {TMutationEvents} event - template event triggering the template refresh.
|
|
59
|
+
*/
|
|
60
|
+
type TTemplateEvent = {
|
|
61
|
+
scope: TTemplateAvaliableScopes;
|
|
62
|
+
key?: string;
|
|
63
|
+
event: TMutationEvents;
|
|
64
|
+
};
|
|
65
|
+
export { TSubscribedTemplates, TTemplateEvent, TTemplateAvaliableScopes, TTemplateAvaliableScopesEnum };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TFormValues } from './form';
|
|
2
|
+
import { TValidationMethods } from './schema';
|
|
3
|
+
export type AllowOnly<T, K extends keyof T> = Pick<T, K> & {
|
|
4
|
+
[P in keyof Omit<T, K>]?: never;
|
|
5
|
+
};
|
|
6
|
+
export type OneOf<T, K = keyof T> = K extends keyof T ? AllowOnly<T, K> : never;
|
|
7
|
+
export type TValidationPayload = [
|
|
8
|
+
unknown,
|
|
9
|
+
TValidationMethods,
|
|
10
|
+
TFormValues<unknown>?
|
|
11
|
+
];
|
|
12
|
+
export type TValidationHandler = Record<string, (...args: TValidationPayload) => boolean>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Validates if a given value is a valid credit card number based on predefined validation methods.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be validated as a credit card number.
|
|
6
|
+
* @param validations - An object containing validation methods.
|
|
7
|
+
* @returns `true` if the value is either falsy or does not match a valid credit card type, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { isCreditCard } from './path/to/validationFunctions';
|
|
12
|
+
* import { validationMethods } from './path/to/validationConfig';
|
|
13
|
+
*
|
|
14
|
+
* const isValid = isCreditCard('4111111111111111', validationMethods);
|
|
15
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const isCreditCard: (value: unknown, validations: TValidationMethods) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Validates if a given security code matches the expected length for a specified credit card type.
|
|
21
|
+
*
|
|
22
|
+
* @param value - The security code to be validated.
|
|
23
|
+
* @param validations - An object containing validation methods, specifically with `isCreditCodeMatch` details.
|
|
24
|
+
* @returns `true` if the value is either falsy or if the validation methods are not provided. Otherwise, it checks if the security code length matches the expected length for the card type.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { isCreditCodeMatch } from './path/to/validationFunctions';
|
|
29
|
+
* import { validationMethods } from './path/to/validationConfig';
|
|
30
|
+
*
|
|
31
|
+
* const isValid = isCreditCodeMatch('123', validationMethods);
|
|
32
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const isCreditCodeMatch: (value: string, validations: TValidationMethods) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Validates if a given value is a valid credit card number and checks if its length matches the expected lengths for the card type.
|
|
38
|
+
*
|
|
39
|
+
* @param value - The credit card number to be validated.
|
|
40
|
+
* @param validations - An object containing validation methods, specifically with `isCreditCardAndLength` details.
|
|
41
|
+
* @returns `true` if the value is either falsy or if the card number does not match any valid lengths for the card type, otherwise `false`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { isCreditCardAndLength } from './path/to/validationFunctions';
|
|
46
|
+
* import { validationMethods } from './path/to/validationConfig';
|
|
47
|
+
*
|
|
48
|
+
* const isValid = isCreditCardAndLength('4111111111111111', validationMethods);
|
|
49
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const isCreditCardAndLength: (value: string, validations: TValidationMethods) => boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TFormValues } from '../types/form';
|
|
2
|
+
import { TValidationMethods } from '../types/schema';
|
|
3
|
+
/**
|
|
4
|
+
* Executes a custom callback validation function if provided.
|
|
5
|
+
*
|
|
6
|
+
* @param value - The value to be validated.
|
|
7
|
+
* @param validations - An object containing validation methods, including a custom callback function.
|
|
8
|
+
* @param formValues - An object containing the form state, NOTE: validations might be dirty here
|
|
9
|
+
* @returns `true` if the custom callback validation function returns `true`, otherwise `false`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { callback } from './path/to/validationFunctions';
|
|
14
|
+
*
|
|
15
|
+
* const validations = {
|
|
16
|
+
* callback: (value) => typeof value === 'string' && value.length > 5
|
|
17
|
+
* };
|
|
18
|
+
*
|
|
19
|
+
* // Or from a JSON config
|
|
20
|
+
* const schema = {
|
|
21
|
+
* validations: {
|
|
22
|
+
* callback: (value) => typeof value === 'string' && value.length > 5
|
|
23
|
+
* }
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const callback: (value: unknown, validations: TValidationMethods, { values, metadata }?: TFormValues<unknown>) => boolean;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* @function betweenDates
|
|
4
|
+
* Validates if a date value falls between two specified dates.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} value - The date value to be validated in string format.
|
|
7
|
+
* @param {TValidationMethods} validations - The validation methods object containing the betweenDates validation rules.
|
|
8
|
+
* @returns {boolean} - Returns `true` if the date value fails the betweenDates validation, otherwise `false`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const validations = {
|
|
13
|
+
* betweenDates: [
|
|
14
|
+
* { origin: { value: '2023-01-01', format: 'yyyy-MM-dd' }, operator: '>=' },
|
|
15
|
+
* { origin: { value: '2023-12-31', format: 'yyyy-MM-dd' }, operator: '<=' }
|
|
16
|
+
* ]
|
|
17
|
+
* };
|
|
18
|
+
*
|
|
19
|
+
* const result1 = betweenDates('2023-06-01', validations);
|
|
20
|
+
* console.log(result1); // false (date is within the range)
|
|
21
|
+
*
|
|
22
|
+
* const result2 = betweenDates('2024-01-01', validations);
|
|
23
|
+
* console.log(result2); // true (date is outside the range)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const betweenDates: (value: string, validations: TValidationMethods) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @function date
|
|
29
|
+
* Validates a date value based on various date conditions and intervals.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} value - The date value to be validated in string format.
|
|
32
|
+
* @param {TValidationMethods} validations - The validation methods object containing the date validation rules.
|
|
33
|
+
* @returns {boolean} - Returns `true` if the date validation fails, otherwise `false`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const validations = {
|
|
38
|
+
* date: {
|
|
39
|
+
* origin: {
|
|
40
|
+
* value: '2023-01-01',
|
|
41
|
+
* format: 'YYYY-MM-DD'
|
|
42
|
+
* },
|
|
43
|
+
* target: {
|
|
44
|
+
* value: '2023-12-31',
|
|
45
|
+
* format: 'YYYY-MM-DD'
|
|
46
|
+
* },
|
|
47
|
+
* operator: '<=',
|
|
48
|
+
* onlyValidDate: true
|
|
49
|
+
* }
|
|
50
|
+
* };
|
|
51
|
+
*
|
|
52
|
+
* const result1 = date('2023-06-01', validations);
|
|
53
|
+
* console.log(result1); // false (date is within the range)
|
|
54
|
+
*
|
|
55
|
+
* const result2 = date('2024-01-01', validations);
|
|
56
|
+
* console.log(result2); // true (date is outside the range)
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const date: (value: string | null, validations: TValidationMethods) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* @function validDate
|
|
62
|
+
* Validates that a date string is a valid date according to the given format.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} value - The date value to be validated in string format.
|
|
65
|
+
* @param {TValidationMethods} validations - The validation methods object containing the validDate rule.
|
|
66
|
+
* @returns {boolean} - Returns `true` if the date is not valid, otherwise `false`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const validations = { validDate: 'MM-dd-yyyy' };
|
|
71
|
+
*
|
|
72
|
+
* const result1 = validDate('12-31-2023', validations);
|
|
73
|
+
* console.log(result1); // false (date is valid)
|
|
74
|
+
*
|
|
75
|
+
* const result2 = validDate('02-30-2023', validations);
|
|
76
|
+
* console.log(result2); // true (date is invalid)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare const validDate: (value: string, validations: TValidationMethods) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* General validation function for various document types based on the provided validation methods.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The document value to validate.
|
|
6
|
+
* @param validations - An object containing validation methods.
|
|
7
|
+
* @returns `true` if the document is valid, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import validateDocument from './path/to/validationFunctions';
|
|
12
|
+
*
|
|
13
|
+
* const validations = {
|
|
14
|
+
* document: {
|
|
15
|
+
* type: 'NIF',
|
|
16
|
+
* locale: 'pt-PT'
|
|
17
|
+
* }
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* const isValid = validateDocument('123456789', validations);
|
|
21
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare const _default: (value: string, validations: TValidationMethods) => boolean;
|
|
25
|
+
export default _default;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the length of a value based on the provided validation rules.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be validated. Can be of any type but will be converted to a string for length validation.
|
|
6
|
+
* @param validations - An object containing the length validation rules.
|
|
7
|
+
* @returns `true` if the value meets the length validation rule, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import validateLength from './path/to/validationFunctions';
|
|
12
|
+
*
|
|
13
|
+
* const validations = {
|
|
14
|
+
* length: {
|
|
15
|
+
* target: 5,
|
|
16
|
+
* rule: 'equal'
|
|
17
|
+
* }
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* const isValid = validateLength('hello', validations);
|
|
21
|
+
* console.log(isValid); // Output: true
|
|
22
|
+
*
|
|
23
|
+
* // Using from a JSON config
|
|
24
|
+
* const config = {
|
|
25
|
+
* inputValue: 'test',
|
|
26
|
+
* validations: {
|
|
27
|
+
* length: {
|
|
28
|
+
* target: 4,
|
|
29
|
+
* rule: 'equal'
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const isValid = validateLength(config.inputValue, config.validations);
|
|
35
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare const _default: (value: unknown, validations: TValidationMethods) => boolean;
|
|
39
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a value is included in the specified array within the validation rules.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be checked.
|
|
6
|
+
* @param validations - An object containing validation methods, including an array of allowed values.
|
|
7
|
+
* @returns `true` if the value is included in the array, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { includes } from './path/to/validationFunctions';
|
|
12
|
+
*
|
|
13
|
+
* const validations = {
|
|
14
|
+
* includes: ['apple', 'banana', 'cherry']
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* const isValid = includes('banana', validations);
|
|
18
|
+
* console.log(isValid); // Output: true
|
|
19
|
+
*
|
|
20
|
+
* // Using from a JSON config
|
|
21
|
+
* const config = {
|
|
22
|
+
* inputValue: 'apple',
|
|
23
|
+
* validations: {
|
|
24
|
+
* includes: ['apple', 'banana', 'cherry']
|
|
25
|
+
* }
|
|
26
|
+
* };
|
|
27
|
+
*
|
|
28
|
+
* const isValid = includes(config.inputValue, config.validations);
|
|
29
|
+
* console.log(isValid); // Output: true or false based on validation
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const includes: (value: unknown, validations?: TValidationMethods | null) => boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a value is required.
|
|
4
|
+
*
|
|
5
|
+
* @param {unknown} value - The value to be validated.
|
|
6
|
+
* @param {TValidationMethods} validations - The validation methods object containing the required validation rule.
|
|
7
|
+
* @returns {boolean} - Returns `true` if the value is required and is empty or not provided, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Assume validations is an object with a required property
|
|
12
|
+
* const validations = { required: true };
|
|
13
|
+
*
|
|
14
|
+
* // Returns true because the value is required and is empty
|
|
15
|
+
* const result1 = required('', validations);
|
|
16
|
+
* console.log(result1); // true
|
|
17
|
+
*
|
|
18
|
+
* // Returns false because the value is required and is provided
|
|
19
|
+
* const result2 = required('text', validations);
|
|
20
|
+
* console.log(result2); // false
|
|
21
|
+
*
|
|
22
|
+
* // Returns false because the required validation rule is not set
|
|
23
|
+
* const result3 = required('', { required: false });
|
|
24
|
+
* console.log(result3); // false
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const required: (value: unknown, validations: TValidationMethods) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Validates that a value matches a boolean rule. Useful with iVars property.
|
|
30
|
+
*
|
|
31
|
+
* @param _
|
|
32
|
+
* @param {TValidationMethods} validations - The validation methods object containing the boolean validation rule.
|
|
33
|
+
* @returns {boolean} - Returns `true` if the boolean validation rule is set and fails, otherwise `false`.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Assume validations is an object with a bool property
|
|
38
|
+
* const validations = { bool: true };
|
|
39
|
+
*
|
|
40
|
+
* // Returns true because the boolean validation rule is set to fail
|
|
41
|
+
* const result1 = bool(null, validations);
|
|
42
|
+
* console.log(result1); // true
|
|
43
|
+
*
|
|
44
|
+
* // Returns false because the boolean validation rule is not set
|
|
45
|
+
* const result2 = bool(null, { bool: false });
|
|
46
|
+
* console.log(result2); // false
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const bool: (_: unknown, validations: TValidationMethods | null) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Validates that a value exists. Useful with iVars property.
|
|
52
|
+
*
|
|
53
|
+
* @param {unknown} value - The value to be validated.
|
|
54
|
+
* @param {TValidationMethods} validations - The validation methods object containing the exists validation rule.
|
|
55
|
+
* @returns {boolean} - Returns `true` if the value does not exist when the exists rule is set, otherwise `false`.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // Assume validations is an object with an exists property
|
|
60
|
+
* const validations = { exists: true };
|
|
61
|
+
*
|
|
62
|
+
* // Returns true because the value does not exist
|
|
63
|
+
* const result1 = exists(null, validations);
|
|
64
|
+
* console.log(result1); // true
|
|
65
|
+
*
|
|
66
|
+
* // Returns false because the value exists
|
|
67
|
+
* const result2 = exists('text', validations);
|
|
68
|
+
* console.log(result2); // false
|
|
69
|
+
*
|
|
70
|
+
* // Returns false because the exists validation rule is not set
|
|
71
|
+
* const result3 = exists(null, { exists: false });
|
|
72
|
+
* console.log(result3); // false
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare const exists: (value: unknown, validations: TValidationMethods) => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a value meets multiple validation rules.
|
|
4
|
+
*
|
|
5
|
+
* @param {number | string | boolean} value - The value to be validated.
|
|
6
|
+
* @param {TValidationMethods} methods - The validation methods object containing the multipleValidations rule set.
|
|
7
|
+
* @returns {boolean} - Returns `true` if the value meets the specified multiple validation rules, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Assume validations is an object with a multipleValidations property
|
|
12
|
+
* const validations = {
|
|
13
|
+
* multipleValidations: {
|
|
14
|
+
* rule: 'AND',
|
|
15
|
+
* validations: {
|
|
16
|
+
* required: true,
|
|
17
|
+
* isNumber: true
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // Returns true because both required and isNumber validations pass
|
|
23
|
+
* const result1 = multipleValidations(123, validations);
|
|
24
|
+
* console.log(result1); // true
|
|
25
|
+
*
|
|
26
|
+
* // Returns false because the value is not a number
|
|
27
|
+
* const result2 = multipleValidations('abc', validations);
|
|
28
|
+
* console.log(result2); // false
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const multipleValidations: (value: number | string | boolean, methods: TValidationMethods) => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
import { TValidationHandler } from '../types/utility';
|
|
3
|
+
/**
|
|
4
|
+
* Validates a given value based on specified validation methods inside a custom named validation.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to be validated.
|
|
7
|
+
* @param {TValidationMethods} methods - The validation methods to be applied.
|
|
8
|
+
* @param {TValidationHandler} validations - An object containing every validation methods to be executed.
|
|
9
|
+
* @returns {boolean} - Returns true if any of the validation methods pass, otherwise false.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const value = 'example@example.com';
|
|
13
|
+
* const methods = {
|
|
14
|
+
* required: true,
|
|
15
|
+
* email: true
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* const isValid = validateValue(value, methods);
|
|
19
|
+
* console.log(isValid); // Output: true
|
|
20
|
+
*/
|
|
21
|
+
declare const _default: (value: unknown, methods: TValidationMethods, validations: TValidationHandler) => boolean;
|
|
22
|
+
export default _default;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Validates if a value exceeds the maximum allowed value.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to be checked.
|
|
6
|
+
* @param validations - An object containing the maximum value for validation.
|
|
7
|
+
* @returns `true` if the value exceeds the maximum, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { max } from './path/to/validationFunctions';
|
|
12
|
+
*
|
|
13
|
+
* const validations = { max: 10 };
|
|
14
|
+
*
|
|
15
|
+
* const isValid = max(15, validations);
|
|
16
|
+
* console.log(isValid); // Output: true
|
|
17
|
+
*
|
|
18
|
+
* // Using from a JSON config
|
|
19
|
+
* const config = {
|
|
20
|
+
* inputValue: '8',
|
|
21
|
+
* validations: { max: 10 }
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* const isValid = max(config.inputValue, config.validations);
|
|
25
|
+
* console.log(isValid); // Output: false
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const max: (value: unknown, validations: TValidationMethods) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Validates if a value is less than the minimum allowed value.
|
|
31
|
+
*
|
|
32
|
+
* @param value - The value to be checked.
|
|
33
|
+
* @param validations - An object containing the minimum value for validation.
|
|
34
|
+
* @returns `true` if the value is less than the minimum, otherwise `false`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { min } from './path/to/validationFunctions';
|
|
39
|
+
*
|
|
40
|
+
* const validations = { min: 5 };
|
|
41
|
+
*
|
|
42
|
+
* const isValid = min(3, validations);
|
|
43
|
+
* console.log(isValid); // Output: true
|
|
44
|
+
*
|
|
45
|
+
* // Using from a JSON config
|
|
46
|
+
* const config = {
|
|
47
|
+
* inputValue: '8',
|
|
48
|
+
* validations: { min: 10 }
|
|
49
|
+
* };
|
|
50
|
+
*
|
|
51
|
+
* const isValid = min(config.inputValue, config.validations);
|
|
52
|
+
* console.log(isValid); // Output: true
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const min: (value: unknown, validations: TValidationMethods) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Validates if a value falls within a specified range.
|
|
58
|
+
*
|
|
59
|
+
* @param value - The value to be checked.
|
|
60
|
+
* @param validations - An object containing the range (start and end) for validation.
|
|
61
|
+
* @returns `true` if the value falls within the range, otherwise `false`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { between } from './path/to/validationFunctions';
|
|
66
|
+
*
|
|
67
|
+
* const validations = { between: { start: 5, end: 10 } };
|
|
68
|
+
*
|
|
69
|
+
* const isValid = between(7, validations);
|
|
70
|
+
* console.log(isValid); // Output: true
|
|
71
|
+
*
|
|
72
|
+
* // Using from a JSON config
|
|
73
|
+
* const config = {
|
|
74
|
+
* inputValue: '4',
|
|
75
|
+
* validations: { between: { start: 5, end: 10 } }
|
|
76
|
+
* };
|
|
77
|
+
*
|
|
78
|
+
* const isValid = between(config.inputValue, config.validations);
|
|
79
|
+
* console.log(isValid); // Output: false
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const between: (value: unknown, validations: TValidationMethods) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a given value is less than a specified threshold.
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
87
|
+
* @param validations - An object containing validation methods, specifically the `lessThan` property which holds the threshold value.
|
|
88
|
+
* @returns Returns `false` if the `lessThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is greater than or equal to the `lessThan` threshold.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const validations = { lessThan: 10 };
|
|
93
|
+
* console.log(lessThan(5, validations)); // true
|
|
94
|
+
* console.log(lessThan(15, validations)); // false
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const lessThan: (value: unknown, validations: TValidationMethods) => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Checks if a given value is greater than a specified threshold.
|
|
100
|
+
*
|
|
101
|
+
* @param value - The value to be checked. This value will be converted to a number.
|
|
102
|
+
* @param validations - An object containing validation methods, specifically the `greaterThan` property which holds the threshold value.
|
|
103
|
+
* @returns Returns `false` if the `greaterThan` threshold is not provided or if the value is not a valid number. Otherwise, returns `true` if the value is less than or equal to the `greaterThan` threshold.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const validations = { greaterThan: 10 };
|
|
108
|
+
* console.log(greaterThan(15, validations)); // true
|
|
109
|
+
* console.log(greaterThan(5, validations)); // false
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare const greaterThan: (value: unknown, validations: TValidationMethods) => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Validates if a value contains sequential numbers.
|
|
115
|
+
*
|
|
116
|
+
* @param value - The value to be checked.
|
|
117
|
+
* @param validations - An object containing the validation methods.
|
|
118
|
+
* @returns `true` if the value contains sequential numbers, otherwise `false`.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* import { sequential } from './path/to/validationFunctions';
|
|
123
|
+
*
|
|
124
|
+
* const validations = { sequential: true };
|
|
125
|
+
*
|
|
126
|
+
* const isValid = sequential('12345', validations);
|
|
127
|
+
* console.log(isValid); // Output: true
|
|
128
|
+
*
|
|
129
|
+
* // Using in a React component
|
|
130
|
+
* const MyComponent = ({ inputValue }) => {
|
|
131
|
+
* const isValid = sequential(inputValue, validations);
|
|
132
|
+
* return <div>{isValid ? 'Valid' : 'Invalid'}</div>;
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* // Using from a JSON config
|
|
136
|
+
* const config = {
|
|
137
|
+
* inputValue: '98765',
|
|
138
|
+
* validations: { sequential: true }
|
|
139
|
+
* };
|
|
140
|
+
*
|
|
141
|
+
* const isValid = sequential(config.inputValue, config.validations);
|
|
142
|
+
* console.log(isValid); // Output: true
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare const sequential: (value: unknown, validations: TValidationMethods) => boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TValidationMethods } from '../types/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a value meets specified conditions.
|
|
4
|
+
*
|
|
5
|
+
* @param {number | string | boolean} value - The value to be validated.
|
|
6
|
+
* @param {TValidationMethods} validations - The validation methods object containing the conditions validation rule.
|
|
7
|
+
* @returns {boolean} - Returns `true` if the value meets the specified conditions, otherwise `false`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Assume validations is an object with a conditions property
|
|
12
|
+
* const validations = {
|
|
13
|
+
* conditions: {
|
|
14
|
+
* rule: 'and',
|
|
15
|
+
* set: [
|
|
16
|
+
* { condition: '===', origin: 10, target: 10 },
|
|
17
|
+
* { condition: '!==', origin: 5, target: 3 }
|
|
18
|
+
* ]
|
|
19
|
+
* }
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // Returns true because both conditions are met
|
|
23
|
+
* const result1 = conditions(10, validations);
|
|
24
|
+
* console.log(result1); // true
|
|
25
|
+
*
|
|
26
|
+
* // Returns false because the second condition is not met
|
|
27
|
+
* const result2 = conditions(5, validations);
|
|
28
|
+
* console.log(result2); // false
|
|
29
|
+
*
|
|
30
|
+
* // Returns true because at least one condition is met with 'or' rule
|
|
31
|
+
* const orValidations = {
|
|
32
|
+
* conditions: {
|
|
33
|
+
* rule: 'or',
|
|
34
|
+
* set: [
|
|
35
|
+
* { condition: '===', origin: 10, target: 5 },
|
|
36
|
+
* { condition: '!==', origin: 5, target: 3 }
|
|
37
|
+
* ]
|
|
38
|
+
* }
|
|
39
|
+
* };
|
|
40
|
+
* const result3 = conditions(10, orValidations);
|
|
41
|
+
* console.log(result3); // true
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const conditions: (value: number | string | boolean, validations: TValidationMethods) => boolean;
|