ingeni-validation 1.1.9 → 1.1.10
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 +14 -11
- package/package.json +1 -1
package/ingeni-validation.js
CHANGED
|
@@ -339,6 +339,7 @@ async function isValidStopDetails(stop_details){
|
|
|
339
339
|
|
|
340
340
|
const stop_id = keys[0];
|
|
341
341
|
|
|
342
|
+
// stop id must be numeric
|
|
342
343
|
if (!/^\d+$/.test(stop_id)){
|
|
343
344
|
return false;
|
|
344
345
|
}
|
|
@@ -351,32 +352,34 @@ async function isValidStopDetails(stop_details){
|
|
|
351
352
|
|
|
352
353
|
let [stop_name, arrival_time, departure_time, latlong] = values;
|
|
353
354
|
|
|
355
|
+
// stop name
|
|
354
356
|
if (typeof stop_name !== "string" || stop_name.trim().length === 0){
|
|
355
357
|
return false;
|
|
356
358
|
}
|
|
357
359
|
|
|
360
|
+
// time validation
|
|
358
361
|
if (!timeRegex.test(arrival_time) || !timeRegex.test(departure_time)){
|
|
359
362
|
return false;
|
|
360
363
|
}
|
|
361
364
|
|
|
362
|
-
//
|
|
365
|
+
// arrival must be <= departure
|
|
363
366
|
if (toMinutes(arrival_time) > toMinutes(departure_time)){
|
|
364
367
|
return false;
|
|
365
368
|
}
|
|
366
369
|
|
|
367
|
-
//
|
|
368
|
-
if (latlong !== ""){
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return false;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
let [lat, lon] = latlong.split(",").map(Number);
|
|
370
|
+
// coordinates mandatory
|
|
371
|
+
if (typeof latlong !== "string" || latlong.trim().length === 0){
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
375
374
|
|
|
376
|
-
|
|
377
|
-
|
|
375
|
+
if (!latlongRegex.test(latlong)){
|
|
376
|
+
return false;
|
|
378
377
|
}
|
|
379
378
|
|
|
379
|
+
let [lat, lon] = latlong.split(",").map(Number);
|
|
380
|
+
|
|
381
|
+
if (lat < -90 || lat > 90) return false;
|
|
382
|
+
if (lon < -180 || lon > 180) return false;
|
|
380
383
|
}
|
|
381
384
|
|
|
382
385
|
return true;
|