geo-coordinates-parser 1.5.3 → 1.5.6

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/converter.js CHANGED
@@ -78,7 +78,7 @@ function converter(coordsString, decimalPlaces) {
78
78
  }
79
79
 
80
80
  if (match[6]){
81
- ddLat += match[6]/3600;
81
+ ddLat += match[6].replace(',', '.')/3600;
82
82
  }
83
83
 
84
84
  if (parseInt(match[2]) < 0) {
@@ -92,7 +92,7 @@ function converter(coordsString, decimalPlaces) {
92
92
  }
93
93
 
94
94
  if (match[13]) {
95
- ddLng += match[13]/3600;
95
+ ddLng += match[13].replace(',', '.')/3600;
96
96
  }
97
97
 
98
98
  if (parseInt(match[9]) < 0) {
@@ -108,10 +108,18 @@ 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 {
114
- throw new Error("invalid DMS coordinates format")
122
+ throw new Error("invalid DMS coordinates format")
115
123
  }
116
124
  }
117
125
  else if (dms_abbr.test(coordsString)) {
@@ -409,11 +417,16 @@ function coordsCloseEnough(coordsToTest) {
409
417
  }
410
418
 
411
419
  //Coordinates pattern matching regex
420
+
421
+ //decimal degrees
412
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;
423
+
413
424
  //degrees minutes seconds with '.' as separator - gives array with 15 values
414
- 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})?)?(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})?)?(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])(?:[\.,]{1}\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;
426
+
415
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
416
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;
429
+
417
430
  //everything else - gives array of 17 values
418
431
  var coords_other = /(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*([•º°\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['′´’\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|′′|’’|´´|["″”\.])?[\ \t]*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*([•º°\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['′´’\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|′′|´´|’’|["″”\.])?[\ \t]*(EAST|WEST|[EW])?/i;
419
432
 
package/failFormats.js CHANGED
@@ -7,6 +7,11 @@ 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
14
+ '27.45.34 23.23.23 E' //no dir on one side
10
15
  ]
11
16
 
12
17
  module.exports = failingFormats
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geo-coordinates-parser",
3
- "version": "1.5.3",
3
+ "version": "1.5.6",
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/testFormats.json CHANGED
@@ -251,6 +251,13 @@
251
251
  "decimalLatitude": 40.123256,
252
252
  "decimalLongitude": -74.123256
253
253
  },
254
+ {
255
+ "verbatimCoordinates": "18°24S 22°45E",
256
+ "verbatimLatitude": "18°24S",
257
+ "verbatimLongitude": "22°45E",
258
+ "decimalLatitude": -18.4,
259
+ "decimalLongitude": 22.75
260
+ },
254
261
  {
255
262
  "verbatimCoordinates": "18.24S 22.45E",
256
263
  "verbatimLatitude": "18.24S",
@@ -299,5 +306,12 @@
299
306
  "verbatimLongitude": "23,07771° E",
300
307
  "decimalLatitude": -27.71372,
301
308
  "decimalLongitude": 23.07771
309
+ },
310
+ {
311
+ "verbatimCoordinates": "27.45.34 S 23.23.23 E",
312
+ "verbatimLatitude": "27.45.34 S",
313
+ "verbatimLongitude": "23.23.23 E",
314
+ "decimalLatitude": -27.759444,
315
+ "decimalLongitude": 23.38972222
302
316
  }
303
317
  ]
package/testIndividual.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const convert = require('./converter')
2
- const test = '23°45\'12.2\'\'S 18.33\'56.7\'\'E'
2
+ const test = '27.15.45,2S 18.32.53,4E'
3
3
 
4
4
  try{
5
5
  let converted = convert(test)
package/testformats.js CHANGED
@@ -273,6 +273,20 @@ var otherFormats = [
273
273
  decimalLatitude: -27.2625,
274
274
  decimalLongitude: 18.548055
275
275
  },
276
+ {
277
+ verbatimCoordinates: '27.15.45.2S 18.32.53.4E',
278
+ verbatimLatitude: '27.15.45.2S',
279
+ verbatimLongitude: '18.32.53.4E',
280
+ decimalLatitude: -27.262556,
281
+ decimalLongitude: 18.548167
282
+ },
283
+ {
284
+ verbatimCoordinates: '27.15.45,2S 18.32.53,4E',
285
+ verbatimLatitude: '27.15.45,2S',
286
+ verbatimLongitude: '18.32.53,4E',
287
+ decimalLatitude: -27.262556,
288
+ decimalLongitude: 18.548167
289
+ },
276
290
  {
277
291
  verbatimCoordinates: 'S23.43563 ° E22.45634 °', //decimals with spaces before the symbol!!
278
292
  verbatimLatitude: 'S23.43563 °',
@@ -286,6 +300,20 @@ var otherFormats = [
286
300
  verbatimLongitude: '23,07771° E',
287
301
  decimalLatitude: -27.71372,
288
302
  decimalLongitude: 23.07771
303
+ },
304
+ {
305
+ verbatimCoordinates: '27.45.34 S 23.23.23 E',
306
+ verbatimLatitude: '27.45.34 S',
307
+ verbatimLongitude: '23.23.23 E',
308
+ decimalLatitude: -27.759444,
309
+ decimalLongitude: 23.38972222
310
+ },
311
+ {
312
+ verbatimCoordinates: 'S 27.45.34 E 23.23.23',
313
+ verbatimLatitude: 'S 27.45.34',
314
+ verbatimLongitude: 'E 23.23.23',
315
+ decimalLatitude: -27.759444,
316
+ decimalLongitude: 23.38972222
289
317
  }
290
318
  ]
291
319