ingeni-validation 1.1.11 → 1.1.13

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.
@@ -311,7 +311,7 @@ async function isValidDate(value, format) {
311
311
  //Stop details Validation "stop_details":[{"30":["Baripada","13:00","13:01","21.9319,86.7465"]}]
312
312
 
313
313
  async function isValidStopDetails(stop_details){
314
- console.log("api stop details"+stop_details);
314
+ console.log("api stop details"+stop_details);
315
315
 
316
316
  if (!Array.isArray(stop_details) || stop_details.length === 0){
317
317
  return false;
@@ -326,6 +326,7 @@ async function isValidStopDetails(stop_details){
326
326
  };
327
327
 
328
328
  let usedIds = new Set();
329
+ let usedStopNames = new Set();
329
330
  let expectedStopId = 1;
330
331
  let previousArrival = -1;
331
332
 
@@ -343,20 +344,19 @@ async function isValidStopDetails(stop_details){
343
344
 
344
345
  const stop_id = keys[0];
345
346
 
346
- // stop id numeric
347
347
  if (!/^\d+$/.test(stop_id)){
348
348
  return false;
349
349
  }
350
350
 
351
351
  const stopIdNum = Number(stop_id);
352
352
 
353
- // 1️⃣ Duplicate stop ID check
353
+ // Duplicate stop ID check
354
354
  if (usedIds.has(stopIdNum)){
355
355
  return false;
356
356
  }
357
357
  usedIds.add(stopIdNum);
358
358
 
359
- // 2️⃣ Sequential stop check
359
+ // Sequential stop check
360
360
  if (stopIdNum !== expectedStopId){
361
361
  return false;
362
362
  }
@@ -384,6 +384,13 @@ async function isValidStopDetails(stop_details){
384
384
 
385
385
  if (stop_name.length === 0) return false;
386
386
 
387
+ // Unique stop_name check (case-insensitive)
388
+ const cleanName = stop_name.toLowerCase();
389
+ if (usedStopNames.has(cleanName)){
390
+ return false;
391
+ }
392
+ usedStopNames.add(cleanName);
393
+
387
394
  if (!timeRegex.test(arrival_time) || !timeRegex.test(departure_time)){
388
395
  return false;
389
396
  }
@@ -391,19 +398,16 @@ async function isValidStopDetails(stop_details){
391
398
  const arrivalMin = toMinutes(arrival_time);
392
399
  const departMin = toMinutes(departure_time);
393
400
 
394
- // arrival <= departure
395
401
  if (arrivalMin > departMin){
396
402
  return false;
397
403
  }
398
404
 
399
- // 3️⃣ Next stop must be after previous stop
400
405
  if (arrivalMin <= previousArrival){
401
406
  return false;
402
407
  }
403
408
 
404
409
  previousArrival = arrivalMin;
405
410
 
406
- // mandatory coordinates
407
411
  if (latlong.length === 0) return false;
408
412
 
409
413
  if (!latlongRegex.test(latlong)){
@@ -421,4 +425,40 @@ async function isValidStopDetails(stop_details){
421
425
 
422
426
 
423
427
 
424
- export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice,isValidStopDetails};
428
+
429
+
430
+ //allow this format only ("20.2849144,85.8078186")
431
+
432
+ function isValidCoordinates(location) {
433
+
434
+ if (location === null || location === undefined) return false;
435
+
436
+ if (typeof location === "boolean") return false;
437
+
438
+ if (typeof location !== "string") return false;
439
+
440
+ if (location.length === 0) return false;
441
+
442
+ if (location.includes(" ")) return false;
443
+
444
+ const regex = /^-?\d{1,2}(\.\d+)?,-?\d{1,3}(\.\d+)?$/;
445
+ if (!regex.test(location)) return false;
446
+
447
+ const [latStr, lngStr] = location.split(",");
448
+
449
+ const lat = Number(latStr);
450
+ const lng = Number(lngStr);
451
+
452
+ // Extra safety
453
+ if (!Number.isFinite(lat) || !Number.isFinite(lng)) return false;
454
+
455
+ if (lat < -90 || lat > 90) return false;
456
+ if (lng < -180 || lng > 180) return false;
457
+
458
+ return true;
459
+ }
460
+
461
+
462
+
463
+
464
+ export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice,isValidStopDetails,isValidCoordinates};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeni-validation",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",