quantique-field-validator 1.0.9 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +0 -0
  2. package/dist/index.d.ts +52 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +176 -0
  5. package/dist/messages/defaultErrorMessages.d.ts +8 -0
  6. package/dist/messages/defaultErrorMessages.d.ts.map +1 -0
  7. package/dist/messages/defaultErrorMessages.js +38 -0
  8. package/dist/types/index.d.ts +97 -0
  9. package/dist/types/index.d.ts.map +1 -0
  10. package/dist/types/index.js +2 -0
  11. package/dist/utils/safeRegex.d.ts +22 -0
  12. package/dist/utils/safeRegex.d.ts.map +1 -0
  13. package/dist/utils/safeRegex.js +32 -0
  14. package/dist/validators/validateAadhaar.d.ts +8 -0
  15. package/dist/validators/validateAadhaar.d.ts.map +1 -0
  16. package/dist/validators/validateAadhaar.js +20 -0
  17. package/dist/validators/validateAddress.d.ts +8 -0
  18. package/dist/validators/validateAddress.d.ts.map +1 -0
  19. package/dist/validators/validateAddress.js +38 -0
  20. package/dist/validators/validateAlphanumeric.d.ts +8 -0
  21. package/dist/validators/validateAlphanumeric.d.ts.map +1 -0
  22. package/dist/validators/validateAlphanumeric.js +38 -0
  23. package/dist/validators/validateBankIFSC.d.ts +9 -0
  24. package/dist/validators/validateBankIFSC.d.ts.map +1 -0
  25. package/dist/validators/validateBankIFSC.js +33 -0
  26. package/dist/validators/validateChassisNumber.d.ts +9 -0
  27. package/dist/validators/validateChassisNumber.d.ts.map +1 -0
  28. package/dist/validators/validateChassisNumber.js +33 -0
  29. package/dist/validators/validateCustom.d.ts +9 -0
  30. package/dist/validators/validateCustom.d.ts.map +1 -0
  31. package/dist/validators/validateCustom.js +26 -0
  32. package/dist/validators/validateDate.d.ts +11 -0
  33. package/dist/validators/validateDate.d.ts.map +1 -0
  34. package/dist/validators/validateDate.js +119 -0
  35. package/dist/validators/validateEmail.d.ts +9 -0
  36. package/dist/validators/validateEmail.d.ts.map +1 -0
  37. package/dist/validators/validateEmail.js +33 -0
  38. package/dist/validators/validateEngineNumber.d.ts +8 -0
  39. package/dist/validators/validateEngineNumber.d.ts.map +1 -0
  40. package/dist/validators/validateEngineNumber.js +32 -0
  41. package/dist/validators/validateFirstMiddleLastName.d.ts +9 -0
  42. package/dist/validators/validateFirstMiddleLastName.d.ts.map +1 -0
  43. package/dist/validators/validateFirstMiddleLastName.js +33 -0
  44. package/dist/validators/validateFloatNumber.d.ts +13 -0
  45. package/dist/validators/validateFloatNumber.d.ts.map +1 -0
  46. package/dist/validators/validateFloatNumber.js +75 -0
  47. package/dist/validators/validateGST.d.ts +9 -0
  48. package/dist/validators/validateGST.d.ts.map +1 -0
  49. package/dist/validators/validateGST.js +21 -0
  50. package/dist/validators/validateIPAddress.d.ts +8 -0
  51. package/dist/validators/validateIPAddress.d.ts.map +1 -0
  52. package/dist/validators/validateIPAddress.js +51 -0
  53. package/dist/validators/validateMobile.d.ts +9 -0
  54. package/dist/validators/validateMobile.d.ts.map +1 -0
  55. package/dist/validators/validateMobile.js +21 -0
  56. package/dist/validators/validateName.d.ts +11 -0
  57. package/dist/validators/validateName.d.ts.map +1 -0
  58. package/dist/validators/validateName.js +53 -0
  59. package/dist/validators/validateNumber.d.ts +8 -0
  60. package/dist/validators/validateNumber.d.ts.map +1 -0
  61. package/dist/validators/validateNumber.js +51 -0
  62. package/dist/validators/validatePanCard.d.ts +8 -0
  63. package/dist/validators/validatePanCard.d.ts.map +1 -0
  64. package/dist/validators/validatePanCard.js +20 -0
  65. package/dist/validators/validatePassword.d.ts +4 -0
  66. package/dist/validators/validatePassword.d.ts.map +1 -0
  67. package/dist/validators/validatePassword.js +47 -0
  68. package/dist/validators/validatePincode.d.ts +8 -0
  69. package/dist/validators/validatePincode.d.ts.map +1 -0
  70. package/dist/validators/validatePincode.js +20 -0
  71. package/dist/validators/validateRTO.d.ts +12 -0
  72. package/dist/validators/validateRTO.d.ts.map +1 -0
  73. package/dist/validators/validateRTO.js +45 -0
  74. package/dist/validators/validateString.d.ts +8 -0
  75. package/dist/validators/validateString.d.ts.map +1 -0
  76. package/dist/validators/validateString.js +39 -0
  77. package/dist/validators/validateURL.d.ts +9 -0
  78. package/dist/validators/validateURL.d.ts.map +1 -0
  79. package/dist/validators/validateURL.js +51 -0
  80. package/package.json +50 -9
  81. package/.github/workflows/publish.yml +0 -31
  82. package/Messages/defaultErrorMessages.js +0 -27
  83. package/Validators/ValidateChassisNumber.js +0 -37
  84. package/Validators/validateAadhaar.js +0 -18
  85. package/Validators/validateAddress.js +0 -38
  86. package/Validators/validateAlphanumeric.js +0 -47
  87. package/Validators/validateBankIFSC.js +0 -41
  88. package/Validators/validateCustom.js +0 -18
  89. package/Validators/validateDate.js +0 -166
  90. package/Validators/validateEmail.js +0 -39
  91. package/Validators/validateEngineNumber.js +0 -37
  92. package/Validators/validateFirstMiddleLastName.js +0 -36
  93. package/Validators/validateFloatNumber.js +0 -108
  94. package/Validators/validateGST.js +0 -19
  95. package/Validators/validateIPAddress.js +0 -41
  96. package/Validators/validateMobile.js +0 -116
  97. package/Validators/validateName.js +0 -67
  98. package/Validators/validateNumber.js +0 -75
  99. package/Validators/validatePanCard.js +0 -23
  100. package/Validators/validatePassword.js +0 -38
  101. package/Validators/validateRTO.js +0 -41
  102. package/Validators/validateString.js +0 -41
  103. package/index.js +0 -194
