ingeni-validation 1.1.0 → 1.1.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.
@@ -1,5 +1,5 @@
1
1
 
2
-
2
+ //Mandatory Field Validation
3
3
  async function validateMandate(req, res, requiredFields) {
4
4
  try {
5
5
  // const missingFields = requiredFields.filter(field => !req.body[field]);
@@ -42,6 +42,7 @@ async function validateMandate(req, res, requiredFields) {
42
42
  }
43
43
  };
44
44
 
45
+ //Optional Field validation
45
46
  async function validateOptional(req, res, optionalFields) {
46
47
  try {
47
48
  // const missingFields = requiredFields.filter(field => !req.body[field]);
@@ -71,7 +72,7 @@ const optionMissingFields = optionalFields.filter(
71
72
  }
72
73
  };
73
74
 
74
-
75
+ //valid boolean
75
76
  async function isValidBoolean(value){
76
77
  if(typeof value==="boolean"){
77
78
  return true;
@@ -91,69 +92,102 @@ async function checkBooleanParams(...params) {
91
92
  }
92
93
 
93
94
 
94
- //Mobile No. Validation
95
+ // Mobile No. Validation
95
96
  async function isValidMobile(mobile) {
96
-
97
- if (typeof mobile === "boolean" || mobile===null || mobile===undefined) {
97
+
98
+ if (mobile === null || mobile === undefined || typeof mobile === "boolean") {
98
99
  return false;
99
100
  }
100
-
101
+
101
102
  const mobileStr = String(mobile).trim();
102
-
103
- return /^[0-9]{10}$/.test(mobileStr);
104
- }
105
103
 
104
+ if (mobileStr === "") {
105
+ return false;
106
+ }
106
107
 
108
+ return /^[6-9]\d{9}$/.test(mobileStr);
109
+ }
110
+
111
+ // Email Validation
107
112
  async function isValidEmail(email) {
108
- if (typeof email === "boolean" || email===null || email===undefined) {
109
- return false;
110
- }
113
+
114
+ if (email === null || email === undefined || typeof email === "boolean") {
115
+ return false;
116
+ }
111
117
 
112
118
  const emailStr = String(email).trim();
119
+
120
+ if (emailStr === "") {
121
+ return false;
122
+ }
123
+
113
124
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
114
125
 
115
126
  return emailRegex.test(emailStr);
116
127
  }
117
128
 
118
129
 
130
+ //OTP Validation
131
+
132
+ async function isValidOtp(otp, otplength) {
119
133
 
134
+ if (otp === null || otp === undefined || typeof otp === "boolean") {
135
+ return false;
136
+ }
120
137
 
138
+ if (!Number.isInteger(otplength) || otplength <= 0) {
139
+ return false;
140
+ }
121
141
 
122
- async function isValidOtp(otp, otplength) {
123
- if (typeof otp === "boolean" || otp===null || otp===undefined) {
124
- return false;
125
- }
126
-
127
- if (!Number.isInteger(otplength) || otplength <= 0) return false;
128
- //console.log("OTPSTR:", otpStr, otpStr.length);
129
142
  const otpStr = String(otp).trim();
130
-
143
+
144
+ if (otpStr === "") {
145
+ return false;
146
+ }
147
+
131
148
  return new RegExp(`^[0-9]{${otplength}}$`).test(otpStr);
132
149
  }
150
+
151
+ //Valid Number with length
133
152
 
134
153
  async function isValidNumber(num, numlength) {
135
154
 
136
- if (typeof num === "boolean" || num===null || num===undefined) {
137
- return false;
138
- }
139
-
140
- if (!Number.isInteger(numlength) || numlength <= 0) return false;
141
-
155
+ if (num === null || num === undefined || typeof num === "boolean") {
156
+ return false;
157
+ }
158
+
159
+ if (!Number.isInteger(numlength) || numlength <= 0) {
160
+ return false;
161
+ }
162
+
142
163
  const numStr = String(num).trim();
143
- return new RegExp(`^[0-9]{${numlength}}$`).test(numStr);
164
+
165
+ if (numStr === "") {
166
+ return false;
167
+ }
168
+
169
+ return new RegExp(`^\\d{${numlength}}$`).test(numStr);
144
170
  }
145
171
 
172
+
173
+ //Pincode validation
174
+
146
175
  async function isValidPin(pinCode) {
147
- if (typeof pinCode === "boolean" || pinCode===null || pinCode===undefined) {
148
- return false;
149
- }
150
- // convert safely to string
176
+
177
+ if (pinCode === null || pinCode === undefined || typeof pinCode === "boolean") {
178
+ return false;
179
+ }
180
+
151
181
  const pinCodeStr = String(pinCode).trim();
152
182
 
153
- // exactly 6 digits
154
- if (pinCodeStr.length !== 6) return false;
183
+ if (pinCodeStr === "") {
184
+ return false;
185
+ }
155
186
 
156
187
  return /^[0-9]{6}$/.test(pinCodeStr);
157
188
  }
158
189
 
190
+
191
+
192
+
159
193
  export {validateMandate,validateOptional, isValidMobile, isValidEmail, isValidOtp, isValidPin,isValidNumber,isValidBoolean,checkBooleanParams};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeni-validation",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",