ingeni-validation 1.1.7 → 1.1.9

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.
@@ -308,7 +308,80 @@ async function isValidDate(value, format) {
308
308
  return true;
309
309
  }
310
310
 
311
+ //Stop details Validation "stop_details":[{"30":["Baripada","13:00","13:01","21.9319,86.7465"]}]
312
+
313
+ async function isValidStopDetails(stop_details){
314
+
315
+ if (!Array.isArray(stop_details) || stop_details.length === 0){
316
+ return false;
317
+ }
318
+
319
+ const timeRegex = /^([01][0-9]|2[0-3]):([0-5][0-9])$/;
320
+
321
+ const toMinutes = (t)=>{
322
+ const [h,m] = t.split(":").map(Number);
323
+ return h*60 + m;
324
+ };
325
+
326
+ const latlongRegex = /^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/;
327
+
328
+ for (let stop of stop_details){
329
+
330
+ if (typeof stop !== "object" || stop === null){
331
+ return false;
332
+ }
333
+
334
+ const keys = Object.keys(stop);
335
+
336
+ if (keys.length !== 1){
337
+ return false;
338
+ }
339
+
340
+ const stop_id = keys[0];
341
+
342
+ if (!/^\d+$/.test(stop_id)){
343
+ return false;
344
+ }
345
+
346
+ const values = stop[stop_id];
347
+
348
+ if (!Array.isArray(values) || values.length !== 4){
349
+ return false;
350
+ }
351
+
352
+ let [stop_name, arrival_time, departure_time, latlong] = values;
353
+
354
+ if (typeof stop_name !== "string" || stop_name.trim().length === 0){
355
+ return false;
356
+ }
357
+
358
+ if (!timeRegex.test(arrival_time) || !timeRegex.test(departure_time)){
359
+ return false;
360
+ }
361
+
362
+ // allow equal time
363
+ if (toMinutes(arrival_time) > toMinutes(departure_time)){
364
+ return false;
365
+ }
366
+
367
+ // lat,long optional
368
+ if (latlong !== ""){
369
+
370
+ if (typeof latlong !== "string" || !latlongRegex.test(latlong)){
371
+ return false;
372
+ }
373
+
374
+ let [lat, lon] = latlong.split(",").map(Number);
375
+
376
+ if (lat < -90 || lat > 90) return false;
377
+ if (lon < -180 || lon > 180) return false;
378
+ }
379
+
380
+ }
381
+
382
+ return true;
383
+ }
311
384
 
312
385
 
313
386
 
314
- export {validateMandate,validateOptional,isValidMobile,isValidEmail,isValidOtp,isValidPin,isValidNumber,isValidBoolean,checkBooleanParams,isValidDate,isValidTime,isValidPrice};
387
+ 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.7",
3
+ "version": "1.1.9",
4
4
  "description": "Ingeni Validation",
5
5
  "license": "ISC",
6
6
  "author": "",