ingeni-validation 1.1.14 → 1.1.15
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 +53 -1
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -460,5 +460,57 @@ async function isValidCoordinates(location) {
|
|
|
460
460
|
|
|
461
461
|
|
|
462
462
|
|
|
463
|
+
//Stop time edit json format - [{"stop_id":"2","stop_name":"Stop_D","arrival_time":"08:15","departure_time":"08:16"}]
|
|
463
464
|
|
|
464
|
-
|
|
465
|
+
async function isValidStopTime(data) {
|
|
466
|
+
|
|
467
|
+
if (!Array.isArray(data) || data.length === 0) return false;
|
|
468
|
+
|
|
469
|
+
const seenIds = new Set();
|
|
470
|
+
|
|
471
|
+
const timeRegex = /^([01]\d|2[0-3]):([0-5]\d)$/;
|
|
472
|
+
|
|
473
|
+
const toMinutes = (t) => {
|
|
474
|
+
const parts = t.split(":");
|
|
475
|
+
if (parts.length !== 2) return NaN;
|
|
476
|
+
const [h, m] = parts.map(Number);
|
|
477
|
+
return h * 60 + m;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
for (let item of data) {
|
|
481
|
+
|
|
482
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) return false;
|
|
483
|
+
|
|
484
|
+
let { stop_id, stop_name, arrival_time, departure_time } = item;
|
|
485
|
+
|
|
486
|
+
// stop_id validation
|
|
487
|
+
if (stop_id === undefined || stop_id === null) return false;
|
|
488
|
+
if (typeof stop_id === "boolean") return false;
|
|
489
|
+
|
|
490
|
+
const idStr = String(stop_id).trim();
|
|
491
|
+
|
|
492
|
+
if (!/^\d+$/.test(idStr)) return false;
|
|
493
|
+
|
|
494
|
+
if (seenIds.has(idStr)) return false;
|
|
495
|
+
seenIds.add(idStr);
|
|
496
|
+
|
|
497
|
+
// stop_name
|
|
498
|
+
if (typeof stop_name !== "string" || stop_name.trim().length === 0) return false;
|
|
499
|
+
|
|
500
|
+
// time fields
|
|
501
|
+
if (arrival_time === undefined || departure_time === undefined) return false;
|
|
502
|
+
|
|
503
|
+
const arrTime = String(arrival_time).trim();
|
|
504
|
+
const depTime = String(departure_time).trim();
|
|
505
|
+
|
|
506
|
+
if (!timeRegex.test(arrTime)) return false;
|
|
507
|
+
if (!timeRegex.test(depTime)) return false;
|
|
508
|
+
|
|
509
|
+
if (toMinutes(arrTime) > toMinutes(depTime)) return false;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice,isValidStopDetails,isValidStopTime,isValidCoordinates};
|