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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates Indian bank IFSC codes.
|
|
6
|
+
* Format: 4 uppercase letters + '0' + 6 alphanumeric chars (total 11 chars).
|
|
7
|
+
* Default min/max length is 11.
|
|
8
|
+
*/
|
|
9
|
+
const validateBankIFSC = (value, rules = { minLength: 11, maxLength: 11 }, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
11
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
12
|
+
return {
|
|
13
|
+
isValid: false,
|
|
14
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
18
|
+
return {
|
|
19
|
+
isValid: false,
|
|
20
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const defaultRegex = /^[A-Z]{4}0[A-Z0-9]{6}$/;
|
|
24
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
25
|
+
if (!regexToUse.test(value)) {
|
|
26
|
+
return {
|
|
27
|
+
isValid: false,
|
|
28
|
+
error: (_g = (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).ifsc) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return { isValid: true, error: '' };
|
|
32
|
+
};
|
|
33
|
+
exports.default = validateBankIFSC;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates vehicle chassis numbers (VIN format).
|
|
4
|
+
* Standard 17-character VIN excluding I, O, Q to avoid confusion with 1 and 0.
|
|
5
|
+
* Must contain at least one letter.
|
|
6
|
+
*/
|
|
7
|
+
declare const validateChassisNumber: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateChassisNumber;
|
|
9
|
+
//# sourceMappingURL=validateChassisNumber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateChassisNumber.d.ts","sourceRoot":"","sources":["../../src/validators/validateChassisNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,qBAAqB,GACzB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBA6BF,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates vehicle chassis numbers (VIN format).
|
|
6
|
+
* Standard 17-character VIN excluding I, O, Q to avoid confusion with 1 and 0.
|
|
7
|
+
* Must contain at least one letter.
|
|
8
|
+
*/
|
|
9
|
+
const validateChassisNumber = (value, rules, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
11
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
12
|
+
return {
|
|
13
|
+
isValid: false,
|
|
14
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
18
|
+
return {
|
|
19
|
+
isValid: false,
|
|
20
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const defaultRegex = /^(?=.*[A-HJ-NPR-Z])[A-HJ-NPR-Z0-9]{17}$/;
|
|
24
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
25
|
+
if (!regexToUse.test(value)) {
|
|
26
|
+
return {
|
|
27
|
+
isValid: false,
|
|
28
|
+
error: (_g = (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).chassisNumber) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return { isValid: true, error: '' };
|
|
32
|
+
};
|
|
33
|
+
exports.default = validateChassisNumber;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a value against a caller-supplied regex pattern.
|
|
4
|
+
* rules.regex is required for this validator type.
|
|
5
|
+
* If rules.regex is missing or malformed, validation fails gracefully.
|
|
6
|
+
*/
|
|
7
|
+
declare const validateCustom: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateCustom;
|
|
9
|
+
//# sourceMappingURL=validateCustom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateCustom.d.ts","sourceRoot":"","sources":["../../src/validators/validateCustom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAkBF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates a value against a caller-supplied regex pattern.
|
|
6
|
+
* rules.regex is required for this validator type.
|
|
7
|
+
* If rules.regex is missing or malformed, validation fails gracefully.
|
|
8
|
+
*/
|
|
9
|
+
const validateCustom = (value, rules, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
11
|
+
if (!rules.regex) {
|
|
12
|
+
return {
|
|
13
|
+
isValid: false,
|
|
14
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.invalid) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).invalid,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const regexToUse = (0, safeRegex_1.buildRegex)(rules.regex);
|
|
18
|
+
if (!regexToUse.test(value)) {
|
|
19
|
+
return {
|
|
20
|
+
isValid: false,
|
|
21
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.invalid) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).invalid,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return { isValid: true, error: '' };
|
|
25
|
+
};
|
|
26
|
+
exports.default = validateCustom;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates date values with support for:
|
|
4
|
+
* - Custom format strings (DD/MM/YYYY, MM-DD-YYYY, etc.)
|
|
5
|
+
* - Age-based checks (minAge, maxAge in years)
|
|
6
|
+
* - Relative past/future offsets (minMinus, maxMinus, minPlus, maxPlus)
|
|
7
|
+
* - Configurable time units: day | month | year
|
|
8
|
+
*/
|
|
9
|
+
declare const validateDate: (value: string, rules: ValidationRules | undefined, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
10
|
+
export default validateDate;
|
|
11
|
+
//# sourceMappingURL=validateDate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateDate.d.ts","sourceRoot":"","sources":["../../src/validators/validateDate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAuD1F;;;;;;GAMG;AACH,QAAA,MAAM,YAAY,GAChB,OAAO,MAAM,EACb,OAAO,eAAe,YAA2B,EACjD,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAkGF,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function parseDateByFormat(value, format) {
|
|
4
|
+
var _a, _b, _c;
|
|
5
|
+
if (!format) {
|
|
6
|
+
return new Date(value);
|
|
7
|
+
}
|
|
8
|
+
const separator = format.includes('/') ? '/' : '-';
|
|
9
|
+
const parts = value.split(separator);
|
|
10
|
+
const formatParts = format.split(separator);
|
|
11
|
+
if (parts.length !== 3 || formatParts.length !== 3) {
|
|
12
|
+
return new Date(NaN);
|
|
13
|
+
}
|
|
14
|
+
const dateParts = {};
|
|
15
|
+
formatParts.forEach((part, index) => {
|
|
16
|
+
var _a;
|
|
17
|
+
dateParts[part] = parseInt((_a = parts[index]) !== null && _a !== void 0 ? _a : '0', 10);
|
|
18
|
+
});
|
|
19
|
+
const day = (_a = dateParts['DD']) !== null && _a !== void 0 ? _a : NaN;
|
|
20
|
+
const month = ((_b = dateParts['MM']) !== null && _b !== void 0 ? _b : 1) - 1;
|
|
21
|
+
const year = (_c = dateParts['YYYY']) !== null && _c !== void 0 ? _c : NaN;
|
|
22
|
+
return new Date(year, month, day);
|
|
23
|
+
}
|
|
24
|
+
function applyOffset(baseDate, value, unit, operation = 'add') {
|
|
25
|
+
const date = new Date(baseDate);
|
|
26
|
+
const multiplier = operation === 'subtract' ? -1 : 1;
|
|
27
|
+
switch (unit) {
|
|
28
|
+
case 'month':
|
|
29
|
+
case 'months':
|
|
30
|
+
date.setMonth(date.getMonth() + value * multiplier);
|
|
31
|
+
break;
|
|
32
|
+
case 'year':
|
|
33
|
+
case 'years':
|
|
34
|
+
date.setFullYear(date.getFullYear() + value * multiplier);
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
date.setDate(date.getDate() + value * multiplier);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return date;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Validates date values with support for:
|
|
44
|
+
* - Custom format strings (DD/MM/YYYY, MM-DD-YYYY, etc.)
|
|
45
|
+
* - Age-based checks (minAge, maxAge in years)
|
|
46
|
+
* - Relative past/future offsets (minMinus, maxMinus, minPlus, maxPlus)
|
|
47
|
+
* - Configurable time units: day | month | year
|
|
48
|
+
*/
|
|
49
|
+
const validateDate = (value, rules = { format: 'DD/MM/YYYY' }, defaultErrorMessages, type) => {
|
|
50
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
51
|
+
const parsedDate = parseDateByFormat(value, rules.format);
|
|
52
|
+
const today = new Date();
|
|
53
|
+
today.setHours(0, 0, 0, 0);
|
|
54
|
+
if (isNaN(parsedDate.getTime())) {
|
|
55
|
+
return {
|
|
56
|
+
isValid: false,
|
|
57
|
+
error: (_c = (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.invalid) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).invalid) !== null && _c !== void 0 ? _c : 'Invalid date format',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (rules.minAge !== undefined) {
|
|
61
|
+
const minAgeDate = new Date();
|
|
62
|
+
minAgeDate.setFullYear(minAgeDate.getFullYear() - rules.minAge);
|
|
63
|
+
if (parsedDate > minAgeDate) {
|
|
64
|
+
return {
|
|
65
|
+
isValid: false,
|
|
66
|
+
error: (_f = (_e = (_d = rules.errorMessages) === null || _d === void 0 ? void 0 : _d.minAge) !== null && _e !== void 0 ? _e : defaultErrorMessages(rules, type).minAge) !== null && _f !== void 0 ? _f : `You must be at least ${rules.minAge} years old`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (rules.maxAge !== undefined) {
|
|
71
|
+
const maxAgeDate = new Date();
|
|
72
|
+
maxAgeDate.setFullYear(maxAgeDate.getFullYear() - rules.maxAge);
|
|
73
|
+
if (parsedDate < maxAgeDate) {
|
|
74
|
+
return {
|
|
75
|
+
isValid: false,
|
|
76
|
+
error: (_j = (_h = (_g = rules.errorMessages) === null || _g === void 0 ? void 0 : _g.maxAge) !== null && _h !== void 0 ? _h : defaultErrorMessages(rules, type).maxAge) !== null && _j !== void 0 ? _j : `You must be at most ${rules.maxAge} years old`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const unit = (_k = rules.unit) !== null && _k !== void 0 ? _k : 'day';
|
|
81
|
+
if (rules.minMinus !== undefined) {
|
|
82
|
+
const minPast = applyOffset(today, rules.minMinus, unit, 'subtract');
|
|
83
|
+
if (parsedDate < minPast) {
|
|
84
|
+
return {
|
|
85
|
+
isValid: false,
|
|
86
|
+
error: (_o = (_m = (_l = rules.errorMessages) === null || _l === void 0 ? void 0 : _l.minMinus) !== null && _m !== void 0 ? _m : defaultErrorMessages(rules, type).minMinus) !== null && _o !== void 0 ? _o : `Date should not be earlier than ${rules.minMinus} ${unit}(s) ago`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (rules.maxPlus !== undefined) {
|
|
91
|
+
const maxFuture = applyOffset(today, rules.maxPlus, unit, 'add');
|
|
92
|
+
if (parsedDate > maxFuture) {
|
|
93
|
+
return {
|
|
94
|
+
isValid: false,
|
|
95
|
+
error: (_r = (_q = (_p = rules.errorMessages) === null || _p === void 0 ? void 0 : _p.maxPlus) !== null && _q !== void 0 ? _q : defaultErrorMessages(rules, type).maxPlus) !== null && _r !== void 0 ? _r : `Date should not be more than ${rules.maxPlus} ${unit}(s) in the future`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (rules.minPlus !== undefined) {
|
|
100
|
+
const minFuture = applyOffset(today, rules.minPlus, unit, 'add');
|
|
101
|
+
if (parsedDate < minFuture) {
|
|
102
|
+
return {
|
|
103
|
+
isValid: false,
|
|
104
|
+
error: (_u = (_t = (_s = rules.errorMessages) === null || _s === void 0 ? void 0 : _s.minPlus) !== null && _t !== void 0 ? _t : defaultErrorMessages(rules, type).minPlus) !== null && _u !== void 0 ? _u : `Date should be at least ${rules.minPlus} ${unit}(s) in the future`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (rules.maxMinus !== undefined) {
|
|
109
|
+
const maxPast = applyOffset(today, rules.maxMinus, unit, 'subtract');
|
|
110
|
+
if (parsedDate > maxPast) {
|
|
111
|
+
return {
|
|
112
|
+
isValid: false,
|
|
113
|
+
error: (_x = (_w = (_v = rules.errorMessages) === null || _v === void 0 ? void 0 : _v.maxMinus) !== null && _w !== void 0 ? _w : defaultErrorMessages(rules, type).maxMinus) !== null && _x !== void 0 ? _x : `Date should not be later than ${rules.maxMinus} ${unit}(s) ago`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return { isValid: true, error: '' };
|
|
118
|
+
};
|
|
119
|
+
exports.default = validateDate;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates email addresses.
|
|
4
|
+
* Uses RFC-5321 compatible regex by default.
|
|
5
|
+
* Accepts optional minLength / maxLength constraints and a custom regex override.
|
|
6
|
+
*/
|
|
7
|
+
declare const validateEmail: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateEmail;
|
|
9
|
+
//# sourceMappingURL=validateEmail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateEmail.d.ts","sourceRoot":"","sources":["../../src/validators/validateEmail.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,aAAa,GACjB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBA2BF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates email addresses.
|
|
6
|
+
* Uses RFC-5321 compatible regex by default.
|
|
7
|
+
* Accepts optional minLength / maxLength constraints and a custom regex override.
|
|
8
|
+
*/
|
|
9
|
+
const validateEmail = (value, rules, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
12
|
+
return {
|
|
13
|
+
isValid: false,
|
|
14
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
18
|
+
return {
|
|
19
|
+
isValid: false,
|
|
20
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const defaultRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}))$/;
|
|
24
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
25
|
+
if (!regexToUse.test(value)) {
|
|
26
|
+
return {
|
|
27
|
+
isValid: false,
|
|
28
|
+
error: (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).invalid,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return { isValid: true, error: '' };
|
|
32
|
+
};
|
|
33
|
+
exports.default = validateEmail;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates vehicle engine numbers.
|
|
4
|
+
* Default: 5–25 alphanumeric characters (may include dots).
|
|
5
|
+
*/
|
|
6
|
+
declare const validateEngineNumber: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
7
|
+
export default validateEngineNumber;
|
|
8
|
+
//# sourceMappingURL=validateEngineNumber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateEngineNumber.d.ts","sourceRoot":"","sources":["../../src/validators/validateEngineNumber.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,gBA6BF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates vehicle engine numbers.
|
|
6
|
+
* Default: 5–25 alphanumeric characters (may include dots).
|
|
7
|
+
*/
|
|
8
|
+
const validateEngineNumber = (value, rules, defaultErrorMessages, type) => {
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
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
|
+
const defaultRegex = /^[A-Za-z0-9.]{5,25}$/;
|
|
23
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
24
|
+
if (!regexToUse.test(value)) {
|
|
25
|
+
return {
|
|
26
|
+
isValid: false,
|
|
27
|
+
error: (_g = (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).engineNumber) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return { isValid: true, error: '' };
|
|
31
|
+
};
|
|
32
|
+
exports.default = validateEngineNumber;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates first, middle, or last name fields.
|
|
4
|
+
* Supports a broad set of international Unicode letters.
|
|
5
|
+
* Does NOT allow spaces (use validateName for full-name fields).
|
|
6
|
+
*/
|
|
7
|
+
declare const validateFirstMiddleLastName: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateFirstMiddleLastName;
|
|
9
|
+
//# sourceMappingURL=validateFirstMiddleLastName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateFirstMiddleLastName.d.ts","sourceRoot":"","sources":["../../src/validators/validateFirstMiddleLastName.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,2BAA2B,GAC/B,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBA8BF,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates first, middle, or last name fields.
|
|
6
|
+
* Supports a broad set of international Unicode letters.
|
|
7
|
+
* Does NOT allow spaces (use validateName for full-name fields).
|
|
8
|
+
*/
|
|
9
|
+
const validateFirstMiddleLastName = (value, rules, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
11
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
12
|
+
return {
|
|
13
|
+
isValid: false,
|
|
14
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
18
|
+
return {
|
|
19
|
+
isValid: false,
|
|
20
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const defaultRegex = /^[a-zA-ZàáâäãåąčćęèéêëėįìíîïłńòóôöõøùúûüųūÿýżźñçčšžÀÁÂÄÃÅĄĆČĖĘÈÉÊËÌÍÎÏĮŁŃÒÓÔÖÕØÙÚÛÜŲŪŸÝŻŹÑßÇŒÆČŠŽ∂ð]+$/u;
|
|
24
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex, 'u') : defaultRegex;
|
|
25
|
+
if (!regexToUse.test(value)) {
|
|
26
|
+
return {
|
|
27
|
+
isValid: false,
|
|
28
|
+
error: (_g = (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).name) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return { isValid: true, error: '' };
|
|
32
|
+
};
|
|
33
|
+
exports.default = validateFirstMiddleLastName;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates floating-point numbers.
|
|
4
|
+
* Supports:
|
|
5
|
+
* - decimalPrecision — max digits after decimal
|
|
6
|
+
* - maxWholeDigits — max digits before decimal
|
|
7
|
+
* - minValue / maxValue — numeric range checks
|
|
8
|
+
* - minLength / maxLength — string-length checks on the raw input
|
|
9
|
+
* - custom regex override
|
|
10
|
+
*/
|
|
11
|
+
declare const validateFloatNumber: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
12
|
+
export default validateFloatNumber;
|
|
13
|
+
//# sourceMappingURL=validateFloatNumber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateFloatNumber.d.ts","sourceRoot":"","sources":["../../src/validators/validateFloatNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;;;;;GAQG;AACH,QAAA,MAAM,mBAAmB,GACvB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAuFF,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates floating-point numbers.
|
|
6
|
+
* Supports:
|
|
7
|
+
* - decimalPrecision — max digits after decimal
|
|
8
|
+
* - maxWholeDigits — max digits before decimal
|
|
9
|
+
* - minValue / maxValue — numeric range checks
|
|
10
|
+
* - minLength / maxLength — string-length checks on the raw input
|
|
11
|
+
* - custom regex override
|
|
12
|
+
*/
|
|
13
|
+
const validateFloatNumber = (value, rules, defaultErrorMessages, type) => {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
15
|
+
if (/\s/.test(value)) {
|
|
16
|
+
return {
|
|
17
|
+
isValid: false,
|
|
18
|
+
error: (_e = (_d = (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.noSpace) !== null && _b !== void 0 ? _b : (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.invalid) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).noSpace) !== null && _e !== void 0 ? _e : defaultErrorMessages(rules, type).invalid,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const defaultFloatRegex = /^\d+(\.\d+)?$/;
|
|
22
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultFloatRegex;
|
|
23
|
+
if (!regexToUse.test(value)) {
|
|
24
|
+
return {
|
|
25
|
+
isValid: false,
|
|
26
|
+
error: (_h = (_g = (_f = rules.errorMessages) === null || _f === void 0 ? void 0 : _f.invalid) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid) !== null && _h !== void 0 ? _h : 'Please enter a valid amount (e.g., 123.45)',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const numberValue = Number(value);
|
|
30
|
+
if (rules.decimalPrecision !== undefined) {
|
|
31
|
+
const decimalPart = value.split('.')[1];
|
|
32
|
+
const actualPrecision = decimalPart ? decimalPart.length : 0;
|
|
33
|
+
if (actualPrecision > rules.decimalPrecision) {
|
|
34
|
+
return {
|
|
35
|
+
isValid: false,
|
|
36
|
+
error: (_k = (_j = rules.errorMessages) === null || _j === void 0 ? void 0 : _j.decimalPrecision) !== null && _k !== void 0 ? _k : `Only up to ${rules.decimalPrecision} digits allowed after the decimal point`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (rules.maxWholeDigits !== undefined) {
|
|
41
|
+
const wholePart = (_l = value.split('.')[0]) !== null && _l !== void 0 ? _l : '';
|
|
42
|
+
if (wholePart.length > rules.maxWholeDigits) {
|
|
43
|
+
return {
|
|
44
|
+
isValid: false,
|
|
45
|
+
error: (_o = (_m = rules.errorMessages) === null || _m === void 0 ? void 0 : _m.maxWholeDigits) !== null && _o !== void 0 ? _o : `Only up to ${rules.maxWholeDigits} digits allowed before the decimal point`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
50
|
+
return {
|
|
51
|
+
isValid: false,
|
|
52
|
+
error: (_q = (_p = rules.errorMessages) === null || _p === void 0 ? void 0 : _p.minLength) !== null && _q !== void 0 ? _q : defaultErrorMessages(rules, type).minLength,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
56
|
+
return {
|
|
57
|
+
isValid: false,
|
|
58
|
+
error: (_s = (_r = rules.errorMessages) === null || _r === void 0 ? void 0 : _r.maxLength) !== null && _s !== void 0 ? _s : defaultErrorMessages(rules, type).maxLength,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (rules.minValue !== undefined && numberValue < rules.minValue) {
|
|
62
|
+
return {
|
|
63
|
+
isValid: false,
|
|
64
|
+
error: (_v = (_u = (_t = rules.errorMessages) === null || _t === void 0 ? void 0 : _t.minValue) !== null && _u !== void 0 ? _u : defaultErrorMessages(rules, type).minValue) !== null && _v !== void 0 ? _v : `Amount must be at least ${rules.minValue}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (rules.maxValue !== undefined && numberValue > rules.maxValue) {
|
|
68
|
+
return {
|
|
69
|
+
isValid: false,
|
|
70
|
+
error: (_y = (_x = (_w = rules.errorMessages) === null || _w === void 0 ? void 0 : _w.maxValue) !== null && _x !== void 0 ? _x : defaultErrorMessages(rules, type).maxValue) !== null && _y !== void 0 ? _y : `Amount must not exceed ${rules.maxValue}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return { isValid: true, error: '' };
|
|
74
|
+
};
|
|
75
|
+
exports.default = validateFloatNumber;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates Indian GSTIN numbers.
|
|
4
|
+
* Format: 2 digits + 5 uppercase letters + 4 digits + 1 letter + 1 alphanumeric + 'Z' + 1 alphanumeric
|
|
5
|
+
* Total: 15 characters
|
|
6
|
+
*/
|
|
7
|
+
declare const validateGST: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateGST;
|
|
9
|
+
//# sourceMappingURL=validateGST.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateGST.d.ts","sourceRoot":"","sources":["../../src/validators/validateGST.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,WAAW,GACf,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAeF,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates Indian GSTIN numbers.
|
|
6
|
+
* Format: 2 digits + 5 uppercase letters + 4 digits + 1 letter + 1 alphanumeric + 'Z' + 1 alphanumeric
|
|
7
|
+
* Total: 15 characters
|
|
8
|
+
*/
|
|
9
|
+
const validateGST = (value, rules, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
11
|
+
const defaultRegex = /^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}Z{1}[A-Z\d]{1}$/;
|
|
12
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
13
|
+
if (!regexToUse.test(value)) {
|
|
14
|
+
return {
|
|
15
|
+
isValid: false,
|
|
16
|
+
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,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { isValid: true, error: '' };
|
|
20
|
+
};
|
|
21
|
+
exports.default = validateGST;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates IPv4, IPv6, or both (default) IP addresses.
|
|
4
|
+
* rules.version: 'v4' | 'v6' | undefined
|
|
5
|
+
*/
|
|
6
|
+
declare const validateIPAddress: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
7
|
+
export default validateIPAddress;
|
|
8
|
+
//# sourceMappingURL=validateIPAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateIPAddress.d.ts","sourceRoot":"","sources":["../../src/validators/validateIPAddress.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAmB1F;;;GAGG;AACH,QAAA,MAAM,iBAAiB,GACrB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAqCF,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* IPv4 regex — linear complexity, safe from ReDoS.
|
|
6
|
+
*/
|
|
7
|
+
const IPV4_REGEX = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
8
|
+
/**
|
|
9
|
+
* IPv6 regex — well-known standard pattern.
|
|
10
|
+
* Complexity is bounded because alternation arms are non-overlapping.
|
|
11
|
+
*/
|
|
12
|
+
const IPV6_REGEX = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|::(?:[fF]{4}(?::0{1,4})?:)?(?:(?:25[0-5]|(?:2[0-4]|1?[0-9])?[0-9])\.){3}(?:25[0-5]|(?:2[0-4]|1?[0-9])?[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1?[0-9])?[0-9])\.){3}(?:25[0-5]|(?:2[0-4]|1?[0-9])?[0-9]))$/;
|
|
13
|
+
const BOTH_REGEX = new RegExp(`(?:${IPV4_REGEX.source})|(?:${IPV6_REGEX.source})`);
|
|
14
|
+
/**
|
|
15
|
+
* Validates IPv4, IPv6, or both (default) IP addresses.
|
|
16
|
+
* rules.version: 'v4' | 'v6' | undefined
|
|
17
|
+
*/
|
|
18
|
+
const validateIPAddress = (value, rules, defaultErrorMessages, type) => {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
20
|
+
if (rules.minLength !== undefined && value.length < rules.minLength) {
|
|
21
|
+
return {
|
|
22
|
+
isValid: false,
|
|
23
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (rules.maxLength !== undefined && value.length > rules.maxLength) {
|
|
27
|
+
return {
|
|
28
|
+
isValid: false,
|
|
29
|
+
error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
let defaultRegex;
|
|
33
|
+
if (rules.version === 'v4') {
|
|
34
|
+
defaultRegex = IPV4_REGEX;
|
|
35
|
+
}
|
|
36
|
+
else if (rules.version === 'v6') {
|
|
37
|
+
defaultRegex = IPV6_REGEX;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
defaultRegex = BOTH_REGEX;
|
|
41
|
+
}
|
|
42
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
43
|
+
if (!regexToUse.test(value)) {
|
|
44
|
+
return {
|
|
45
|
+
isValid: false,
|
|
46
|
+
error: (_g = (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).ipAddress) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return { isValid: true, error: '' };
|
|
50
|
+
};
|
|
51
|
+
exports.default = validateIPAddress;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates mobile phone numbers.
|
|
4
|
+
* Default regex targets Indian mobile numbers: starts with 6–9, followed by 9 digits (10 digits total).
|
|
5
|
+
* Provide rules.regex to support other country formats.
|
|
6
|
+
*/
|
|
7
|
+
declare const validateMobile: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
|
|
8
|
+
export default validateMobile;
|
|
9
|
+
//# sourceMappingURL=validateMobile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateMobile.d.ts","sourceRoot":"","sources":["../../src/validators/validateMobile.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;GAIG;AACH,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAYF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const safeRegex_1 = require("../utils/safeRegex");
|
|
4
|
+
/**
|
|
5
|
+
* Validates mobile phone numbers.
|
|
6
|
+
* Default regex targets Indian mobile numbers: starts with 6–9, followed by 9 digits (10 digits total).
|
|
7
|
+
* Provide rules.regex to support other country formats.
|
|
8
|
+
*/
|
|
9
|
+
const validateMobile = (value, rules, defaultErrorMessages, type) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const defaultRegex = /^[6-9]\d{9}$/;
|
|
12
|
+
const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
|
|
13
|
+
if (!regexToUse.test(value)) {
|
|
14
|
+
return {
|
|
15
|
+
isValid: false,
|
|
16
|
+
error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.invalid) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).invalid,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { isValid: true, error: '' };
|
|
20
|
+
};
|
|
21
|
+
exports.default = validateMobile;
|