ingeni-validation 1.1.10 → 1.1.12

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,19 +311,24 @@ 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
315
 
315
316
  if (!Array.isArray(stop_details) || stop_details.length === 0){
316
317
  return false;
317
318
  }
318
319
 
319
320
  const timeRegex = /^([01][0-9]|2[0-3]):([0-5][0-9])$/;
321
+ const latlongRegex = /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/;
320
322
 
321
323
  const toMinutes = (t)=>{
322
324
  const [h,m] = t.split(":").map(Number);
323
325
  return h*60 + m;
324
326
  };
325
327
 
326
- const latlongRegex = /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/;
328
+ let usedIds = new Set();
329
+ let usedStopNames = new Set();
330
+ let expectedStopId = 1;
331
+ let previousArrival = -1;
327
332
 
328
333
  for (let stop of stop_details){
329
334
 
@@ -339,11 +344,24 @@ async function isValidStopDetails(stop_details){
339
344
 
340
345
  const stop_id = keys[0];
341
346
 
342
- // stop id must be numeric
343
347
  if (!/^\d+$/.test(stop_id)){
344
348
  return false;
345
349
  }
346
350
 
351
+ const stopIdNum = Number(stop_id);
352
+
353
+ // Duplicate stop ID check
354
+ if (usedIds.has(stopIdNum)){
355
+ return false;
356
+ }
357
+ usedIds.add(stopIdNum);
358
+
359
+ // Sequential stop check
360
+ if (stopIdNum !== expectedStopId){
361
+ return false;
362
+ }
363
+ expectedStopId++;
364
+
347
365
  const values = stop[stop_id];
348
366
 
349
367
  if (!Array.isArray(values) || values.length !== 4){
@@ -352,26 +370,46 @@ async function isValidStopDetails(stop_details){
352
370
 
353
371
  let [stop_name, arrival_time, departure_time, latlong] = values;
354
372
 
355
- // stop name
356
- if (typeof stop_name !== "string" || stop_name.trim().length === 0){
373
+ if (typeof stop_name !== "string" ||
374
+ typeof arrival_time !== "string" ||
375
+ typeof departure_time !== "string" ||
376
+ typeof latlong !== "string"){
357
377
  return false;
358
378
  }
359
379
 
360
- // time validation
380
+ stop_name = stop_name.trim();
381
+ arrival_time = arrival_time.trim();
382
+ departure_time = departure_time.trim();
383
+ latlong = latlong.trim();
384
+
385
+ if (stop_name.length === 0) return false;
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
+
361
394
  if (!timeRegex.test(arrival_time) || !timeRegex.test(departure_time)){
362
395
  return false;
363
396
  }
364
397
 
365
- // arrival must be <= departure
366
- if (toMinutes(arrival_time) > toMinutes(departure_time)){
398
+ const arrivalMin = toMinutes(arrival_time);
399
+ const departMin = toMinutes(departure_time);
400
+
401
+ if (arrivalMin > departMin){
367
402
  return false;
368
403
  }
369
404
 
370
- // coordinates mandatory
371
- if (typeof latlong !== "string" || latlong.trim().length === 0){
405
+ if (arrivalMin <= previousArrival){
372
406
  return false;
373
407
  }
374
408
 
409
+ previousArrival = arrivalMin;
410
+
411
+ if (latlong.length === 0) return false;
412
+
375
413
  if (!latlongRegex.test(latlong)){
376
414
  return false;
377
415
  }
@@ -387,4 +425,5 @@ async function isValidStopDetails(stop_details){
387
425
 
388
426
 
389
427
 
428
+
390
429
  export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice,isValidStopDetails};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ingeni-validation",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",