@@ -0,0 +1,11 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Validates name fields with two sub-types:
4
+ * - 'user' (default) — letters, spaces, apostrophes, hyphens, dots
5
+ * - 'corporate' — letters, digits, common business punctuation
6
+ *
7
+ * Set rules.type to select the sub-type.
8
+ */
9
+ declare const validateName: (value: string, rules: ValidationRules | undefined, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
10
+ export default validateName;
11
+ //# sourceMappingURL=validateName.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateName.d.ts","sourceRoot":"","sources":["../../src/validators/validateName.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAK1F;;;;;;GAMG;AACH,QAAA,MAAM,YAAY,GAChB,OAAO,MAAM,EACb,OAAO,eAAe,YAAmB,EACzC,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAyCF,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const safeRegex_1 = require("../utils/safeRegex");
4
+ const USER_NAME_REGEX = /^(?=.*[a-zA-ZÀ-ÿ])[a-zA-ZÀ-ÿ\s'\-.]*$/;
5
+ const CORPORATE_NAME_REGEX = /^(?=.*[A-Za-z0-9])[A-Za-z0-9&.,'"()\- ]*$/;
6
+ /**
7
+ * Validates name fields with two sub-types:
8
+ * - 'user' (default) — letters, spaces, apostrophes, hyphens, dots
9
+ * - 'corporate' — letters, digits, common business punctuation
10
+ *
11
+ * Set rules.type to select the sub-type.
12
+ */
13
+ const validateName = (value, rules = { type: 'user' }, defaultErrorMessages, type) => {
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
15
+ if (!value || !value.trim()) {
16
+ return {
17
+ isValid: false,
18
+ error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.empty) !== null && _b !== void 0 ? _b : 'Name cannot be empty',
19
+ };
20
+ }
21
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
22
+ return {
23
+ isValid: false,
24
+ error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.minLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).minLength,
25
+ };
26
+ }
27
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
28
+ return {
29
+ isValid: false,
30
+ error: (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.maxLength) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).maxLength,
31
+ };
32
+ }
33
+ if (rules.type === 'corporate') {
34
+ const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : CORPORATE_NAME_REGEX;
35
+ if (!regexToUse.test(value)) {
36
+ return {
37
+ isValid: false,
38
+ error: (_h = (_g = rules.errorMessages) === null || _g === void 0 ? void 0 : _g.invalid) !== null && _h !== void 0 ? _h : 'Corporate name contains invalid characters',
39
+ };
40
+ }
41
+ }
42
+ else {
43
+ const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : USER_NAME_REGEX;
44
+ if (!regexToUse.test(value)) {
45
+ return {
46
+ isValid: false,
47
+ error: (_k = (_j = rules.errorMessages) === null || _j === void 0 ? void 0 : _j.invalid) !== null && _k !== void 0 ? _k : 'Name contains invalid characters',
48
+ };
49
+ }
50
+ }
51
+ return { isValid: true, error: '' };
52
+ };
53
+ exports.default = validateName;
@@ -0,0 +1,8 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Validates whole (integer) numbers.
4
+ * Supports minLength / maxLength (string length) and minValue / maxValue (numeric range).
5
+ */
6
+ declare const validateNumber: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
7
+ export default validateNumber;
8
+ //# sourceMappingURL=validateNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateNumber.d.ts","sourceRoot":"","sources":["../../src/validators/validateNumber.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;GAGG;AACH,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBA8DF,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const safeRegex_1 = require("../utils/safeRegex");
4
+ /**
5
+ * Validates whole (integer) numbers.
6
+ * Supports minLength / maxLength (string length) and minValue / maxValue (numeric range).
7
+ */
8
+ const validateNumber = (value, rules, defaultErrorMessages, type) => {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
10
+ if (/\s/.test(value)) {
11
+ return {
12
+ isValid: false,
13
+ 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,
14
+ };
15
+ }
16
+ const defaultNumberRegex = /^\d+$/;
17
+ const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultNumberRegex;
18
+ if (!regexToUse.test(value)) {
19
+ return {
20
+ isValid: false,
21
+ 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 whole number',
22
+ };
23
+ }
24
+ const numberValue = Number(value);
25
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
26
+ return {
27
+ isValid: false,
28
+ error: (_k = (_j = rules.errorMessages) === null || _j === void 0 ? void 0 : _j.minLength) !== null && _k !== void 0 ? _k : defaultErrorMessages(rules, type).minLength,
29
+ };
30
+ }
31
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
32
+ return {
33
+ isValid: false,
34
+ error: (_m = (_l = rules.errorMessages) === null || _l === void 0 ? void 0 : _l.maxLength) !== null && _m !== void 0 ? _m : defaultErrorMessages(rules, type).maxLength,
35
+ };
36
+ }
37
+ if (rules.minValue !== undefined && numberValue < rules.minValue) {
38
+ return {
39
+ isValid: false,
40
+ error: (_q = (_p = (_o = rules.errorMessages) === null || _o === void 0 ? void 0 : _o.minValue) !== null && _p !== void 0 ? _p : defaultErrorMessages(rules, type).minValue) !== null && _q !== void 0 ? _q : `Value must be at least ${rules.minValue}`,
41
+ };
42
+ }
43
+ if (rules.maxValue !== undefined && numberValue > rules.maxValue) {
44
+ return {
45
+ isValid: false,
46
+ error: (_t = (_s = (_r = rules.errorMessages) === null || _r === void 0 ? void 0 : _r.maxValue) !== null && _s !== void 0 ? _s : defaultErrorMessages(rules, type).maxValue) !== null && _t !== void 0 ? _t : `Value must not exceed ${rules.maxValue}`,
47
+ };
48
+ }
49
+ return { isValid: true, error: '' };
50
+ };
51
+ exports.default = validateNumber;
@@ -0,0 +1,8 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Validates Indian PAN card numbers.
4
+ * Format: 5 uppercase letters + 4 digits + 1 uppercase letter (total 10 chars).
5
+ */
6
+ declare const validatePanCard: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
7
+ export default validatePanCard;
8
+ //# sourceMappingURL=validatePanCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatePanCard.d.ts","sourceRoot":"","sources":["../../src/validators/validatePanCard.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 PAN card numbers.
6
+ * Format: 5 uppercase letters + 4 digits + 1 uppercase letter (total 10 chars).
7
+ */
8
+ const validatePanCard = (value, rules, defaultErrorMessages, type) => {
9
+ var _a, _b, _c, _d;
10
+ const defaultRegex = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/;
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 = validatePanCard;
@@ -0,0 +1,4 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ declare const validatePassword: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
3
+ export default validatePassword;
4
+ //# sourceMappingURL=validatePassword.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatePassword.d.ts","sourceRoot":"","sources":["../../src/validators/validatePassword.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAuB1F,QAAA,MAAM,gBAAgB,GACpB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBA8BF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const safeRegex_1 = require("../utils/safeRegex");
4
+ /**
5
+ * Password strength profiles:
6
+ * 'basic' — at least one letter AND one digit (default, backward-compatible)
7
+ * 'medium' — uppercase + lowercase + digit; min 8 chars recommended
8
+ * 'strong' — uppercase + lowercase + digit + special character; min 12 chars recommended
9
+ *
10
+ * A custom regex via rules.regex overrides the strength profile entirely.
11
+ */
12
+ const STRENGTH_PATTERNS = {
13
+ basic: /^(?=.*[A-Za-z])(?=.*\d).+$/,
14
+ medium: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/,
15
+ strong: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?`~]).+$/,
16
+ };
17
+ const STRENGTH_MESSAGES = {
18
+ basic: 'Password must contain at least one letter and one number',
19
+ medium: 'Password must contain uppercase, lowercase, and a number',
20
+ strong: 'Password must contain uppercase, lowercase, a number, and a special character',
21
+ };
22
+ const validatePassword = (value, rules, defaultErrorMessages, type) => {
23
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
24
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
25
+ return {
26
+ isValid: false,
27
+ error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
28
+ };
29
+ }
30
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
31
+ return {
32
+ isValid: false,
33
+ error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
34
+ };
35
+ }
36
+ const strength = (_e = rules.strength) !== null && _e !== void 0 ? _e : 'basic';
37
+ const defaultRegex = (_f = STRENGTH_PATTERNS[strength]) !== null && _f !== void 0 ? _f : STRENGTH_PATTERNS['basic'];
38
+ const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
39
+ if (!regexToUse.test(value)) {
40
+ return {
41
+ isValid: false,
42
+ error: (_j = (_h = (_g = rules.errorMessages) === null || _g === void 0 ? void 0 : _g.invalid) !== null && _h !== void 0 ? _h : STRENGTH_MESSAGES[strength]) !== null && _j !== void 0 ? _j : 'Password does not meet the required criteria',
43
+ };
44
+ }
45
+ return { isValid: true, error: '' };
46
+ };
47
+ exports.default = validatePassword;
@@ -0,0 +1,8 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Validates Indian postal PIN codes.
4
+ * Format: 6 digits, first digit 1–9 (no leading zero).
5
+ */
6
+ declare const validatePincode: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
7
+ export default validatePincode;
8
+ //# sourceMappingURL=validatePincode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validatePincode.d.ts","sourceRoot":"","sources":["../../src/validators/validatePincode.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 postal PIN codes.
6
+ * Format: 6 digits, first digit 1–9 (no leading zero).
7
+ */
8
+ const validatePincode = (value, rules, defaultErrorMessages, type) => {
9
+ var _a, _b, _c;
10
+ const defaultRegex = /^[1-9][0-9]{5}$/;
11
+ const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
12
+ if (!regexToUse.test(value)) {
13
+ return {
14
+ isValid: false,
15
+ error: (_c = (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.invalid) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).pincode) !== null && _c !== void 0 ? _c : defaultErrorMessages(rules, type).invalid,
16
+ };
17
+ }
18
+ return { isValid: true, error: '' };
19
+ };
20
+ exports.default = validatePincode;
@@ -0,0 +1,12 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Validates Indian RTO (Regional Transport Office) codes.
4
+ *
5
+ * rules.version controls the accepted format:
6
+ * undefined / 'old' — "AA-00" (state + district only)
7
+ * 'new' — "AA-00" or "AA-00-AA" (with optional series letters)
8
+ * 'all' — flexible separators
9
+ */
10
+ declare const validateRTO: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
11
+ export default validateRTO;
12
+ //# sourceMappingURL=validateRTO.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateRTO.d.ts","sourceRoot":"","sources":["../../src/validators/validateRTO.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;;;;;GAOG;AACH,QAAA,MAAM,WAAW,GACf,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAqCF,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const safeRegex_1 = require("../utils/safeRegex");
4
+ /**
5
+ * Validates Indian RTO (Regional Transport Office) codes.
6
+ *
7
+ * rules.version controls the accepted format:
8
+ * undefined / 'old' — "AA-00" (state + district only)
9
+ * 'new' — "AA-00" or "AA-00-AA" (with optional series letters)
10
+ * 'all' — flexible separators
11
+ */
12
+ const validateRTO = (value, rules, defaultErrorMessages, type) => {
13
+ var _a, _b, _c, _d, _e, _f, _g;
14
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
15
+ return {
16
+ isValid: false,
17
+ error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.minLength) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).minLength,
18
+ };
19
+ }
20
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
21
+ return {
22
+ isValid: false,
23
+ error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.maxLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).maxLength,
24
+ };
25
+ }
26
+ let defaultRegex;
27
+ if (rules.version === 'new') {
28
+ defaultRegex = /^[A-Z]{2}-[0-9]{1,2}(-[A-Z]{1,2})?$/;
29
+ }
30
+ else if (rules.version === 'all') {
31
+ defaultRegex = /^[A-Z]{2}-?[0-9]{1,2}(-?[A-Z]{1,2})?$/;
32
+ }
33
+ else {
34
+ defaultRegex = /^[A-Z]{2}-[0-9]{1,2}$/;
35
+ }
36
+ const regexToUse = rules.regex ? (0, safeRegex_1.buildRegex)(rules.regex) : defaultRegex;
37
+ if (!regexToUse.test(value)) {
38
+ return {
39
+ isValid: false,
40
+ error: (_g = (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.invalid) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).rto) !== null && _g !== void 0 ? _g : defaultErrorMessages(rules, type).invalid,
41
+ };
42
+ }
43
+ return { isValid: true, error: '' };
44
+ };
45
+ exports.default = validateRTO;
@@ -0,0 +1,8 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Generic string validator.
4
+ * Accepts minLength, maxLength, and an optional custom regex override.
5
+ */
6
+ declare const validateString: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
7
+ export default validateString;
8
+ //# sourceMappingURL=validateString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateString.d.ts","sourceRoot":"","sources":["../../src/validators/validateString.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAE1F;;;GAGG;AACH,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,EACb,OAAO,eAAe,EACtB,sBAAsB,sBAAsB,EAC5C,MAAM,MAAM,KACX,gBAiCF,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const safeRegex_1 = require("../utils/safeRegex");
4
+ /**
5
+ * Generic string validator.
6
+ * Accepts minLength, maxLength, and an optional custom regex override.
7
+ */
8
+ const validateString = (value, rules, defaultErrorMessages, type) => {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10
+ if (typeof value !== 'string') {
11
+ return {
12
+ isValid: false,
13
+ error: (_b = (_a = rules.errorMessages) === null || _a === void 0 ? void 0 : _a.invalid) !== null && _b !== void 0 ? _b : defaultErrorMessages(rules, type).invalid,
14
+ };
15
+ }
16
+ if (rules.minLength !== undefined && value.length < rules.minLength) {
17
+ return {
18
+ isValid: false,
19
+ error: (_d = (_c = rules.errorMessages) === null || _c === void 0 ? void 0 : _c.minLength) !== null && _d !== void 0 ? _d : defaultErrorMessages(rules, type).minLength,
20
+ };
21
+ }
22
+ if (rules.maxLength !== undefined && value.length > rules.maxLength) {
23
+ return {
24
+ isValid: false,
25
+ error: (_f = (_e = rules.errorMessages) === null || _e === void 0 ? void 0 : _e.maxLength) !== null && _f !== void 0 ? _f : defaultErrorMessages(rules, type).maxLength,
26
+ };
27
+ }
28
+ if (rules.regex) {
29
+ const regexToUse = (0, safeRegex_1.buildRegex)(rules.regex);
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
+ }
37
+ return { isValid: true, error: '' };
38
+ };
39
+ exports.default = validateString;
@@ -0,0 +1,9 @@
1
+ import type { ValidationResult, ValidationRules, DefaultErrorMessagesFn } from '../types';
2
+ /**
3
+ * Validates URLs using the WHATWG URL parser (Node.js built-in).
4
+ * Default: allows http and https schemes with valid domain or IP, optional path/query/fragment.
5
+ * Provide rules.regex to accept other schemes (ftp, custom, etc.).
6
+ */
7
+ declare const validateURL: (value: string, rules: ValidationRules, defaultErrorMessages: DefaultErrorMessagesFn, type: string) => ValidationResult;
8
+ export default validateURL;
9
+ //# sourceMappingURL=validateURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateURL.d.ts","sourceRoot":"","sources":["../../src/validators/validateURL.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,gBA8CF,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const safeRegex_1 = require("../utils/safeRegex");
4
+ /**
5
+ * Validates URLs using the WHATWG URL parser (Node.js built-in).
6
+ * Default: allows http and https schemes with valid domain or IP, optional path/query/fragment.
7
+ * Provide rules.regex to accept other schemes (ftp, custom, etc.).
8
+ */
9
+ const validateURL = (value, rules, defaultErrorMessages, type) => {
10
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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
+ if (rules.regex) {
24
+ const customRegex = (0, safeRegex_1.buildRegex)(rules.regex);
25
+ if (!customRegex.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
+ let parsed;
34
+ try {
35
+ parsed = new (require('url').URL)(value);
36
+ }
37
+ catch {
38
+ return {
39
+ isValid: false,
40
+ error: (_h = (_g = rules.errorMessages) === null || _g === void 0 ? void 0 : _g.invalid) !== null && _h !== void 0 ? _h : defaultErrorMessages(rules, type).url,
41
+ };
42
+ }
43
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
44
+ return {
45
+ isValid: false,
46
+ error: (_k = (_j = rules.errorMessages) === null || _j === void 0 ? void 0 : _j.invalid) !== null && _k !== void 0 ? _k : defaultErrorMessages(rules, type).url,
47
+ };
48
+ }
49
+ return { isValid: true, error: '' };
50
+ };
51
+ exports.default = validateURL;
package/package.json CHANGED
@@ -1,22 +1,63 @@
1
1
  {
2
2
  "name": "quantique-field-validator",
3
- "version": "1.0.9",
4
- "description": "Validator to verify all form fields.",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
3
+ "version": "2.0.1",
4
+ "description": "Enterprise-grade dynamic field validator for Indian and international form fields.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
8
12
  },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/saketsinhaquantique/quantique-field-validator.git"
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc --build",
21
+ "typecheck": "tsc --noEmit",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "test:coverage": "vitest run --coverage",
25
+ "lint": "eslint src tests --ext .ts",
26
+ "lint:fix": "eslint src tests --ext .ts --fix",
27
+ "format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\""
12
28
  },
13
29
  "keywords": [
30
+ "validator",
31
+ "form-validation",
32
+ "aadhaar",
33
+ "pan",
34
+ "gst",
35
+ "ifsc",
36
+ "india",
37
+ "field-validator",
14
38
  "QFV"
15
39
  ],
16
40
  "author": "Saket Brij Sinha <saket.sinha@quantique.ai>",
17
41
  "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/saketsinhaquantique/quantique-field-validator.git"
45
+ },
18
46
  "bugs": {
19
47
  "url": "https://github.com/saketsinhaquantique/quantique-field-validator/issues"
20
48
  },
21
- "homepage": "https://github.com/saketsinhaquantique/quantique-field-validator#readme"
49
+ "homepage": "https://github.com/saketsinhaquantique/quantique-field-validator#readme",
50
+ "engines": {
51
+ "node": ">=18.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^25.0.0",
55
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
56
+ "@typescript-eslint/parser": "^8.0.0",
57
+ "eslint": "^9.0.0",
58
+ "eslint-config-prettier": "^10.0.0",
59
+ "prettier": "^3.0.0",
60
+ "typescript": "^5.9.0",
61
+ "vitest": "^3.0.0"
62
+ }
22
63
  }
@@ -1,31 +0,0 @@
1
- name: Publish Package to npm
2
-
3
- # This tells GitHub to run this script whenever you publish a new Release on GitHub
4
- on:
5
- release:
6
- types: [published]
7
-
8
- jobs:
9
- publish-npm:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - name: Checkout code
13
- uses: actions/checkout@v4
14
-
15
- # Setup Node.js (I set this to v24 to match the version in your error logs)
16
- - name: Setup Node.js
17
- uses: actions/setup-node@v4
18
- with:
19
- node-version: '24.x'
20
- registry-url: 'https://registry.npmjs.org'
21
-
22
- # Install dependencies cleanly
23
- - name: Install dependencies
24
- run: npm ci
25
-
26
- # Publish the package
27
- - name: Publish to npm
28
- run: npm publish --tag beta
29
- env:
30
- # This pulls the token we saved in Step 2 securely
31
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,27 +0,0 @@
1
- // Default error messages
2
- const defaultErrorMessages = (rules, type) => {
3
- return {
4
- noSpace: "Value should not contain spaces",
5
- minAge: `User must be ${rules.minAge} years or older`,
6
- minMinus: "Date is too far in the past",
7
- maxPlus: "Date is too far in the future",
8
- required: "This field is required",
9
- minLength: `Minimum length should be ${rules.minLength}`,
10
- maxLength: `Maximum length should be ${rules.maxLength}`,
11
- invalid: `Please entere a valid ${type}`,
12
- noValidation: `No validation exist for ${type}`,
13
- custom: "Validation failed",
14
- Alphanumeric: "value must be alphanumeric",
15
- chassisNumber: "Invalid chassis number",
16
- engineNumber: "Invalid engine number",
17
- ipAddress: "Invalid IP Address",
18
- name: "Invalid name",
19
- rto: "Invalid RTO",
20
- ifsc: "Invalid Bank IFSC Code",
21
- customValidation:
22
- rules.errorMessages?.customValidation || "Custom validation failed",
23
- emoji: "Emoji characters are not allowed",
24
- };
25
- };
26
-
27
- module.exports = defaultErrorMessages;
@@ -1,37 +0,0 @@
1
- // ChassisNumber validation
2
- const validateChassisNumber = (value, rules, defaultErrorMessages, type) => {
3
- if (rules?.minLength && value?.length < rules?.minLength) {
4
- return {
5
- isValid: false,
6
- error:
7
- rules?.errorMessages?.minLength ||
8
- defaultErrorMessages(rules, type).minLength,
9
- };
10
- }
11
-
12
- if (rules?.maxLength && value?.length > rules?.maxLength) {
13
- return {
14
- isValid: false,
15
- error:
16
- rules?.errorMessages?.maxLength ||
17
- defaultErrorMessages(rules, type).maxLength,
18
- };
19
- }
20
-
21
- const defaultRegex = /^(?=.*[A-HJ-NPR-Z])[A-HJ-NPR-Z0-9]{17}$/;
22
- const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
23
- console.log(regexToUse);
24
- if (!regexToUse.test(value)) {
25
- return {
26
- isValid: false,
27
- error: rules?.errorMessages?.invalid
28
- ? rules?.errorMessages?.invalid
29
- : defaultErrorMessages(rules, type).chassisNumber ||
30
- defaultErrorMessages(rules, type).invalid,
31
- };
32
- }
33
-
34
- return { isValid: true, error: "" };
35
- };
36
-
37
- module.exports = validateChassisNumber;
@@ -1,18 +0,0 @@
1
- const validateAadhaar = (value, rules, defaultErrorMessages, type) => {
2
- const defaultRegex = /^[2-9]{1}[0-9]{11}$/;
3
- const regexToUse = rules?.regex ? new RegExp(rules.regex) : defaultRegex;
4
-
5
- if (!regexToUse.test(value)) {
6
- return {
7
- isValid: false,
8
- error:
9
- rules?.errorMessages?.regex ||
10
- rules?.errorMessages?.invalid ||
11
- defaultErrorMessages(rules, type).invalid,
12
- };
13
- }
14
-
15
- return { isValid: true, error: "" };
16
- };
17
-
18
- module.exports = validateAadhaar;