ingeni-validation 1.0.4 → 1.0.8

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.
@@ -4,15 +4,16 @@ async function validateMandate(req, res, requiredFields) {
4
4
  try {
5
5
  // const missingFields = requiredFields.filter(field => !req.body[field]);
6
6
 
7
- const nameRegex = /^[A-Za-z .-]+$/;
8
- const missingFields = requiredFields.filter(
7
+ // const nameRegex = /^[A-Za-z .-]+$/;
8
+
9
+ const missingFields = requiredFields.filter(
9
10
  field => req.body[field] === undefined ||
10
11
  req.body[field] === null ||
11
12
  req.body[field] === '' ||
12
13
  req.body[field] === 'undefined' ||
13
- (typeof req.body[field] === "string" && req.body[field].trim() === "")
14
+ (typeof req.body[field] === "string" && req.body[field].trim() === "") ||
15
+ (typeof req.body[field] === "boolean")
14
16
  );
15
-
16
17
 
17
18
 
18
19
  if (missingFields.length > 0) {
@@ -71,6 +72,15 @@ const optionMissingFields = optionalFields.filter(
71
72
  };
72
73
 
73
74
 
75
+ async function isValidBoolean(value){
76
+ if(typeof value==="boolean"){
77
+ return true;
78
+ }
79
+ return false;
80
+
81
+ }
82
+
83
+
74
84
  async function isValidMobile(mobile) {
75
85
 
76
86
  const mobileStr = String(mobile).trim();
@@ -87,17 +97,27 @@ async function isValidEmail(email) {
87
97
  }
88
98
 
89
99
 
90
- async function isValidOtp(otp) {
91
- if (otp === undefined || otp === null) return false;
92
100
 
93
- const otpStr = String(otp).trim();
94
101
 
95
- if (otpStr.length !== 6) return false;
96
102
 
97
- return /^[0-9]{6}$/.test(otpStr);
103
+ async function isValidOtp(otp, otplength) {
104
+ if (otp === undefined || otp === null) return false;
105
+
106
+ if (!Number.isInteger(otplength) || otplength <= 0) return false;
107
+ //console.log("OTPSTR:", otpStr, otpStr.length);
108
+ const otpStr = String(otp).trim();
109
+
110
+ return new RegExp(`^[0-9]{${otplength}}$`).test(otpStr);
111
+ }
112
+
113
+ async function isValidNumber(num, numlength) {
114
+ if (num === undefined || num === null) return false;
115
+
116
+ if (!Number.isInteger(numlength) || numlength <= 0) return false;
117
+
118
+ const numStr = String(num).trim();
119
+ return new RegExp(`^[0-9]{${numlength}}$`).test(numStr);
98
120
  }
99
-
100
-
101
121
 
102
122
  async function isValidPin(pinCode) {
103
123
  if (pinCode === undefined || pinCode === null) return false;
@@ -111,7 +131,4 @@ async function isValidPin(pinCode) {
111
131
  return /^[0-9]{6}$/.test(pinCodeStr);
112
132
  }
113
133
 
114
-
115
-
116
-
117
- export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin };
134
+ export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin,isValidNumber,isValidBoolean};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeni-validation",
3
- "version": "1.0.4",
3
+ "version": "1.0.8",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",