ingeni-validation 1.1.14 → 1.1.16
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 +77 -1
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -82,6 +82,30 @@ async function validateOptional(req, res, optionalFields) {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
//Check Null value (Not Allow null or "null"
|
|
86
|
+
async function isNullValue(...params) {
|
|
87
|
+
for (let param of params) {
|
|
88
|
+
|
|
89
|
+
if (param == null) return true;
|
|
90
|
+
|
|
91
|
+
if (typeof param === "string") {
|
|
92
|
+
const val = param.trim().toLowerCase();
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
val === "" ||
|
|
96
|
+
val === "null" ||
|
|
97
|
+
val === "undefined"
|
|
98
|
+
) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
85
109
|
|
|
86
110
|
//valid boolean
|
|
87
111
|
async function isValidBoolean(value){
|
|
@@ -460,5 +484,57 @@ async function isValidCoordinates(location) {
|
|
|
460
484
|
|
|
461
485
|
|
|
462
486
|
|
|
487
|
+
//Stop time edit json format - [{"stop_id":"2","stop_name":"Stop_D","arrival_time":"08:15","departure_time":"08:16"}]
|
|
488
|
+
|
|
489
|
+
async function isValidStopTime(data) {
|
|
490
|
+
|
|
491
|
+
if (!Array.isArray(data) || data.length === 0) return false;
|
|
492
|
+
|
|
493
|
+
const seenIds = new Set();
|
|
494
|
+
|
|
495
|
+
const timeRegex = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
496
|
+
|
|
497
|
+
const toMinutes = (t) => {
|
|
498
|
+
const parts = t.split(":");
|
|
499
|
+
if (parts.length !== 2) return NaN;
|
|
500
|
+
const [h, m] = parts.map(Number);
|
|
501
|
+
return h * 60 + m;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
for (let item of data) {
|
|
505
|
+
|
|
506
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) return false;
|
|
507
|
+
|
|
508
|
+
let { stop_id, stop_name, arrival_time, departure_time } = item;
|
|
509
|
+
|
|
510
|
+
// stop_id validation
|
|
511
|
+
if (stop_id === undefined || stop_id === null) return false;
|
|
512
|
+
if (typeof stop_id === "boolean") return false;
|
|
513
|
+
|
|
514
|
+
const idStr = String(stop_id).trim();
|
|
515
|
+
|
|
516
|
+
if (!/^\d+$/.test(idStr)) return false;
|
|
517
|
+
|
|
518
|
+
if (seenIds.has(idStr)) return false;
|
|
519
|
+
seenIds.add(idStr);
|
|
520
|
+
|
|
521
|
+
// stop_name
|
|
522
|
+
if (typeof stop_name !== "string" || stop_name.trim().length === 0) return false;
|
|
523
|
+
|
|
524
|
+
// time fields
|
|
525
|
+
if (arrival_time === undefined || departure_time === undefined) return false;
|
|
526
|
+
|
|
527
|
+
const arrTime = String(arrival_time).trim();
|
|
528
|
+
const depTime = String(departure_time).trim();
|
|
529
|
+
|
|
530
|
+
if (!timeRegex.test(arrTime)) return false;
|
|
531
|
+
if (!timeRegex.test(depTime)) return false;
|
|
532
|
+
|
|
533
|
+
if (toMinutes(arrTime) > toMinutes(depTime)) return false;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
|
|
463
539
|
|
|
464
|
-
export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice,isValidStopDetails,isValidCoordinates};
|
|
540
|
+
export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice,isValidStopDetails,isValidStopTime,isValidCoordinates};
|