geo-coordinates-parser 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
package/converter.js CHANGED
@@ -108,6 +108,14 @@ function converter(coordsString, decimalPlaces) {
108
108
  latdir = match[7];
109
109
  lngdir = match[14];
110
110
  }
111
+ else { //we have to catch an edge case where we have no direction indicators
112
+ throw new Error("invalid DMS coordinates format")
113
+ }
114
+
115
+ //we have to catch another edge case here, same or missing direction indicators
116
+ if(!latdir || !lngdir) {
117
+ throw new Error("invalid DMS coordinates format")
118
+ }
111
119
 
112
120
  }
113
121
  else {
@@ -414,7 +422,7 @@ function coordsCloseEnough(coordsToTest) {
414
422
  var dd_re = /(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))[\s]*([•º°]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))[\s]*([•º°]?)[\s]*(EAST|WEST|[EW])?/i;
415
423
 
416
424
  //degrees minutes seconds with '.' as separator - gives array with 15 values
417
- var dms_periods = /(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*(\.)[\ \t]*([0-5]?[0-9])[\ \t]*(\.)?[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?\s*(NORTH|SOUTH|[NS])?(?:[\ \t]*[,/;][\ \t]*|[\ \t]*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*(\.)[\ \t]*([0-5]?[0-9])[\ \t]*(\.)?[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?\s*(EAST|WEST|[EW])?/i;
425
+ var dms_periods = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(\.)\s*([0-5]?[0-9])\s*(\.)?\s*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(\.)\s*([0-5]?[0-9])\s*(\.)?\s*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?\s*(EAST|WEST|[EW])?/i;
418
426
 
419
427
  //degrees minutes seconds with words 'degrees, minutes, seconds' as separators (needed because the s of seconds messes with the S of SOUTH) - gives array of 17 values
420
428
  var dms_abbr = /(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*(D(?:EG)?(?:REES)?)[\ \t]*([0-5]?[0-9])[\ \t]*(M(?:IN)?(?:UTES)?)[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?(S(?:EC)?(?:ONDS)?)?[\ \t]*(NORTH|SOUTH|[NS])?(?:[\ \t]*[,/;][\ \t]*|[\ \t]*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*(D(?:EG)?(?:REES)?)[\ \t]*([0-5]?[0-9])[\ \t]*(M(?:IN)?(?:UTES)?)[\ \t]*((?:[0-5]?[0-9])(?:\.\d{1,3})?)?(S(?:EC)?(?:ONDS)?)[\ \t]*(EAST|WEST|[EW])?/i;
package/failFormats.js CHANGED
@@ -7,6 +7,10 @@ const failingFormats = [
7
7
  '50°4\'17.698"east, 23°4\'17.698"south', //directions wrong way round
8
8
  'E23.34355,S25.324234', // directions wrong way round
9
9
  '23°45\'12.2\'\'S 18.33\'56.7\'\'E', //symbols don't match
10
+ 'S 27.45.34 23.23.23', //missing direction on right side
11
+ 'S 27.45.34 S 23.23.23', //invalid direction on right side
12
+ 'S 90°4\'17.698" S 23°4\'17.698"',
13
+ '27.45.34 S S 23.23.23', //invalid direction on right side
10
14
  ]
11
15
 
12
16
  module.exports = failingFormats
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geo-coordinates-parser",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "description": "A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts by returning the verbatim coordinates and the decimal coordinates all in one object.",
5
5
  "main": "merge.js",
6
6
  "scripts": {
package/testIndividual.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const convert = require('./converter')
2
- const test = '27.45.34 S 23.23.23 E'
2
+ const test = 'S 27.45.34 S 23.23.23'
3
3
 
4
4
  try{
5
5
  let converted = convert(test)