geo-coordinates-parser 1.7.2 → 1.7.3

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.
@@ -26,6 +26,9 @@ function converter(coordsString, decimalPlaces) {
26
26
  let originalFormat = null;
27
27
  let match = [];
28
28
  let matchSuccess = false;
29
+ if (regex_js_1.dm_invalid.test(coordsString)) {
30
+ throw new Error("invalid coordinate value");
31
+ }
29
32
  if (regex_js_1.dm_numbers.test(coordsString)) {
30
33
  match = regex_js_1.dm_numbers.exec(coordsString);
31
34
  matchSuccess = checkMatch(match);
@@ -163,6 +166,10 @@ function converter(coordsString, decimalPlaces) {
163
166
  else if (regex_js_1.coords_other.test(coordsString)) {
164
167
  match = regex_js_1.coords_other.exec(coordsString);
165
168
  matchSuccess = checkMatch(match);
169
+ // we need an extra check here for things that matched that shouldn't have
170
+ if (match.filter(x => x).length <= 5) {
171
+ throw new Error("invalid coordinates format");
172
+ }
166
173
  if (matchSuccess) {
167
174
  ddLat = Math.abs(parseInt(match[2]));
168
175
  if (match[4]) {
@@ -370,6 +377,9 @@ function decimalsCloseEnough(dec1, dec2) {
370
377
  }
371
378
  }
372
379
  function coordsCloseEnough(coordsToTest) {
380
+ if (!coordsToTest) {
381
+ throw new Error('coords must be provided');
382
+ }
373
383
  if (coordsToTest.includes(',')) {
374
384
  const coords = coordsToTest.split(',');
375
385
  if (Number(coords[0]) == NaN || Number(coords[1]) == NaN) {
@@ -1,3 +1,4 @@
1
+ export const dm_invalid: RegExp;
1
2
  export const dm_numbers: RegExp;
2
3
  export const dd_re: RegExp;
3
4
  export const dms_periods: RegExp;
package/dist/cjs/regex.js CHANGED
@@ -1,19 +1,22 @@
1
1
  "use strict";
2
2
  //Coordinates pattern matching regex
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.coords_other = exports.dms_abbr = exports.dms_periods = exports.dd_re = exports.dm_numbers = void 0;
4
+ exports.coords_other = exports.dms_abbr = exports.dms_periods = exports.dd_re = exports.dm_numbers = exports.dm_invalid = void 0;
5
+ //DM with invalid minutes (goes to coords_other); this is just a shortened version of that to create a guard condition
6
+ const dm_invalid = /^(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([6-9][0-9])\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([6-9][0-9])\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*(EAST|WEST|[EW])?$/i;
7
+ exports.dm_invalid = dm_invalid;
5
8
  //DM as numbers only - see issue #15
6
- const dm_numbers = /([+-]?[0-8]?[0-9])\s+([0-5]?[0-9]\.\d{3,})[\s,]{1,}([+-]?[0-1]?[0-9]?[0-9])\s+([0-5]?[0-9]\.\d{3,})/;
9
+ const dm_numbers = /^([+-]?[0-8]?[0-9])\s+([0-5]?[0-9]\.\d{3,})[\s,]{1,}([+-]?[0-1]?[0-9]?[0-9])\s+([0-5]?[0-9]\.\d{3,})$/;
7
10
  exports.dm_numbers = dm_numbers;
8
11
  //decimal degrees
9
- const 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;
12
+ const 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;
10
13
  exports.dd_re = dd_re;
11
14
  //degrees minutes seconds with '.' as separator - gives array with 15 values
12
- const 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;
15
+ const 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;
13
16
  exports.dms_periods = dms_periods;
14
17
  //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
15
- const dms_abbr = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)\s*(EAST|WEST|[EW])?/i;
18
+ const dms_abbr = /^(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)\s*(EAST|WEST|[EW])?$/i;
16
19
  exports.dms_abbr = dms_abbr;
17
20
  //everything else - gives array of 17 values
18
- const coords_other = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|’’|´´|["″”\.])?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|´´|’’|["″”\.])?\s*(EAST|WEST|[EW])?/i;
21
+ const coords_other = /^(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|’’|´´|["″”\.])?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|´´|’’|["″”\.])?\s*(EAST|WEST|[EW])?$/i;
19
22
  exports.coords_other = coords_other;
@@ -21,6 +21,9 @@ const failingFormats = [
21
21
  'S 90°4\'17.698" S 23°4\'17.698"',
22
22
  '27.45.34 S S 23.23.23',
23
23
  '27.45.34 23.23.23 E',
24
- '8°83S 35°67E '
24
+ '8°83S 35°67E ',
25
+ '25.62S, 27.77E',
26
+ '-254.4602, 31.53681',
27
+ '1234.524234234, 1241.1541241234',
25
28
  ];
26
29
  exports.default = failingFormats;
@@ -9,21 +9,20 @@ const converter_js_1 = __importDefault(require("../converter.js"));
9
9
  //const test = `45°5'46.8134"N, 18°30'36.7124"E`
10
10
  //const test = `50 8.2914,-5 2.4447`
11
11
  //const test = `8°83S 35°67E`
12
- const test = `N 48° 30,6410', E 18° 57,4583'`;
12
+ //const test = `N 48° 30,6410', E 18° 57,4583'`
13
+ //const test = '-254.4602, 31.53681'
14
+ const test = '25.62S, 27.77E';
15
+ //const correctDecimals = '-25.533333, 27.283333'
16
+ let converted;
13
17
  try {
14
- let converted = (0, converter_js_1.default)(test);
15
- console.log(converted);
16
- console.log(converted.toCoordinateFormat(converter_js_1.default.to.DM));
17
- //and just to make sure it's frozen
18
- let previous = converted.decimalLatitude;
19
- converted.decimalLatitude = 24;
20
- if (converted.decimalLatitude === previous) {
21
- console.log('the result is frozen');
22
- }
23
- else {
24
- console.error('!!!The result is not frozen!!!!');
25
- }
18
+ converted = (0, converter_js_1.default)(test);
26
19
  }
27
20
  catch (err) {
28
21
  console.log(err.message);
22
+ process.exit();
23
+ }
24
+ console.log(converted);
25
+ console.log('DM:', converted.toCoordinateFormat(converter_js_1.default.to.DM).replace(/\s/g, '')); // shortened format
26
+ if (!converted.closeEnough(correctDecimals)) {
27
+ console.error('!!! conversion is incorrect !!!');
29
28
  }
@@ -363,6 +363,13 @@ const otherFormats = [
363
363
  verbatimLongitude: `E 18° 57,4583'`,
364
364
  decimalLatitude: 48.51068,
365
365
  decimalLongitude: 18.95764
366
+ },
367
+ {
368
+ verbatimCoordinates: `1.23456, 18.33453`,
369
+ verbatimLatitude: `1.23456`,
370
+ verbatimLongitude: `18.33453`,
371
+ decimalLatitude: 1.23456,
372
+ decimalLongitude: 18.33453
366
373
  }
367
374
  ];
368
375
  function getAllTestFormats() {
@@ -1,6 +1,6 @@
1
1
  //function for converting coordinates from a string to decimal and verbatim
2
2
  //this is just a comment
3
- import { dm_numbers, dd_re, dms_periods, dms_abbr, coords_other } from './regex.js';
3
+ import { dm_invalid, dm_numbers, dd_re, dms_periods, dms_abbr, coords_other } from './regex.js';
4
4
  import toCoordinateFormat from './toCoordinateFormat.js';
5
5
  /**
6
6
  * Function for converting coordinates in a variety of formats to decimal coordinates
@@ -21,6 +21,9 @@ function converter(coordsString, decimalPlaces) {
21
21
  let originalFormat = null;
22
22
  let match = [];
23
23
  let matchSuccess = false;
24
+ if (dm_invalid.test(coordsString)) {
25
+ throw new Error("invalid coordinate value");
26
+ }
24
27
  if (dm_numbers.test(coordsString)) {
25
28
  match = dm_numbers.exec(coordsString);
26
29
  matchSuccess = checkMatch(match);
@@ -158,6 +161,10 @@ function converter(coordsString, decimalPlaces) {
158
161
  else if (coords_other.test(coordsString)) {
159
162
  match = coords_other.exec(coordsString);
160
163
  matchSuccess = checkMatch(match);
164
+ // we need an extra check here for things that matched that shouldn't have
165
+ if (match.filter(x => x).length <= 5) {
166
+ throw new Error("invalid coordinates format");
167
+ }
161
168
  if (matchSuccess) {
162
169
  ddLat = Math.abs(parseInt(match[2]));
163
170
  if (match[4]) {
@@ -365,6 +372,9 @@ function decimalsCloseEnough(dec1, dec2) {
365
372
  }
366
373
  }
367
374
  function coordsCloseEnough(coordsToTest) {
375
+ if (!coordsToTest) {
376
+ throw new Error('coords must be provided');
377
+ }
368
378
  if (coordsToTest.includes(',')) {
369
379
  const coords = coordsToTest.split(',');
370
380
  if (Number(coords[0]) == NaN || Number(coords[1]) == NaN) {
@@ -1,3 +1,4 @@
1
+ export const dm_invalid: RegExp;
1
2
  export const dm_numbers: RegExp;
2
3
  export const dd_re: RegExp;
3
4
  export const dms_periods: RegExp;
package/dist/mjs/regex.js CHANGED
@@ -1,12 +1,14 @@
1
1
  //Coordinates pattern matching regex
2
+ //DM with invalid minutes (goes to coords_other); this is just a shortened version of that to create a guard condition
3
+ const dm_invalid = /^(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([6-9][0-9])\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([6-9][0-9])\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*(EAST|WEST|[EW])?$/i;
2
4
  //DM as numbers only - see issue #15
3
- const dm_numbers = /([+-]?[0-8]?[0-9])\s+([0-5]?[0-9]\.\d{3,})[\s,]{1,}([+-]?[0-1]?[0-9]?[0-9])\s+([0-5]?[0-9]\.\d{3,})/;
5
+ const dm_numbers = /^([+-]?[0-8]?[0-9])\s+([0-5]?[0-9]\.\d{3,})[\s,]{1,}([+-]?[0-1]?[0-9]?[0-9])\s+([0-5]?[0-9]\.\d{3,})$/;
4
6
  //decimal degrees
5
- const 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;
7
+ const 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;
6
8
  //degrees minutes seconds with '.' as separator - gives array with 15 values
7
- const 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;
9
+ const 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;
8
10
  //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
9
- const dms_abbr = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)\s*(EAST|WEST|[EW])?/i;
11
+ const dms_abbr = /^(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*(D(?:EG)?(?:REES)?)\s*([0-5]?[0-9])\s*(M(?:IN)?(?:UTES)?)\s*((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(S(?:EC)?(?:ONDS)?)\s*(EAST|WEST|[EW])?$/i;
10
12
  //everything else - gives array of 17 values
11
- const coords_other = /(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|’’|´´|["″”\.])?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|´´|’’|["″”\.])?\s*(EAST|WEST|[EW])?/i;
12
- export { dm_numbers, dd_re, dms_periods, dms_abbr, coords_other };
13
+ const coords_other = /^(NORTH|SOUTH|[NS])?\s*([+-]?[0-8]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|’’|´´|["″”\.])?\s*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?\s*([+-]?[0-1]?[0-9]?[0-9])\s*([•º°\.:]|D(?:EG)?(?:REES)?)?\s*,?([0-5]?[0-9](?:[\.,]\d{1,})?)?\s*(['′´’\.:]|M(?:IN)?(?:UTES)?)?\s*,?((?:[0-5]?[0-9])(?:[\.,]\d{1,3})?)?\s*(''|′′|´´|’’|["″”\.])?\s*(EAST|WEST|[EW])?$/i;
14
+ export { dm_invalid, dm_numbers, dd_re, dms_periods, dms_abbr, coords_other };
@@ -19,6 +19,9 @@ const failingFormats = [
19
19
  'S 90°4\'17.698" S 23°4\'17.698"',
20
20
  '27.45.34 S S 23.23.23',
21
21
  '27.45.34 23.23.23 E',
22
- '8°83S 35°67E '
22
+ '8°83S 35°67E ',
23
+ '25.62S, 27.77E',
24
+ '-254.4602, 31.53681',
25
+ '1234.524234234, 1241.1541241234',
23
26
  ];
24
27
  export default failingFormats;
@@ -4,21 +4,20 @@ import convert from '../converter.js';
4
4
  //const test = `45°5'46.8134"N, 18°30'36.7124"E`
5
5
  //const test = `50 8.2914,-5 2.4447`
6
6
  //const test = `8°83S 35°67E`
7
- const test = `N 48° 30,6410', E 18° 57,4583'`;
7
+ //const test = `N 48° 30,6410', E 18° 57,4583'`
8
+ //const test = '-254.4602, 31.53681'
9
+ const test = '25.62S, 27.77E';
10
+ //const correctDecimals = '-25.533333, 27.283333'
11
+ let converted;
8
12
  try {
9
- let converted = convert(test);
10
- console.log(converted);
11
- console.log(converted.toCoordinateFormat(convert.to.DM));
12
- //and just to make sure it's frozen
13
- let previous = converted.decimalLatitude;
14
- converted.decimalLatitude = 24;
15
- if (converted.decimalLatitude === previous) {
16
- console.log('the result is frozen');
17
- }
18
- else {
19
- console.error('!!!The result is not frozen!!!!');
20
- }
13
+ converted = convert(test);
21
14
  }
22
15
  catch (err) {
23
16
  console.log(err.message);
17
+ process.exit();
18
+ }
19
+ console.log(converted);
20
+ console.log('DM:', converted.toCoordinateFormat(convert.to.DM).replace(/\s/g, '')); // shortened format
21
+ if (!converted.closeEnough(correctDecimals)) {
22
+ console.error('!!! conversion is incorrect !!!');
24
23
  }
@@ -361,6 +361,13 @@ const otherFormats = [
361
361
  verbatimLongitude: `E 18° 57,4583'`,
362
362
  decimalLatitude: 48.51068,
363
363
  decimalLongitude: 18.95764
364
+ },
365
+ {
366
+ verbatimCoordinates: `1.23456, 18.33453`,
367
+ verbatimLatitude: `1.23456`,
368
+ verbatimLongitude: `18.33453`,
369
+ decimalLatitude: 1.23456,
370
+ decimalLongitude: 18.33453
364
371
  }
365
372
  ];
366
373
  function getAllTestFormats() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geo-coordinates-parser",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
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
  "type": "module",
6
6
  "main": "./dist/cjs/merge.js",