quantique-field-validator 1.0.9 → 2.0.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/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +176 -0
- package/dist/messages/defaultErrorMessages.d.ts +8 -0
- package/dist/messages/defaultErrorMessages.d.ts.map +1 -0
- package/dist/messages/defaultErrorMessages.js +38 -0
- package/dist/types/index.d.ts +97 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/safeRegex.d.ts +22 -0
- package/dist/utils/safeRegex.d.ts.map +1 -0
- package/dist/utils/safeRegex.js +32 -0
- package/dist/validators/validateAadhaar.d.ts +8 -0
- package/dist/validators/validateAadhaar.d.ts.map +1 -0
- package/dist/validators/validateAadhaar.js +20 -0
- package/dist/validators/validateAddress.d.ts +8 -0
- package/dist/validators/validateAddress.d.ts.map +1 -0
- package/dist/validators/validateAddress.js +38 -0
- package/dist/validators/validateAlphanumeric.d.ts +8 -0
- package/dist/validators/validateAlphanumeric.d.ts.map +1 -0
- package/dist/validators/validateAlphanumeric.js +38 -0
- package/dist/validators/validateBankIFSC.d.ts +9 -0
- package/dist/validators/validateBankIFSC.d.ts.map +1 -0
- package/dist/validators/validateBankIFSC.js +33 -0
- package/dist/validators/validateChassisNumber.d.ts +9 -0
- package/dist/validators/validateChassisNumber.d.ts.map +1 -0
- package/dist/validators/validateChassisNumber.js +33 -0
- package/dist/validators/validateCustom.d.ts +9 -0
- package/dist/validators/validateCustom.d.ts.map +1 -0
- package/dist/validators/validateCustom.js +26 -0
- package/dist/validators/validateDate.d.ts +11 -0
- package/dist/validators/validateDate.d.ts.map +1 -0
- package/dist/validators/validateDate.js +119 -0
- package/dist/validators/validateEmail.d.ts +9 -0
- package/dist/validators/validateEmail.d.ts.map +1 -0
- package/dist/validators/validateEmail.js +33 -0
- package/dist/validators/validateEngineNumber.d.ts +8 -0
- package/dist/validators/validateEngineNumber.d.ts.map +1 -0
- package/dist/validators/validateEngineNumber.js +32 -0
- package/dist/validators/validateFirstMiddleLastName.d.ts +9 -0
- package/dist/validators/validateFirstMiddleLastName.d.ts.map +1 -0
- package/dist/validators/validateFirstMiddleLastName.js +33 -0
- package/dist/validators/validateFloatNumber.d.ts +13 -0
- package/dist/validators/validateFloatNumber.d.ts.map +1 -0
- package/dist/validators/validateFloatNumber.js +75 -0
- package/dist/validators/validateGST.d.ts +9 -0
- package/dist/validators/validateGST.d.ts.map +1 -0
- package/dist/validators/validateGST.js +21 -0
- package/dist/validators/validateIPAddress.d.ts +8 -0
- package/dist/validators/validateIPAddress.d.ts.map +1 -0
- package/dist/validators/validateIPAddress.js +51 -0
- package/dist/validators/validateMobile.d.ts +9 -0
- package/dist/validators/validateMobile.d.ts.map +1 -0
- package/dist/validators/validateMobile.js +21 -0
- package/dist/validators/validateName.d.ts +11 -0
- package/dist/validators/validateName.d.ts.map +1 -0
- package/dist/validators/validateName.js +53 -0
- package/dist/validators/validateNumber.d.ts +8 -0
- package/dist/validators/validateNumber.d.ts.map +1 -0
- package/dist/validators/validateNumber.js +51 -0
- package/dist/validators/validatePanCard.d.ts +8 -0
- package/dist/validators/validatePanCard.d.ts.map +1 -0
- package/dist/validators/validatePanCard.js +20 -0
- package/dist/validators/validatePassword.d.ts +4 -0
- package/dist/validators/validatePassword.d.ts.map +1 -0
- package/dist/validators/validatePassword.js +47 -0
- package/dist/validators/validatePincode.d.ts +8 -0
- package/dist/validators/validatePincode.d.ts.map +1 -0
- package/dist/validators/validatePincode.js +20 -0
- package/dist/validators/validateRTO.d.ts +12 -0
- package/dist/validators/validateRTO.d.ts.map +1 -0
- package/dist/validators/validateRTO.js +45 -0
- package/dist/validators/validateString.d.ts +8 -0
- package/dist/validators/validateString.d.ts.map +1 -0
- package/dist/validators/validateString.js +39 -0
- package/dist/validators/validateURL.d.ts +9 -0
- package/dist/validators/validateURL.d.ts.map +1 -0
- package/dist/validators/validateURL.js +51 -0
- package/package.json +50 -9
- package/.github/workflows/publish.yml +0 -31
- package/Messages/defaultErrorMessages.js +0 -27
- package/README.md +0 -0
- package/Validators/ValidateChassisNumber.js +0 -37
- package/Validators/validateAadhaar.js +0 -18
- package/Validators/validateAddress.js +0 -38
- package/Validators/validateAlphanumeric.js +0 -47
- package/Validators/validateBankIFSC.js +0 -41
- package/Validators/validateCustom.js +0 -18
- package/Validators/validateDate.js +0 -166
- package/Validators/validateEmail.js +0 -39
- package/Validators/validateEngineNumber.js +0 -37
- package/Validators/validateFirstMiddleLastName.js +0 -36
- package/Validators/validateFloatNumber.js +0 -108
- package/Validators/validateGST.js +0 -19
- package/Validators/validateIPAddress.js +0 -41
- package/Validators/validateMobile.js +0 -116
- package/Validators/validateName.js +0 -67
- package/Validators/validateNumber.js +0 -75
- package/Validators/validatePanCard.js +0 -23
- package/Validators/validatePassword.js +0 -38
- package/Validators/validateRTO.js +0 -41
- package/Validators/validateString.js +0 -41
- package/index.js +0 -194
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* quantique-field-validator
|
|
3
|
+
*
|
|
4
|
+
* Enterprise-grade dynamic field validator for Indian and international form fields.
|
|
5
|
+
* Supports tree-shakeable named exports (individual validators) and a single
|
|
6
|
+
* dynamicValidator entry point that dispatches by type string.
|
|
7
|
+
*
|
|
8
|
+
* @module @quantique-field-validator
|
|
9
|
+
*/
|
|
10
|
+
import defaultErrorMessages from './messages/defaultErrorMessages';
|
|
11
|
+
import validateString from './validators/validateString';
|
|
12
|
+
import validateAlphanumeric from './validators/validateAlphanumeric';
|
|
13
|
+
import validateNumber from './validators/validateNumber';
|
|
14
|
+
import validateFloatNumber from './validators/validateFloatNumber';
|
|
15
|
+
import validateDate from './validators/validateDate';
|
|
16
|
+
import validateName from './validators/validateName';
|
|
17
|
+
import validateFirstMiddleLastName from './validators/validateFirstMiddleLastName';
|
|
18
|
+
import validateEmail from './validators/validateEmail';
|
|
19
|
+
import validateMobile from './validators/validateMobile';
|
|
20
|
+
import validateAddress from './validators/validateAddress';
|
|
21
|
+
import validatePassword from './validators/validatePassword';
|
|
22
|
+
import validateURL from './validators/validateURL';
|
|
23
|
+
import validateCustom from './validators/validateCustom';
|
|
24
|
+
import validateAadhaar from './validators/validateAadhaar';
|
|
25
|
+
import validatePanCard from './validators/validatePanCard';
|
|
26
|
+
import validateGST from './validators/validateGST';
|
|
27
|
+
import validateChassisNumber from './validators/validateChassisNumber';
|
|
28
|
+
import validateEngineNumber from './validators/validateEngineNumber';
|
|
29
|
+
import validateIPAddress from './validators/validateIPAddress';
|
|
30
|
+
import validateRTO from './validators/validateRTO';
|
|
31
|
+
import validateBankIFSC from './validators/validateBankIFSC';
|
|
32
|
+
import validatePincode from './validators/validatePincode';
|
|
33
|
+
export type { ValidationResult, ValidationRules, ErrorMessages, ValidatorFn, ValidatorType, CustomValidatorFn, DefaultErrorMessagesFn, } from './types';
|
|
34
|
+
export { defaultErrorMessages, validateString, validateAlphanumeric, validateNumber, validateFloatNumber, validateDate, validateName, validateFirstMiddleLastName, validateEmail, validateMobile, validateAddress, validatePassword, validateURL, validateCustom, validateAadhaar, validatePanCard, validateGST, validateChassisNumber, validateEngineNumber, validateIPAddress, validateRTO, validateBankIFSC, validatePincode, };
|
|
35
|
+
import type { ValidationResult, ValidationRules, ValidatorType, CustomValidatorFn } from './types';
|
|
36
|
+
/**
|
|
37
|
+
* Dynamic field validator — dispatches validation based on the `type` string.
|
|
38
|
+
*
|
|
39
|
+
* @param value - Raw input value (string or any type for number validators)
|
|
40
|
+
* @param type - Validator type key (e.g. 'email', 'mobile', 'aadhaar')
|
|
41
|
+
* @param rules - Optional validation rules (minLength, regex, required, etc.)
|
|
42
|
+
* @param customValidator - Optional external custom validator; runs before type dispatch
|
|
43
|
+
* @returns ValidationResult { isValid: boolean, error: string }
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* dynamicValidator('test@example.com', 'email') // { isValid: true, error: '' }
|
|
47
|
+
* dynamicValidator('', 'email', { required: true }) // { isValid: false, error: '...' }
|
|
48
|
+
*/
|
|
49
|
+
declare const dynamicValidator: (value: unknown, type: ValidatorType, rules?: ValidationRules, customValidator?: CustomValidatorFn | null) => ValidationResult;
|
|
50
|
+
export default dynamicValidator;
|
|
51
|
+
export { dynamicValidator };
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,oBAAoB,MAAM,iCAAiC,CAAC;AACnE,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,mBAAmB,MAAM,kCAAkC,CAAC;AACnE,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,2BAA2B,MAAM,0CAA0C,CAAC;AACnF,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAC7D,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAC3D,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,qBAAqB,MAAM,oCAAoC,CAAC;AACvE,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAC7D,OAAO,eAAe,MAAM,8BAA8B,CAAC;AAG3D,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,2BAA2B,EAC3B,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,eAAe,EACf,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,CAAC;AAEF,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,gBAAgB,GACpB,OAAO,OAAO,EACd,MAAM,aAAa,EACnB,QAAO,eAAoB,EAC3B,kBAAiB,iBAAiB,GAAG,IAAW,KAC/C,gBAoIF,CAAC;AAEF,eAAe,gBAAgB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* quantique-field-validator
|
|
4
|
+
*
|
|
5
|
+
* Enterprise-grade dynamic field validator for Indian and international form fields.
|
|
6
|
+
* Supports tree-shakeable named exports (individual validators) and a single
|
|
7
|
+
* dynamicValidator entry point that dispatches by type string.
|
|
8
|
+
*
|
|
9
|
+
* @module @quantique-field-validator
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.dynamicValidator = exports.validatePincode = exports.validateBankIFSC = exports.validateRTO = exports.validateIPAddress = exports.validateEngineNumber = exports.validateChassisNumber = exports.validateGST = exports.validatePanCard = exports.validateAadhaar = exports.validateCustom = exports.validateURL = exports.validatePassword = exports.validateAddress = exports.validateMobile = exports.validateEmail = exports.validateFirstMiddleLastName = exports.validateName = exports.validateDate = exports.validateFloatNumber = exports.validateNumber = exports.validateAlphanumeric = exports.validateString = exports.defaultErrorMessages = void 0;
|
|
13
|
+
const defaultErrorMessages_1 = require("./messages/defaultErrorMessages");
|
|
14
|
+
exports.defaultErrorMessages = defaultErrorMessages_1.default;
|
|
15
|
+
const validateString_1 = require("./validators/validateString");
|
|
16
|
+
exports.validateString = validateString_1.default;
|
|
17
|
+
const validateAlphanumeric_1 = require("./validators/validateAlphanumeric");
|
|
18
|
+
exports.validateAlphanumeric = validateAlphanumeric_1.default;
|
|
19
|
+
const validateNumber_1 = require("./validators/validateNumber");
|
|
20
|
+
exports.validateNumber = validateNumber_1.default;
|
|
21
|
+
const validateFloatNumber_1 = require("./validators/validateFloatNumber");
|
|
22
|
+
exports.validateFloatNumber = validateFloatNumber_1.default;
|
|
23
|
+
const validateDate_1 = require("./validators/validateDate");
|
|
24
|
+
exports.validateDate = validateDate_1.default;
|
|
25
|
+
const validateName_1 = require("./validators/validateName");
|
|
26
|
+
exports.validateName = validateName_1.default;
|
|
27
|
+
const validateFirstMiddleLastName_1 = require("./validators/validateFirstMiddleLastName");
|
|
28
|
+
exports.validateFirstMiddleLastName = validateFirstMiddleLastName_1.default;
|
|
29
|
+
const validateEmail_1 = require("./validators/validateEmail");
|
|
30
|
+
exports.validateEmail = validateEmail_1.default;
|
|
31
|
+
const validateMobile_1 = require("./validators/validateMobile");
|
|
32
|
+
exports.validateMobile = validateMobile_1.default;
|
|
33
|
+
const validateAddress_1 = require("./validators/validateAddress");
|
|
34
|
+
exports.validateAddress = validateAddress_1.default;
|
|
35
|
+
const validatePassword_1 = require("./validators/validatePassword");
|
|
36
|
+
exports.validatePassword = validatePassword_1.default;
|
|
37
|
+
const validateURL_1 = require("./validators/validateURL");
|
|
38
|
+
exports.validateURL = validateURL_1.default;
|
|
39
|
+
const validateCustom_1 = require("./validators/validateCustom");
|
|
40
|
+
exports.validateCustom = validateCustom_1.default;
|
|
41
|
+
const validateAadhaar_1 = require("./validators/validateAadhaar");
|
|
42
|
+
exports.validateAadhaar = validateAadhaar_1.default;
|
|
43
|
+
const validatePanCard_1 = require("./validators/validatePanCard");
|
|
44
|
+
exports.validatePanCard = validatePanCard_1.default;
|
|
45
|
+
const validateGST_1 = require("./validators/validateGST");
|
|
46
|
+
exports.validateGST = validateGST_1.default;
|
|
47
|
+
const validateChassisNumber_1 = require("./validators/validateChassisNumber");
|
|
48
|
+
exports.validateChassisNumber = validateChassisNumber_1.default;
|
|
49
|
+
const validateEngineNumber_1 = require("./validators/validateEngineNumber");
|
|
50
|
+
exports.validateEngineNumber = validateEngineNumber_1.default;
|
|
51
|
+
const validateIPAddress_1 = require("./validators/validateIPAddress");
|
|
52
|
+
exports.validateIPAddress = validateIPAddress_1.default;
|
|
53
|
+
const validateRTO_1 = require("./validators/validateRTO");
|
|
54
|
+
exports.validateRTO = validateRTO_1.default;
|
|
55
|
+
const validateBankIFSC_1 = require("./validators/validateBankIFSC");
|
|
56
|
+
exports.validateBankIFSC = validateBankIFSC_1.default;
|
|
57
|
+
const validatePincode_1 = require("./validators/validatePincode");
|
|
58
|
+
exports.validatePincode = validatePincode_1.default;
|
|
59
|
+
const safeRegex_1 = require("./utils/safeRegex");
|
|
60
|
+
/**
|
|
61
|
+
* Dynamic field validator — dispatches validation based on the `type` string.
|
|
62
|
+
*
|
|
63
|
+
* @param value - Raw input value (string or any type for number validators)
|
|
64
|
+
* @param type - Validator type key (e.g. 'email', 'mobile', 'aadhaar')
|
|
65
|
+
* @param rules - Optional validation rules (minLength, regex, required, etc.)
|
|
66
|
+
* @param customValidator - Optional external custom validator; runs before type dispatch
|
|
67
|
+
* @returns ValidationResult { isValid: boolean, error: string }
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* dynamicValidator('test@example.com', 'email') // { isValid: true, error: '' }
|
|
71
|
+
* dynamicValidator('', 'email', { required: true }) // { isValid: false, error: '...' }
|
|
72
|
+
*/
|
|
73
|
+
const dynamicValidator = (value, type, rules = {}, customValidator = null) => {
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
75
|
+
const selectedValue = value;
|
|
76
|
+
if (typeof selectedValue === 'string' && safeRegex_1.EMOJI_REGEX.test(selectedValue)) {
|
|
77
|
+
return {
|
|
78
|
+
isValid: false,
|
|
79
|
+
error: (_c = (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.emoji) !== null && _b !== void 0 ? _b : (0, defaultErrorMessages_1.default)(rules, type).emoji) !== null && _c !== void 0 ? _c : 'Value contains emoji characters which are not allowed',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (rules.required && (!selectedValue || selectedValue === '')) {
|
|
83
|
+
return {
|
|
84
|
+
isValid: false,
|
|
85
|
+
error: (_e = (_d = rules.errorMessages) === null || _d === void 0 ? void 0 : _d.required) !== null && _e !== void 0 ? _e : (0, defaultErrorMessages_1.default)(rules, type).required,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (!rules.required && (!selectedValue || selectedValue === '')) {
|
|
89
|
+
return { isValid: true, error: '' };
|
|
90
|
+
}
|
|
91
|
+
if (customValidator !== null && typeof customValidator === 'function') {
|
|
92
|
+
const result = customValidator(selectedValue);
|
|
93
|
+
if (typeof result === 'object' && result.isValid === false) {
|
|
94
|
+
return {
|
|
95
|
+
isValid: false,
|
|
96
|
+
error: result.error || (0, defaultErrorMessages_1.default)(rules, type).customValidation,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (result === false) {
|
|
100
|
+
return {
|
|
101
|
+
isValid: false,
|
|
102
|
+
error: (0, defaultErrorMessages_1.default)(rules, type).customValidation,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (rules.customValidator !== undefined && typeof rules.customValidator === 'function') {
|
|
107
|
+
const result = rules.customValidator(selectedValue);
|
|
108
|
+
if (typeof result === 'object' && result.isValid === false) {
|
|
109
|
+
return {
|
|
110
|
+
isValid: false,
|
|
111
|
+
error: result.error || (0, defaultErrorMessages_1.default)(rules, type).custom,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (result === false) {
|
|
115
|
+
return {
|
|
116
|
+
isValid: false,
|
|
117
|
+
error: (0, defaultErrorMessages_1.default)(rules, type).custom,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
switch (type) {
|
|
122
|
+
case 'string':
|
|
123
|
+
return (0, validateString_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
124
|
+
case 'alphanumeric':
|
|
125
|
+
return (0, validateAlphanumeric_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
126
|
+
case 'number':
|
|
127
|
+
return (0, validateNumber_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
128
|
+
case 'float':
|
|
129
|
+
return (0, validateFloatNumber_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
130
|
+
case 'date':
|
|
131
|
+
return (0, validateDate_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
132
|
+
case 'name':
|
|
133
|
+
return (0, validateName_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
134
|
+
case 'firstName':
|
|
135
|
+
case 'middleName':
|
|
136
|
+
case 'lastName':
|
|
137
|
+
return (0, validateFirstMiddleLastName_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
138
|
+
case 'email':
|
|
139
|
+
return (0, validateEmail_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
140
|
+
case 'mobile':
|
|
141
|
+
return (0, validateMobile_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
142
|
+
case 'address':
|
|
143
|
+
return (0, validateAddress_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
144
|
+
case 'password':
|
|
145
|
+
return (0, validatePassword_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
146
|
+
case 'url':
|
|
147
|
+
return (0, validateURL_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
148
|
+
case 'pincode':
|
|
149
|
+
return (0, validatePincode_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
150
|
+
case 'chassis':
|
|
151
|
+
return (0, validateChassisNumber_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
152
|
+
case 'engine':
|
|
153
|
+
return (0, validateEngineNumber_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
154
|
+
case 'aadhaar':
|
|
155
|
+
return (0, validateAadhaar_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
156
|
+
case 'pan':
|
|
157
|
+
return (0, validatePanCard_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
158
|
+
case 'gst':
|
|
159
|
+
return (0, validateGST_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
160
|
+
case 'rto':
|
|
161
|
+
return (0, validateRTO_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
162
|
+
case 'ifsc':
|
|
163
|
+
return (0, validateBankIFSC_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
164
|
+
case 'ip':
|
|
165
|
+
return (0, validateIPAddress_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
166
|
+
case 'custom':
|
|
167
|
+
return (0, validateCustom_1.default)(selectedValue, rules, defaultErrorMessages_1.default, type);
|
|
168
|
+
default:
|
|
169
|
+
return {
|
|
170
|
+
isValid: false,
|
|
171
|
+
error: (0, defaultErrorMessages_1.default)(rules, type).noValidation,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
exports.dynamicValidator = dynamicValidator;
|
|
176
|
+
exports.default = dynamicValidator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a strongly-typed map of default error messages for all validation scenarios.
|
|
4
|
+
* All messages can be overridden via rules.errorMessages.
|
|
5
|
+
*/
|
|
6
|
+
declare const defaultErrorMessages: DefaultErrorMessagesFn;
|
|
7
|
+
export default defaultErrorMessages;
|
|
8
|
+
//# sourceMappingURL=defaultErrorMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultErrorMessages.d.ts","sourceRoot":"","sources":["../../src/messages/defaultErrorMessages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD;;;GAGG;AACH,QAAA,MAAM,oBAAoB,EAAE,sBA2B1B,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Returns a strongly-typed map of default error messages for all validation scenarios.
|
|
5
|
+
* All messages can be overridden via rules.errorMessages.
|
|
6
|
+
*/
|
|
7
|
+
const defaultErrorMessages = (rules, type) => {
|
|
8
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
9
|
+
return ({
|
|
10
|
+
noSpace: 'Value should not contain spaces',
|
|
11
|
+
minAge: `User must be at least ${(_a = rules.minAge) !== null && _a !== void 0 ? _a : ''} years old`,
|
|
12
|
+
maxAge: `User must be at most ${(_b = rules.maxAge) !== null && _b !== void 0 ? _b : ''} years old`,
|
|
13
|
+
minMinus: 'Date is too far in the past',
|
|
14
|
+
maxMinus: 'Date must be further in the past',
|
|
15
|
+
minPlus: 'Date must be further in the future',
|
|
16
|
+
maxPlus: 'Date is too far in the future',
|
|
17
|
+
required: 'This field is required',
|
|
18
|
+
minLength: `Minimum length should be ${(_c = rules.minLength) !== null && _c !== void 0 ? _c : ''}`,
|
|
19
|
+
maxLength: `Maximum length should be ${(_d = rules.maxLength) !== null && _d !== void 0 ? _d : ''}`,
|
|
20
|
+
minValue: `Minimum value should be ${(_e = rules.minValue) !== null && _e !== void 0 ? _e : ''}`,
|
|
21
|
+
maxValue: `Maximum value should be ${(_f = rules.maxValue) !== null && _f !== void 0 ? _f : ''}`,
|
|
22
|
+
invalid: `Please enter a valid ${type}`,
|
|
23
|
+
noValidation: `No validation exists for type "${type}"`,
|
|
24
|
+
custom: 'Validation failed',
|
|
25
|
+
Alphanumeric: 'Value must be alphanumeric',
|
|
26
|
+
chassisNumber: 'Invalid chassis number',
|
|
27
|
+
engineNumber: 'Invalid engine number',
|
|
28
|
+
ipAddress: 'Invalid IP address',
|
|
29
|
+
name: 'Invalid name',
|
|
30
|
+
rto: 'Invalid RTO code',
|
|
31
|
+
ifsc: 'Invalid bank IFSC code',
|
|
32
|
+
url: 'Please enter a valid URL',
|
|
33
|
+
pincode: 'Please enter a valid 6-digit PIN code',
|
|
34
|
+
customValidation: (_h = (_g = rules.errorMessages) === null || _g === void 0 ? void 0 : _g.customValidation) !== null && _h !== void 0 ? _h : 'Custom validation failed',
|
|
35
|
+
emoji: 'Emoji characters are not allowed',
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.default = defaultErrorMessages;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
error: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ErrorMessages {
|
|
6
|
+
required?: string;
|
|
7
|
+
minLength?: string;
|
|
8
|
+
maxLength?: string;
|
|
9
|
+
minValue?: string;
|
|
10
|
+
maxValue?: string;
|
|
11
|
+
invalid?: string;
|
|
12
|
+
regex?: string;
|
|
13
|
+
empty?: string;
|
|
14
|
+
minAge?: string;
|
|
15
|
+
maxAge?: string;
|
|
16
|
+
minPlus?: string;
|
|
17
|
+
maxPlus?: string;
|
|
18
|
+
minMinus?: string;
|
|
19
|
+
maxMinus?: string;
|
|
20
|
+
decimalPrecision?: string;
|
|
21
|
+
maxWholeDigits?: string;
|
|
22
|
+
noSpace?: string;
|
|
23
|
+
emoji?: string;
|
|
24
|
+
customValidation?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ValidationRules {
|
|
27
|
+
required?: boolean;
|
|
28
|
+
minLength?: number;
|
|
29
|
+
maxLength?: number;
|
|
30
|
+
minValue?: number;
|
|
31
|
+
maxValue?: number;
|
|
32
|
+
/** Raw regex string — compiled safely at runtime; invalid patterns silently fail validation */
|
|
33
|
+
regex?: string;
|
|
34
|
+
/** Date format string, e.g. "DD/MM/YYYY" */
|
|
35
|
+
format?: string;
|
|
36
|
+
/** Minimum age in years (for date validators) */
|
|
37
|
+
minAge?: number;
|
|
38
|
+
/** Maximum age in years (for date validators) */
|
|
39
|
+
maxAge?: number;
|
|
40
|
+
/** Minimum days/months/years the date must be in the future */
|
|
41
|
+
minPlus?: number;
|
|
42
|
+
/** Maximum days/months/years the date may be in the future */
|
|
43
|
+
maxPlus?: number;
|
|
44
|
+
/** Minimum days/months/years the date must be in the past */
|
|
45
|
+
minMinus?: number;
|
|
46
|
+
/** Maximum days/months/years the date may be in the past */
|
|
47
|
+
maxMinus?: number;
|
|
48
|
+
/** Time unit for relative date rules */
|
|
49
|
+
unit?: 'day' | 'days' | 'month' | 'months' | 'year' | 'years';
|
|
50
|
+
/** Allowed decimal digits after the decimal point */
|
|
51
|
+
decimalPrecision?: number;
|
|
52
|
+
/** Maximum digits before the decimal point */
|
|
53
|
+
maxWholeDigits?: number;
|
|
54
|
+
/** IP version filter: 'v4' | 'v6' | undefined (both) */
|
|
55
|
+
version?: string;
|
|
56
|
+
/** Name sub-type: 'user' | 'corporate' */
|
|
57
|
+
type?: string;
|
|
58
|
+
/** Password strength: 'basic' | 'medium' | 'strong' (default: 'basic') */
|
|
59
|
+
strength?: 'basic' | 'medium' | 'strong';
|
|
60
|
+
errorMessages?: ErrorMessages;
|
|
61
|
+
/** Inline custom validator attached to rules — runs after type-based validation */
|
|
62
|
+
customValidator?: CustomValidatorFn;
|
|
63
|
+
}
|
|
64
|
+
export type CustomValidatorFn = (value: string) => ValidationResult | boolean;
|
|
65
|
+
/** Strongly-typed map returned by defaultErrorMessages — all keys are guaranteed strings */
|
|
66
|
+
export interface DefaultMessages {
|
|
67
|
+
noSpace: string;
|
|
68
|
+
minAge: string;
|
|
69
|
+
maxAge: string;
|
|
70
|
+
minMinus: string;
|
|
71
|
+
maxMinus: string;
|
|
72
|
+
minPlus: string;
|
|
73
|
+
maxPlus: string;
|
|
74
|
+
required: string;
|
|
75
|
+
minLength: string;
|
|
76
|
+
maxLength: string;
|
|
77
|
+
minValue: string;
|
|
78
|
+
maxValue: string;
|
|
79
|
+
invalid: string;
|
|
80
|
+
noValidation: string;
|
|
81
|
+
custom: string;
|
|
82
|
+
Alphanumeric: string;
|
|
83
|
+
chassisNumber: string;
|
|
84
|
+
engineNumber: string;
|
|
85
|
+
ipAddress: string;
|
|
86
|
+
name: string;
|
|
87
|
+
rto: string;
|
|
88
|
+
ifsc: string;
|
|
89
|
+
url: string;
|
|
90
|
+
pincode: string;
|
|
91
|
+
customValidation: string;
|
|
92
|
+
emoji: string;
|
|
93
|
+
}
|
|
94
|
+
export type DefaultErrorMessagesFn = (rules: ValidationRules, type: string) => DefaultMessages;
|
|
95
|
+
export type ValidatorFn = (value: string, rules: ValidationRules, defaultMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
96
|
+
export type ValidatorType = 'string' | 'alphanumeric' | 'number' | 'float' | 'date' | 'name' | 'firstName' | 'middleName' | 'lastName' | 'email' | 'mobile' | 'address' | 'password' | 'url' | 'pincode' | 'chassis' | 'engine' | 'aadhaar' | 'pan' | 'gst' | 'rto' | 'ifsc' | 'ip' | 'custom' | (string & Record<never, never>);
|
|
97
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely compiles a regex pattern string into a RegExp.
|
|
3
|
+
*
|
|
4
|
+
* Security: Wrapping new RegExp() in try/catch prevents crashes from
|
|
5
|
+
* malformed user-supplied patterns and avoids potential ReDoS escalation
|
|
6
|
+
* through invalid back-references or catastrophic alternation.
|
|
7
|
+
*
|
|
8
|
+
* If the pattern is invalid, returns a never-matching regex /(?!)/ so that
|
|
9
|
+
* validation naturally fails with the configured invalid-field error message.
|
|
10
|
+
*
|
|
11
|
+
* @param pattern - Raw regex pattern string from rules.regex
|
|
12
|
+
* @param flags - Optional regex flags (default: none)
|
|
13
|
+
* @returns A compiled RegExp, or /(?!)/ if the pattern is malformed
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildRegex(pattern: string, flags?: string): RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* Unicode property escape covering all Extended Pictographic code points.
|
|
18
|
+
* More comprehensive and future-proof than manually listing Unicode ranges.
|
|
19
|
+
* Requires the 'u' flag.
|
|
20
|
+
*/
|
|
21
|
+
export declare const EMOJI_REGEX: RegExp;
|
|
22
|
+
//# sourceMappingURL=safeRegex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeRegex.d.ts","sourceRoot":"","sources":["../../src/utils/safeRegex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAM9D;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAA+B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EMOJI_REGEX = void 0;
|
|
4
|
+
exports.buildRegex = buildRegex;
|
|
5
|
+
/**
|
|
6
|
+
* Safely compiles a regex pattern string into a RegExp.
|
|
7
|
+
*
|
|
8
|
+
* Security: Wrapping new RegExp() in try/catch prevents crashes from
|
|
9
|
+
* malformed user-supplied patterns and avoids potential ReDoS escalation
|
|
10
|
+
* through invalid back-references or catastrophic alternation.
|
|
11
|
+
*
|
|
12
|
+
* If the pattern is invalid, returns a never-matching regex /(?!)/ so that
|
|
13
|
+
* validation naturally fails with the configured invalid-field error message.
|
|
14
|
+
*
|
|
15
|
+
* @param pattern - Raw regex pattern string from rules.regex
|
|
16
|
+
* @param flags - Optional regex flags (default: none)
|
|
17
|
+
* @returns A compiled RegExp, or /(?!)/ if the pattern is malformed
|
|
18
|
+
*/
|
|
19
|
+
function buildRegex(pattern, flags = '') {
|
|
20
|
+
try {
|
|
21
|
+
return new RegExp(pattern, flags);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return /(?!)/;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Unicode property escape covering all Extended Pictographic code points.
|
|
29
|
+
* More comprehensive and future-proof than manually listing Unicode ranges.
|
|
30
|
+
* Requires the 'u' flag.
|
|
31
|
+
*/
|
|
32
|
+
exports.EMOJI_REGEX = /\p{Extended_Pictographic}/u;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates Indian Aadhaar numbers.
|
|
4
|
+
* Default: 12-digit number starting with 2-9.
|
|
5
|
+
*/
|
|
6
|
+
declare const validateAadhaar: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
7
|
+
export default validateAadhaar;
|
|
8
|
+
//# sourceMappingURL=validateAadhaar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAadhaar.d.ts","sourceRoot":"","sources":["../../src/validators/validateAadhaar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;GAGG;AACH,QAAA,MAAM,eAAe,GACnB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAeF,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates Indian Aadhaar numbers.
|
|
6
|
+
* Default: 12-digit number starting with 2-9.
|
|
7
|
+
*/
|
|
8
|
+
const validateAadhaar = (value, rules, defaultErrorMessages, type) => {
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
const defaultRegex = /^[2-9]{1}[0-9]{11}$/;
|
|
11
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
12
|
+
if (!regexToUse.test(value)) {
|
|
13
|
+
return {
|
|
14
|
+
isValid: false,
|
|
15
|
+
error: (_d = (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.regex) !== null && _b !== void 0 ? _b : (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.invalid) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).invalid,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return { isValid: true, error: '' };
|
|
19
|
+
};
|
|
20
|
+
exports.default = validateAadhaar;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates postal/street addresses.
|
|
4
|
+
* Allows letters, digits, spaces, and common address punctuation: , . / - # & :
|
|
5
|
+
*/
|
|
6
|
+
declare const validateAddress: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
7
|
+
export default validateAddress;
|
|
8
|
+
//# sourceMappingURL=validateAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAddress.d.ts","sourceRoot":"","sources":["../../src/validators/validateAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;GAGG;AACH,QAAA,MAAM,eAAe,GACnB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAiCF,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates postal/street addresses.
|
|
6
|
+
* Allows letters, digits, spaces, and common address punctuation: , . / - # & :
|
|
7
|
+
*/
|
|
8
|
+
const validateAddress = (value, rules, defaultErrorMessages, type) => {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
11
|
+
return {
|
|
12
|
+
isValid: false,
|
|
13
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
17
|
+
return {
|
|
18
|
+
isValid: false,
|
|
19
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!value.trim()) {
|
|
23
|
+
return {
|
|
24
|
+
isValid: false,
|
|
25
|
+
error: (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).invalid,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const defaultRegex = /^[a-zA-Z0-9\s,./\-#&:]+$/;
|
|
29
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
30
|
+
if (!regexToUse.test(value)) {
|
|
31
|
+
return {
|
|
32
|
+
isValid: false,
|
|
33
|
+
error: (_h = (_g = rules.errorMessages) === null || _g === void 0 ? void 0 : _g.invalid) !== null && _h !== void 0 ? _h : defaultErrorMessages(rules, type).invalid,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { isValid: true, error: '' };
|
|
37
|
+
};
|
|
38
|
+
exports.default = validateAddress;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates alphanumeric strings (lowercase letters and digits by default).
|
|
4
|
+
* Accepts minLength, maxLength, and a custom regex override.
|
|
5
|
+
*/
|
|
6
|
+
declare const validateAlphanumeric: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
7
|
+
export default validateAlphanumeric;
|
|
8
|
+
//# sourceMappingURL=validateAlphanumeric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAlphanumeric.d.ts","sourceRoot":"","sources":["../../src/validators/validateAlphanumeric.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;GAGG;AACH,QAAA,MAAM,oBAAoB,GACxB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAuCF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates alphanumeric strings (lowercase letters and digits by default).
|
|
6
|
+
* Accepts minLength, maxLength, and a custom regex override.
|
|
7
|
+
*/
|
|
8
|
+
const validateAlphanumeric = (value, rules, defaultErrorMessages, type) => {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
10
|
+
if (typeof value !== 'string') {
|
|
11
|
+
return {
|
|
12
|
+
isValid: false,
|
|
13
|
+
error: (_c = (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.invalid) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).Alphanumeric) !== null && _c !== void 0 ? _c : defaultErrorMessages(rules, type).invalid,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
17
|
+
return {
|
|
18
|
+
isValid: false,
|
|
19
|
+
error: (_e = (_d = rules.errorMessages) === null || _d === void 0 ? void 0 : _d.minLength) !== null && _e !== void 0 ? _e : defaultErrorMessages(rules, type).minLength,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
23
|
+
return {
|
|
24
|
+
isValid: false,
|
|
25
|
+
error: (_g = (_f = rules.errorMessages) === null || _f === void 0 ? void 0 : _f.maxLength) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).maxLength,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const defaultRegex = /^[a-z0-9]+$/;
|
|
29
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
30
|
+
if (!regexToUse.test(value)) {
|
|
31
|
+
return {
|
|
32
|
+
isValid: false,
|
|
33
|
+
error: (_k = (_j = (_h = rules.errorMessages) === null || _h === void 0 ? void 0 : _h.invalid) !== null && _j !== void 0 ? _j : defaultErrorMessages(rules, type).Alphanumeric) !== null && _k !== void 0 ? _k : defaultErrorMessages(rules, type).invalid,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { isValid: true, error: '' };
|
|
37
|
+
};
|
|
38
|
+
exports.default = validateAlphanumeric;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates Indian bank IFSC codes.
|
|
4
|
+
* Format: 4 uppercase letters + '0' + 6 alphanumeric chars (total 11 chars).
|
|
5
|
+
* Default min/max length is 11.
|
|
6
|
+
*/
|
|
7
|
+
declare const validateBankIFSC: (value: string, rules: ValidationRules | undefined, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateBankIFSC;
|
|
9
|
+
//# sourceMappingURL=validateBankIFSC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateBankIFSC.d.ts","sourceRoot":"","sources":["../../src/validators/validateBankIFSC.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,gBAAgB,GACpB,OAAO,MAAM,EACb,OAAO,eAAe,YAAmC,EACzD,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBA6BF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|