ingeni-validation 1.2.2 → 1.2.3
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/ingeni-validation.js +62 -53
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -108,7 +108,7 @@ async function isNullValue(...params) {
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
//Validating Boolean Value required
|
|
112
112
|
async function isValidBoolean(value){
|
|
113
113
|
if(typeof value==="boolean"){
|
|
114
114
|
return true;
|
|
@@ -116,6 +116,7 @@ async function isNullValue(...params) {
|
|
|
116
116
|
return false;
|
|
117
117
|
|
|
118
118
|
}
|
|
119
|
+
|
|
119
120
|
|
|
120
121
|
//Check Boolean Parameters
|
|
121
122
|
async function checkBooleanParams(...params) {
|
|
@@ -209,6 +210,7 @@ async function isValidOtp(otp, otplength) {
|
|
|
209
210
|
|
|
210
211
|
//Valid Number or with length
|
|
211
212
|
|
|
213
|
+
|
|
212
214
|
async function isValidNumber(num, numlength = null) {
|
|
213
215
|
|
|
214
216
|
if (num === null || num === undefined || typeof num === "boolean") {
|
|
@@ -217,29 +219,22 @@ async function isValidNumber(num, numlength = null) {
|
|
|
217
219
|
|
|
218
220
|
const numStr = String(num).trim();
|
|
219
221
|
|
|
220
|
-
if (numStr === "")
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
222
|
+
if (numStr === "") return false;
|
|
223
223
|
|
|
224
|
-
//
|
|
225
|
-
if (!/^\d+$/.test(numStr))
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
224
|
+
// Only digits allowed
|
|
225
|
+
if (!/^\d+$/.test(numStr)) return false;
|
|
228
226
|
|
|
229
|
-
//
|
|
227
|
+
// Length validation (if provided)
|
|
230
228
|
if (numlength !== null) {
|
|
231
|
-
if (!Number.isInteger(numlength) || numlength <= 0)
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
229
|
+
if (!Number.isInteger(numlength) || numlength <= 0) return false;
|
|
234
230
|
|
|
235
|
-
if (numStr.length !== numlength)
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
231
|
+
if (numStr.length !== numlength) return false;
|
|
238
232
|
}
|
|
239
233
|
|
|
240
234
|
return true;
|
|
241
235
|
}
|
|
242
236
|
|
|
237
|
+
|
|
243
238
|
//Pincode validation
|
|
244
239
|
|
|
245
240
|
async function isValidPin(pinCode) {
|
|
@@ -326,15 +321,25 @@ async function isValidDate(value, format) {
|
|
|
326
321
|
|
|
327
322
|
//Validate Price
|
|
328
323
|
|
|
329
|
-
async function isValidPrice(price){
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
if (typeof price === "string" && price.trim().length === 0) return false;
|
|
333
|
-
if (isNaN(price)) return false;
|
|
334
|
-
if (Number(price) <= 0) return false;
|
|
335
|
-
return true;
|
|
336
|
-
}
|
|
324
|
+
async function isValidPrice(price) {
|
|
325
|
+
if (price === null || price === undefined) return false;
|
|
326
|
+
if (typeof price === "boolean") return false;
|
|
337
327
|
|
|
328
|
+
const str = String(price).trim();
|
|
329
|
+
|
|
330
|
+
// Reject empty string
|
|
331
|
+
if (str === "") return false;
|
|
332
|
+
|
|
333
|
+
// Reject non-numeric strings like "fdsjfkjs"
|
|
334
|
+
if (!/^\d+(\.\d+)?$/.test(str)) return false;
|
|
335
|
+
|
|
336
|
+
const num = Number(str);
|
|
337
|
+
|
|
338
|
+
// Reject zero or negative
|
|
339
|
+
if (num <= 0) return false;
|
|
340
|
+
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
338
343
|
|
|
339
344
|
|
|
340
345
|
//Validate Gender
|
|
@@ -349,6 +354,40 @@ async function isValidDate(value, format) {
|
|
|
349
354
|
return ["m", "f", "male", "female", "other"].includes(val);
|
|
350
355
|
}
|
|
351
356
|
|
|
357
|
+
|
|
358
|
+
//allow this format only ("20.2849144,85.8078186")
|
|
359
|
+
|
|
360
|
+
async function isValidCoordinates(location) {
|
|
361
|
+
|
|
362
|
+
if (location === null || location === undefined) return false;
|
|
363
|
+
|
|
364
|
+
if (typeof location === "boolean") return false;
|
|
365
|
+
|
|
366
|
+
if (typeof location !== "string") return false;
|
|
367
|
+
|
|
368
|
+
if (location.length === 0) return false;
|
|
369
|
+
|
|
370
|
+
if (location.includes(" ")) return false;
|
|
371
|
+
|
|
372
|
+
const regex = /^-?\d{1,2}(\.\d+)?,-?\d{1,3}(\.\d+)?$/;
|
|
373
|
+
if (!regex.test(location)) return false;
|
|
374
|
+
|
|
375
|
+
const [latStr, lngStr] = location.split(",");
|
|
376
|
+
|
|
377
|
+
const lat = Number(latStr);
|
|
378
|
+
const lng = Number(lngStr);
|
|
379
|
+
|
|
380
|
+
// Extra safety
|
|
381
|
+
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return false;
|
|
382
|
+
|
|
383
|
+
if (lat < -90 || lat > 90) return false;
|
|
384
|
+
if (lng < -180 || lng > 180) return false;
|
|
385
|
+
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
352
391
|
|
|
353
392
|
//Stop details Validation "stop_details":[{"30":["Baripada","13:00","13:01","21.9319,86.7465"]}]
|
|
354
393
|
|
|
@@ -469,36 +508,6 @@ async function isValidStopDetails(stop_details){
|
|
|
469
508
|
|
|
470
509
|
|
|
471
510
|
|
|
472
|
-
//allow this format only ("20.2849144,85.8078186")
|
|
473
|
-
|
|
474
|
-
async function isValidCoordinates(location) {
|
|
475
|
-
|
|
476
|
-
if (location === null || location === undefined) return false;
|
|
477
|
-
|
|
478
|
-
if (typeof location === "boolean") return false;
|
|
479
|
-
|
|
480
|
-
if (typeof location !== "string") return false;
|
|
481
|
-
|
|
482
|
-
if (location.length === 0) return false;
|
|
483
|
-
|
|
484
|
-
if (location.includes(" ")) return false;
|
|
485
|
-
|
|
486
|
-
const regex = /^-?\d{1,2}(\.\d+)?,-?\d{1,3}(\.\d+)?$/;
|
|
487
|
-
if (!regex.test(location)) return false;
|
|
488
|
-
|
|
489
|
-
const [latStr, lngStr] = location.split(",");
|
|
490
|
-
|
|
491
|
-
const lat = Number(latStr);
|
|
492
|
-
const lng = Number(lngStr);
|
|
493
|
-
|
|
494
|
-
// Extra safety
|
|
495
|
-
if (!Number.isFinite(lat) || !Number.isFinite(lng)) return false;
|
|
496
|
-
|
|
497
|
-
if (lat < -90 || lat > 90) return false;
|
|
498
|
-
if (lng < -180 || lng > 180) return false;
|
|
499
|
-
|
|
500
|
-
return true;
|
|
501
|
-
}
|
|
502
511
|
|
|
503
512
|
|
|
504
513
|
|