geo-coordinates-parser
Advanced tools
Comparing version 1.7.2 to 1.7.3
@@ -29,2 +29,5 @@ "use strict"; | ||
let matchSuccess = false; | ||
if (regex_js_1.dm_invalid.test(coordsString)) { | ||
throw new Error("invalid coordinate value"); | ||
} | ||
if (regex_js_1.dm_numbers.test(coordsString)) { | ||
@@ -167,2 +170,6 @@ match = regex_js_1.dm_numbers.exec(coordsString); | ||
matchSuccess = checkMatch(match); | ||
// we need an extra check here for things that matched that shouldn't have | ||
if (match.filter(x => x).length <= 5) { | ||
throw new Error("invalid coordinates format"); | ||
} | ||
if (matchSuccess) { | ||
@@ -375,2 +382,5 @@ ddLat = Math.abs(parseInt(match[2])); | ||
function coordsCloseEnough(coordsToTest) { | ||
if (!coordsToTest) { | ||
throw new Error('coords must be provided'); | ||
} | ||
if (coordsToTest.includes(',')) { | ||
@@ -377,0 +387,0 @@ const coords = coordsToTest.split(','); |
@@ -0,1 +1,2 @@ | ||
export const dm_invalid: RegExp; | ||
export const dm_numbers: RegExp; | ||
@@ -2,0 +3,0 @@ export const dd_re: RegExp; |
"use strict"; | ||
//Coordinates pattern matching regex | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.coords_other = exports.dms_abbr = exports.dms_periods = exports.dd_re = exports.dm_numbers = void 0; | ||
exports.coords_other = exports.dms_abbr = exports.dms_periods = exports.dd_re = exports.dm_numbers = exports.dm_invalid = void 0; | ||
//DM with invalid minutes (goes to coords_other); this is just a shortened version of that to create a guard condition | ||
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; | ||
exports.dm_invalid = dm_invalid; | ||
//DM as numbers only - see issue #15 | ||
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,})/; | ||
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,})$/; | ||
exports.dm_numbers = dm_numbers; | ||
//decimal degrees | ||
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; | ||
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; | ||
exports.dd_re = dd_re; | ||
//degrees minutes seconds with '.' as separator - gives array with 15 values | ||
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; | ||
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; | ||
exports.dms_periods = dms_periods; | ||
//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 | ||
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; | ||
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; | ||
exports.dms_abbr = dms_abbr; | ||
//everything else - gives array of 17 values | ||
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; | ||
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; | ||
exports.coords_other = coords_other; |
@@ -24,4 +24,7 @@ "use strict"; | ||
'27.45.34 23.23.23 E', | ||
'8°83S 35°67E ' | ||
'8°83S 35°67E ', | ||
'25.62S, 27.77E', | ||
'-254.4602, 31.53681', | ||
'1234.524234234, 1241.1541241234', | ||
]; | ||
exports.default = failingFormats; |
@@ -366,2 +366,9 @@ "use strict"; | ||
decimalLongitude: 18.95764 | ||
}, | ||
{ | ||
verbatimCoordinates: `1.23456, 18.33453`, | ||
verbatimLatitude: `1.23456`, | ||
verbatimLongitude: `18.33453`, | ||
decimalLatitude: 1.23456, | ||
decimalLongitude: 18.33453 | ||
} | ||
@@ -368,0 +375,0 @@ ]; |
@@ -12,19 +12,18 @@ "use strict"; | ||
//const test = `8°83S 35°67E` | ||
const test = `N 48° 30,6410', E 18° 57,4583'`; | ||
//const test = `N 48° 30,6410', E 18° 57,4583'` | ||
//const test = '-254.4602, 31.53681' | ||
const test = '25.62S, 27.77E'; | ||
//const correctDecimals = '-25.533333, 27.283333' | ||
let converted; | ||
try { | ||
let converted = (0, converter_js_1.default)(test); | ||
console.log(converted); | ||
console.log(converted.toCoordinateFormat(converter_js_1.default.to.DM)); | ||
//and just to make sure it's frozen | ||
let previous = converted.decimalLatitude; | ||
converted.decimalLatitude = 24; | ||
if (converted.decimalLatitude === previous) { | ||
console.log('the result is frozen'); | ||
} | ||
else { | ||
console.error('!!!The result is not frozen!!!!'); | ||
} | ||
converted = (0, converter_js_1.default)(test); | ||
} | ||
catch (err) { | ||
console.log(err.message); | ||
process.exit(); | ||
} | ||
console.log(converted); | ||
console.log('DM:', converted.toCoordinateFormat(converter_js_1.default.to.DM).replace(/\s/g, '')); // shortened format | ||
if (!converted.closeEnough(correctDecimals)) { | ||
console.error('!!! conversion is incorrect !!!'); | ||
} |
//function for converting coordinates from a string to decimal and verbatim | ||
//this is just a comment | ||
import { dm_numbers, dd_re, dms_periods, dms_abbr, coords_other } from './regex.js'; | ||
import { dm_invalid, dm_numbers, dd_re, dms_periods, dms_abbr, coords_other } from './regex.js'; | ||
import toCoordinateFormat from './toCoordinateFormat.js'; | ||
@@ -24,2 +24,5 @@ /** | ||
let matchSuccess = false; | ||
if (dm_invalid.test(coordsString)) { | ||
throw new Error("invalid coordinate value"); | ||
} | ||
if (dm_numbers.test(coordsString)) { | ||
@@ -162,2 +165,6 @@ match = dm_numbers.exec(coordsString); | ||
matchSuccess = checkMatch(match); | ||
// we need an extra check here for things that matched that shouldn't have | ||
if (match.filter(x => x).length <= 5) { | ||
throw new Error("invalid coordinates format"); | ||
} | ||
if (matchSuccess) { | ||
@@ -370,2 +377,5 @@ ddLat = Math.abs(parseInt(match[2])); | ||
function coordsCloseEnough(coordsToTest) { | ||
if (!coordsToTest) { | ||
throw new Error('coords must be provided'); | ||
} | ||
if (coordsToTest.includes(',')) { | ||
@@ -372,0 +382,0 @@ const coords = coordsToTest.split(','); |
@@ -0,1 +1,2 @@ | ||
export const dm_invalid: RegExp; | ||
export const dm_numbers: RegExp; | ||
@@ -2,0 +3,0 @@ export const dd_re: RegExp; |
//Coordinates pattern matching regex | ||
//DM with invalid minutes (goes to coords_other); this is just a shortened version of that to create a guard condition | ||
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; | ||
//DM as numbers only - see issue #15 | ||
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,})/; | ||
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,})$/; | ||
//decimal degrees | ||
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; | ||
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; | ||
//degrees minutes seconds with '.' as separator - gives array with 15 values | ||
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; | ||
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; | ||
//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 | ||
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; | ||
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; | ||
//everything else - gives array of 17 values | ||
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; | ||
export { dm_numbers, dd_re, dms_periods, dms_abbr, coords_other }; | ||
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; | ||
export { dm_invalid, dm_numbers, dd_re, dms_periods, dms_abbr, coords_other }; |
@@ -22,4 +22,7 @@ //TODO These formats should throw... | ||
'27.45.34 23.23.23 E', | ||
'8°83S 35°67E ' | ||
'8°83S 35°67E ', | ||
'25.62S, 27.77E', | ||
'-254.4602, 31.53681', | ||
'1234.524234234, 1241.1541241234', | ||
]; | ||
export default failingFormats; |
@@ -364,2 +364,9 @@ //return an array of coordinate strings for testing | ||
decimalLongitude: 18.95764 | ||
}, | ||
{ | ||
verbatimCoordinates: `1.23456, 18.33453`, | ||
verbatimLatitude: `1.23456`, | ||
verbatimLongitude: `18.33453`, | ||
decimalLatitude: 1.23456, | ||
decimalLongitude: 18.33453 | ||
} | ||
@@ -366,0 +373,0 @@ ]; |
@@ -7,19 +7,18 @@ import convert from '../converter.js'; | ||
//const test = `8°83S 35°67E` | ||
const test = `N 48° 30,6410', E 18° 57,4583'`; | ||
//const test = `N 48° 30,6410', E 18° 57,4583'` | ||
//const test = '-254.4602, 31.53681' | ||
const test = '25.62S, 27.77E'; | ||
//const correctDecimals = '-25.533333, 27.283333' | ||
let converted; | ||
try { | ||
let converted = convert(test); | ||
console.log(converted); | ||
console.log(converted.toCoordinateFormat(convert.to.DM)); | ||
//and just to make sure it's frozen | ||
let previous = converted.decimalLatitude; | ||
converted.decimalLatitude = 24; | ||
if (converted.decimalLatitude === previous) { | ||
console.log('the result is frozen'); | ||
} | ||
else { | ||
console.error('!!!The result is not frozen!!!!'); | ||
} | ||
converted = convert(test); | ||
} | ||
catch (err) { | ||
console.log(err.message); | ||
process.exit(); | ||
} | ||
console.log(converted); | ||
console.log('DM:', converted.toCoordinateFormat(convert.to.DM).replace(/\s/g, '')); // shortened format | ||
if (!converted.closeEnough(correctDecimals)) { | ||
console.error('!!! conversion is incorrect !!!'); | ||
} |
{ | ||
"name": "geo-coordinates-parser", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"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,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115803
2932