geo-coordinates-parser 1.5.1 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).convert=t()}}(function(){function t(t,e,i){const a=Number(t);let r;r=i?a>=0?"N":"S":a>=0?"E":"W";const d=Math.abs(a),o=Math.floor(d),n=60*(d-o);if("DM"==e)return`${o}\xb0 ${n.toFixed(3).replace(/\.0+$/,"")}' ${r}`;const m=Math.floor(n);return`${o}\xb0 ${m}' ${(60*(n-m)).toFixed(1).replace(/\.0$/,"")}" ${r}`}var e=function(e){if(!["DMS","DM"].includes(e))throw new Error("invalid format specified");if(this.decimalCoordinates&&this.decimalCoordinates.trim()){const i=this.decimalCoordinates.split(",").map(t=>t.trim());return`${t(i[0],e,!0)}, ${t(i[1],e,!1)}`}throw new Error("no decimal coordinates to convert")},i={};function a(t,i){i||(i=5),t=t.replace(/\s\s+/g," ").trim();var a=null,d=null,s="",v="",L=[],l=!1;if(n.test(t)){if(!(l=r(L=n.exec(t))))throw new Error("invalid decimal coordinate format");a=L[2],d=L[6],a.includes(",")&&(a=a.replace(",",".")),d.includes(",")&&(d=d.replace(",",".")),L[1]?(s=L[1],v=L[5]):L[4]&&(s=L[4],v=L[8])}else if(m.test(t)){if(!(l=r(L=m.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60),L[6]&&(a+=L[6]/3600),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[9])),L[11]&&(d+=L[11]/60),L[13]&&(d+=L[13]/3600),parseInt(L[9])<0&&(d*=-1),L[1]?(s=L[1],v=L[8]):L[7]&&(s=L[7],v=L[14])}else if(u.test(t)){if(!(l=r(L=u.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60,L[3]||(L[3]=" ")),L[6]&&(a+=L[6]/3600,L[5]||(L[5]=" ")),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[10])),L[12]&&(d+=L[12]/60,L[11]||(L[11]=" ")),L[14]&&(d+=L[14]/3600,L[13]||(L[13]=" ")),parseInt(L[10])<0&&(d*=-1),L[1]?(s=L[1],v=L[9]):L[8]&&(s=L[8],v=L[16])}else if(b.test(t)){if(!(l=r(L=b.exec(t))))throw new Error("invalid coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60,L[3]||(L[3]=" ")),L[6]&&(a+=L[6]/3600,L[5]||(L[5]=" ")),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[10])),L[12]&&(d+=L[12]/60,L[11]||(L[11]=" ")),L[14]&&(d+=L[14]/3600,L[13]||(L[13]=" ")),parseInt(L[10])<0&&(d*=-1),L[1]?(s=L[1],v=L[9]):L[8]&&(s=L[8],v=L[16])}if(0==a||0==d)throw new Error("zero coordinate/s provided");if(Number(Math.round(a))==Number(a))throw new Error("degree only coordinate provided");if(Number(Math.round(d))==Number(d))throw new Error("degree only coordinate provided");if(Math.abs(d)>=180)throw new Error("invalid longitude value");if(l){var c=/S|SOUTH/i;c.test(s)&&a>0&&(a*=-1),(c=/W|WEST/i).test(v)&&d>0&&(d*=-1);var g,N,f=L[0].trim(),E=f.match(/[,/;\u0020]/g);if(null==E){var S=Math.floor(t.length/2);g=f.substring(0,S).trim(),N=f.substring(S).trim()}else{var W=0;if(0==(S=E.length%2==1?Math.floor(E.length/2):E.length/2-1))W=f.indexOf(E[0]),g=f.substring(0,W).trim(),N=f.substring(W+1).trim();else{for(var C=0,h=0;C<=S;)h=(W=f.indexOf(E[C],h))+1,C++;g=f.substring(0,W).trim(),N=f.substring(W+1).trim()}}return isNaN(a)&&a.includes(",")&&(a=a.replace(",",".")),a=Number(Number(a).toFixed(i)),isNaN(d)&&d.includes(",")&&(d=d.replace(",",".")),d=Number(Number(d).toFixed(i)),Object.freeze({verbatimCoordinates:f,verbatimLatitude:g,verbatimLongitude:N,decimalLatitude:a,decimalLongitude:d,decimalCoordinates:`${a},${d}`,closeEnough:o,toCoordinateFormat:e})}throw new Error("coordinates pattern match failed")}function r(t){if(!isNaN(t[0]))return!1;var e=t.filter(t=>t);if(e.shift(),e.length%2>0)return!1;for(var i=/^[-+]?\d+([\.,]{}\d+)?$/,a=/[A-Za-z]+/,r=e.length/2,d=!0,o=0;o<r;o++)if(i.test(e[o])!=i.test(e[o+r])||a.test(e[o])!=a.test(e[o+r])){d=!1;break}return d}function d(t,e){var i=Math.abs(t-e);return diff=Number(i.toFixed(6)),diff<=1e-5}function o(t){if(t.includes(",")){var e=t.split(",");if(NaN==Number(e[0])||NaN==Number(e[1]))throw new Error("coords are not valid decimals");return d(this.decimalLatitude,Number(e[0]))&&d(this.decimalLongitude,e[1])}throw new Error("coords being tested must be separated by a comma")}var n=/(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))[\s]*([\u2022\xba\xb0]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))[\s]*([\u2022\xba\xb0]?)[\s]*(EAST|WEST|[EW])?/i,m=/(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,u=/(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,b=/(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*([\u2022\xba\xb0\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['\u2032\xb4\u2019\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|\u2032\u2032|\u2019\u2019|\xb4\xb4|["\u2033\u201d\.])?[\ \t]*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*([\u2022\xba\xb0\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['\u2032\xb4\u2019\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|\u2032\u2032|\xb4\xb4|\u2019\u2019|["\u2033\u201d\.])?[\ \t]*(EAST|WEST|[EW])?/i;const s=Object.freeze({DMS:"DMS",DM:"DM"});a.to=s,i=a;var v,L={decimalLatitude:40.123,decimalLongitude:-74.123},l=(v=[],[{verbatimCoordinates:"40.123, -74.123",verbatimLatitude:"40.123",verbatimLongitude:"-74.123"},{verbatimCoordinates:"40.123\xb0 N 74.123\xb0 W",verbatimLatitude:"40.123\xb0 N",verbatimLongitude:"74.123\xb0 W"},{verbatimCoordinates:"40.123\xb0 N 74.123\xb0 W",verbatimLatitude:"40.123\xb0 N",verbatimLongitude:"74.123\xb0 W"},{verbatimCoordinates:'40\xb0 7\xb4 22.8" N 74\xb0 7\xb4 22.8" W',verbatimLatitude:'40\xb0 7\xb4 22.8" N',verbatimLongitude:'74\xb0 7\xb4 22.8" W'},{verbatimCoordinates:"40\xb0 7.38\u2019 , -74\xb0 7.38\u2019",verbatimLatitude:"40\xb0 7.38\u2019",verbatimLongitude:"-74\xb0 7.38\u2019"},{verbatimCoordinates:"N40\xb07\u201922.8\u2019\u2019, W74\xb07\u201922.8\u2019\u2019",verbatimLatitude:"N40\xb07\u201922.8\u2019\u2019",verbatimLongitude:"W74\xb07\u201922.8\u2019\u2019"},{verbatimCoordinates:'40\xb07\u201922.8"N, 74\xb07\u201922.8"W',verbatimLatitude:'40\xb07\u201922.8"N',verbatimLongitude:'74\xb07\u201922.8"W'},{verbatimCoordinates:"40\xb07'22.8\"N, 74\xb07'22.8\"W",verbatimLatitude:"40\xb07'22.8\"N",verbatimLongitude:"74\xb07'22.8\"W"},{verbatimCoordinates:"40 7 22.8, -74 7 22.8",verbatimLatitude:"40 7 22.8",verbatimLongitude:"-74 7 22.8"},{verbatimCoordinates:"40.123 -74.123",verbatimLatitude:"40.123",verbatimLongitude:"-74.123"},{verbatimCoordinates:"40.123\xb0,-74.123\xb0",verbatimLatitude:"40.123\xb0",verbatimLongitude:"-74.123\xb0"},{verbatimCoordinates:"40.123N74.123W",verbatimLatitude:"40.123N",verbatimLongitude:"74.123W"},{verbatimCoordinates:"4007.38N7407.38W",verbatimLatitude:"4007.38N",verbatimLongitude:"7407.38W"},{verbatimCoordinates:'40\xb07\u201922.8"N, 74\xb07\u201922.8"W',verbatimLatitude:'40\xb07\u201922.8"N',verbatimLongitude:'74\xb07\u201922.8"W'},{verbatimCoordinates:"400722.8N740722.8W",verbatimLatitude:"400722.8N",verbatimLongitude:"740722.8W"},{verbatimCoordinates:"N 40 7.38 W 74 7.38",verbatimLatitude:"N 40 7.38",verbatimLongitude:"W 74 7.38"},{verbatimCoordinates:"40:7:22.8N 74:7:22.8W",verbatimLatitude:"40:7:22.8N",verbatimLongitude:"74:7:22.8W"},{verbatimCoordinates:"40:7:23N,74:7:23W",verbatimLatitude:"40:7:23N",verbatimLongitude:"74:7:23W",decimalLatitude:40.1230555555,decimalLongitude:-74.1230555555},{verbatimCoordinates:'40\xb07\u201923"N 74\xb07\u201923"W',verbatimLatitude:'40\xb07\u201923"N',verbatimLongitude:'74\xb07\u201923"W',decimalLatitude:40.1230555555,decimalLongitude:-74.12305555555555},{verbatimCoordinates:'40\xb07\u201923" -74\xb07\u201923"',verbatimLatitude:'40\xb07\u201923"',verbatimLongitude:'-74\xb07\u201923"',decimalLatitude:40.1230555555,decimalLongitude:-74.123055555},{verbatimCoordinates:'40d 7\u2019 23" N 74d 7\u2019 23" W',verbatimLatitude:'40d 7\u2019 23" N',verbatimLongitude:'74d 7\u2019 23" W',decimalLatitude:40.1230555555,decimalLongitude:-74.123055555},{verbatimCoordinates:"40.123N 74.123W",verbatimLatitude:"40.123N",verbatimLongitude:"74.123W"},{verbatimCoordinates:"40\xb0 7.38, -74\xb0 7.38",verbatimLatitude:"40\xb0 7.38",verbatimLongitude:"-74\xb0 7.38"},{verbatimCoordinates:"40\xb0 7.38, -74\xb0 7.38",verbatimLatitude:"40\xb0 7.38",verbatimLongitude:"-74\xb0 7.38"},{verbatimCoordinates:"40 7 22.8; -74 7 22.8",verbatimLatitude:"40 7 22.8",verbatimLongitude:"-74 7 22.8"}].forEach(t=>{t.decimalLatitude?v.push(t):v.push({...t,...L})}),[...v,{verbatimCoordinates:"50\xb04'17.698\"south, 14\xb024'2.826\"east",verbatimLatitude:"50\xb04'17.698\"south",verbatimLongitude:"14\xb024'2.826\"east",decimalLatitude:-50.07158277777778,decimalLongitude:14.400785},{verbatimCoordinates:"50d4m17.698S 14d24m2.826E",verbatimLatitude:"50d4m17.698S",verbatimLongitude:"14d24m2.826E",decimalLatitude:-50.07158277777778,decimalLongitude:14.400785},{verbatimCoordinates:"40:26:46N,79:56:55W",verbatimLatitude:"40:26:46N",verbatimLongitude:"79:56:55W",decimalLatitude:40.44611111111111,decimalLongitude:-79.9486111111111},{verbatimCoordinates:"40:26:46.302N 79:56:55.903W",verbatimLatitude:"40:26:46.302N",verbatimLongitude:"79:56:55.903W",decimalLatitude:40.446195,decimalLongitude:-79.94886194444445},{verbatimCoordinates:"40\xb026\u203247\u2033N 79\xb058\u203236\u2033W",verbatimLatitude:"40\xb026\u203247\u2033N",verbatimLongitude:"79\xb058\u203236\u2033W",decimalLatitude:40.44638888888889,decimalLongitude:-79.97666666666667},{verbatimCoordinates:"40d 26\u2032 47\u2033 N 79d 58\u2032 36\u2033 W",verbatimLatitude:"40d 26\u2032 47\u2033 N",verbatimLongitude:"79d 58\u2032 36\u2033 W",decimalLatitude:40.44638888888889,decimalLongitude:-79.97666666666667},{verbatimCoordinates:"40.446195N 79.948862W",verbatimLatitude:"40.446195N",verbatimLongitude:"79.948862W",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40,446195\xb0 79,948862\xb0",verbatimLatitude:"40,446195\xb0",verbatimLongitude:"79,948862\xb0",decimalLatitude:40.446195,decimalLongitude:79.948862},{verbatimCoordinates:"40\xb0 26.7717, -79\xb0 56.93172",verbatimLatitude:"40\xb0 26.7717",verbatimLongitude:"-79\xb0 56.93172",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40.446195, -79.948862",verbatimLatitude:"40.446195",verbatimLongitude:"-79.948862",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40.123256; -74.123256",verbatimLatitude:"40.123256",verbatimLongitude:"-74.123256",decimalLatitude:40.123256,decimalLongitude:-74.123256},{verbatimCoordinates:"18.24S 22.45E",verbatimLatitude:"18.24S",verbatimLongitude:"22.45E",decimalLatitude:-18.4,decimalLongitude:22.75},{verbatimCoordinates:"27deg 15min 45.2sec S 18deg 32min 53.7sec E",verbatimLatitude:"27deg 15min 45.2sec S",verbatimLongitude:"18deg 32min 53.7sec E",decimalLatitude:-27.262555555555554,decimalLongitude:18.54825},{verbatimCoordinates:"-23.3245\xb0 S / 28.2344\xb0 E",verbatimLatitude:"-23.3245\xb0 S",verbatimLongitude:"28.2344\xb0 E",decimalLatitude:-23.3245,decimalLongitude:28.2344},{verbatimCoordinates:"40\xb0 26.7717 -79\xb0 56.93172",verbatimLatitude:"40\xb0 26.7717",verbatimLongitude:"-79\xb0 56.93172",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"27.15.45S 18.32.53E",verbatimLatitude:"27.15.45S",verbatimLongitude:"18.32.53E",decimalLatitude:-27.2625,decimalLongitude:18.548055},{verbatimCoordinates:"S23.43563 \xb0 E22.45634 \xb0",verbatimLatitude:"S23.43563 \xb0",verbatimLongitude:"E22.45634 \xb0",decimalLatitude:-23.43563,decimalLongitude:22.45634},{verbatimCoordinates:"27,71372\xb0 S 23,07771\xb0 E",verbatimLatitude:"27,71372\xb0 S",verbatimLongitude:"23,07771\xb0 E",decimalLatitude:-27.71372,decimalLongitude:23.07771}]).map(t=>t.verbatimCoordinates);return i.formats=l,i});
1
+ !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).convert=t()}}(function(){function t(t,e,i){const a=Number(t);let r;r=i?a>=0?"N":"S":a>=0?"E":"W";const d=Math.abs(a),o=Math.floor(d),n=60*(d-o);if("DM"==e)return`${o}\xb0 ${n.toFixed(3).replace(/\.0+$/,"")}' ${r}`;const m=Math.floor(n);return`${o}\xb0 ${m}' ${(60*(n-m)).toFixed(1).replace(/\.0$/,"")}" ${r}`}var e=function(e){if(!["DMS","DM"].includes(e))throw new Error("invalid format specified");if(this.decimalCoordinates&&this.decimalCoordinates.trim()){const i=this.decimalCoordinates.split(",").map(t=>t.trim());return`${t(i[0],e,!0)}, ${t(i[1],e,!1)}`}throw new Error("no decimal coordinates to convert")},i={};function a(t,i){i||(i=5),t=t.replace(/\s\s+/g," ").trim();var a=null,d=null,s="",v="",L=[],l=!1;if(n.test(t)){if(!(l=r(L=n.exec(t))))throw new Error("invalid decimal coordinate format");if(a=L[2],d=L[6],a.includes(",")&&(a=a.replace(",",".")),d.includes(",")&&(d=d.replace(",",".")),Number(Math.round(a))==Number(a))throw new Error("degree only coordinate provided");if(Number(Math.round(d))==Number(d))throw new Error("degree only coordinate provided");L[1]?(s=L[1],v=L[5]):L[4]&&(s=L[4],v=L[8])}else if(m.test(t)){if(!(l=r(L=m.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60),L[6]&&(a+=L[6]/3600),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[9])),L[11]&&(d+=L[11]/60),L[13]&&(d+=L[13]/3600),parseInt(L[9])<0&&(d*=-1),L[1]?(s=L[1],v=L[8]):L[7]&&(s=L[7],v=L[14])}else if(u.test(t)){if(!(l=r(L=u.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60,L[3]||(L[3]=" ")),L[6]&&(a+=L[6]/3600,L[5]||(L[5]=" ")),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[10])),L[12]&&(d+=L[12]/60,L[11]||(L[11]=" ")),L[14]&&(d+=L[14]/3600,L[13]||(L[13]=" ")),parseInt(L[10])<0&&(d*=-1),L[1]?(s=L[1],v=L[9]):L[8]&&(s=L[8],v=L[16])}else if(b.test(t)){if(!(l=r(L=b.exec(t))))throw new Error("invalid coordinates format");a=Math.abs(parseInt(L[2])),L[4]&&(a+=L[4]/60,L[3]||(L[3]=" ")),L[6]&&(a+=L[6]/3600,L[5]||(L[5]=" ")),parseInt(L[2])<0&&(a*=-1),d=Math.abs(parseInt(L[10])),L[12]&&(d+=L[12]/60,L[11]||(L[11]=" ")),L[14]&&(d+=L[14]/3600,L[13]||(L[13]=" ")),parseInt(L[10])<0&&(d*=-1),L[1]?(s=L[1],v=L[9]):L[8]&&(s=L[8],v=L[16])}if(Math.abs(d)>=180)throw new Error("invalid longitude value");if(Math.abs(a)>=90)throw new Error("invalid latitude value");if(l){var c=/S|SOUTH/i;c.test(s)&&a>0&&(a*=-1),(c=/W|WEST/i).test(v)&&d>0&&(d*=-1);var g,N,E=L[0].trim(),f=E.match(/[,/;\u0020]/g);if(null==f){var S=Math.floor(t.length/2);g=E.substring(0,S).trim(),N=E.substring(S).trim()}else{var W=0;if(0==(S=f.length%2==1?Math.floor(f.length/2):f.length/2-1))W=E.indexOf(f[0]),g=E.substring(0,W).trim(),N=E.substring(W+1).trim();else{for(var C=0,h=0;C<=S;)h=(W=E.indexOf(f[C],h))+1,C++;g=E.substring(0,W).trim(),N=E.substring(W+1).trim()}}return isNaN(a)&&a.includes(",")&&(a=a.replace(",",".")),a=Number(Number(a).toFixed(i)),isNaN(d)&&d.includes(",")&&(d=d.replace(",",".")),d=Number(Number(d).toFixed(i)),Object.freeze({verbatimCoordinates:E,verbatimLatitude:g,verbatimLongitude:N,decimalLatitude:a,decimalLongitude:d,decimalCoordinates:`${a},${d}`,closeEnough:o,toCoordinateFormat:e})}throw new Error("coordinates pattern match failed")}function r(t){if(!isNaN(t[0]))return!1;var e=t.filter(t=>t);if(e.shift(),e.length%2>0)return!1;for(var i=/^[-+]?\d+([\.,]{1}\d+)?$/,a=/[eastsouthnorthwest]+/i,r=e.length/2,d=0;d<r;d++){const t=e[d],o=e[d+r];if(!(i.test(t)&&i.test(o)||a.test(t)&&a.test(o)||t==o))return!1}return!0}function d(t,e){var i=Math.abs(t-e);return diff=Number(i.toFixed(6)),diff<=1e-5}function o(t){if(t.includes(",")){var e=t.split(",");if(NaN==Number(e[0])||NaN==Number(e[1]))throw new Error("coords are not valid decimals");return d(this.decimalLatitude,Number(e[0]))&&d(this.decimalLongitude,e[1])}throw new Error("coords being tested must be separated by a comma")}var n=/(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))[\s]*([\u2022\xba\xb0]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))[\s]*([\u2022\xba\xb0]?)[\s]*(EAST|WEST|[EW])?/i,m=/(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,u=/(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,b=/(NORTH|SOUTH|[NS])?[\ \t]*([+-]?[0-8]?[0-9])[\ \t]*([\u2022\xba\xb0\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['\u2032\xb4\u2019\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|\u2032\u2032|\u2019\u2019|\xb4\xb4|["\u2033\u201d\.])?[\ \t]*(NORTH|SOUTH|[NS])?(?:\s*[,/;]\s*|\s*)(EAST|WEST|[EW])?[\ \t]*([+-]?[0-1]?[0-9]?[0-9])[\ \t]*([\u2022\xba\xb0\.:]|D(?:EG)?(?:REES)?)?[\ \t]*,?([0-5]?[0-9](?:\.\d{1,})?)?[\ \t]*(['\u2032\xb4\u2019\.:]|M(?:IN)?(?:UTES)?)?[\ \t]*,?((?:[0-5]?[0-9])(?:\.\d{1,3})?)?[\ \t]*(''|\u2032\u2032|\xb4\xb4|\u2019\u2019|["\u2033\u201d\.])?[\ \t]*(EAST|WEST|[EW])?/i;const s=Object.freeze({DMS:"DMS",DM:"DM"});a.to=s,i=a;var v,L={decimalLatitude:40.123,decimalLongitude:-74.123},l=(v=[],[{verbatimCoordinates:"40.123, -74.123",verbatimLatitude:"40.123",verbatimLongitude:"-74.123"},{verbatimCoordinates:"40.123\xb0 N 74.123\xb0 W",verbatimLatitude:"40.123\xb0 N",verbatimLongitude:"74.123\xb0 W"},{verbatimCoordinates:"40.123\xb0 N 74.123\xb0 W",verbatimLatitude:"40.123\xb0 N",verbatimLongitude:"74.123\xb0 W"},{verbatimCoordinates:'40\xb0 7\xb4 22.8" N 74\xb0 7\xb4 22.8" W',verbatimLatitude:'40\xb0 7\xb4 22.8" N',verbatimLongitude:'74\xb0 7\xb4 22.8" W'},{verbatimCoordinates:"40\xb0 7.38\u2019 , -74\xb0 7.38\u2019",verbatimLatitude:"40\xb0 7.38\u2019",verbatimLongitude:"-74\xb0 7.38\u2019"},{verbatimCoordinates:"N40\xb07\u201922.8\u2019\u2019, W74\xb07\u201922.8\u2019\u2019",verbatimLatitude:"N40\xb07\u201922.8\u2019\u2019",verbatimLongitude:"W74\xb07\u201922.8\u2019\u2019"},{verbatimCoordinates:'40\xb07\u201922.8"N, 74\xb07\u201922.8"W',verbatimLatitude:'40\xb07\u201922.8"N',verbatimLongitude:'74\xb07\u201922.8"W'},{verbatimCoordinates:"40\xb07'22.8\"N, 74\xb07'22.8\"W",verbatimLatitude:"40\xb07'22.8\"N",verbatimLongitude:"74\xb07'22.8\"W"},{verbatimCoordinates:"40 7 22.8, -74 7 22.8",verbatimLatitude:"40 7 22.8",verbatimLongitude:"-74 7 22.8"},{verbatimCoordinates:"40.123 -74.123",verbatimLatitude:"40.123",verbatimLongitude:"-74.123"},{verbatimCoordinates:"40.123\xb0,-74.123\xb0",verbatimLatitude:"40.123\xb0",verbatimLongitude:"-74.123\xb0"},{verbatimCoordinates:"40.123N74.123W",verbatimLatitude:"40.123N",verbatimLongitude:"74.123W"},{verbatimCoordinates:"4007.38N7407.38W",verbatimLatitude:"4007.38N",verbatimLongitude:"7407.38W"},{verbatimCoordinates:'40\xb07\u201922.8"N, 74\xb07\u201922.8"W',verbatimLatitude:'40\xb07\u201922.8"N',verbatimLongitude:'74\xb07\u201922.8"W'},{verbatimCoordinates:"400722.8N740722.8W",verbatimLatitude:"400722.8N",verbatimLongitude:"740722.8W"},{verbatimCoordinates:"N 40 7.38 W 74 7.38",verbatimLatitude:"N 40 7.38",verbatimLongitude:"W 74 7.38"},{verbatimCoordinates:"40:7:22.8N 74:7:22.8W",verbatimLatitude:"40:7:22.8N",verbatimLongitude:"74:7:22.8W"},{verbatimCoordinates:"40:7:23N,74:7:23W",verbatimLatitude:"40:7:23N",verbatimLongitude:"74:7:23W",decimalLatitude:40.1230555555,decimalLongitude:-74.1230555555},{verbatimCoordinates:'40\xb07\u201923"N 74\xb07\u201923"W',verbatimLatitude:'40\xb07\u201923"N',verbatimLongitude:'74\xb07\u201923"W',decimalLatitude:40.1230555555,decimalLongitude:-74.12305555555555},{verbatimCoordinates:'40\xb07\u201923" -74\xb07\u201923"',verbatimLatitude:'40\xb07\u201923"',verbatimLongitude:'-74\xb07\u201923"',decimalLatitude:40.1230555555,decimalLongitude:-74.123055555},{verbatimCoordinates:'40d 7\u2019 23" N 74d 7\u2019 23" W',verbatimLatitude:'40d 7\u2019 23" N',verbatimLongitude:'74d 7\u2019 23" W',decimalLatitude:40.1230555555,decimalLongitude:-74.123055555},{verbatimCoordinates:"40.123N 74.123W",verbatimLatitude:"40.123N",verbatimLongitude:"74.123W"},{verbatimCoordinates:"40\xb0 7.38, -74\xb0 7.38",verbatimLatitude:"40\xb0 7.38",verbatimLongitude:"-74\xb0 7.38"},{verbatimCoordinates:"40\xb0 7.38, -74\xb0 7.38",verbatimLatitude:"40\xb0 7.38",verbatimLongitude:"-74\xb0 7.38"},{verbatimCoordinates:"40 7 22.8; -74 7 22.8",verbatimLatitude:"40 7 22.8",verbatimLongitude:"-74 7 22.8"}].forEach(t=>{t.decimalLatitude?v.push(t):v.push({...t,...L})}),[...v,{verbatimCoordinates:"50\xb04'17.698\"south, 14\xb024'2.826\"east",verbatimLatitude:"50\xb04'17.698\"south",verbatimLongitude:"14\xb024'2.826\"east",decimalLatitude:-50.07158277777778,decimalLongitude:14.400785},{verbatimCoordinates:"50d4m17.698S 14d24m2.826E",verbatimLatitude:"50d4m17.698S",verbatimLongitude:"14d24m2.826E",decimalLatitude:-50.07158277777778,decimalLongitude:14.400785},{verbatimCoordinates:"40:26:46N,79:56:55W",verbatimLatitude:"40:26:46N",verbatimLongitude:"79:56:55W",decimalLatitude:40.44611111111111,decimalLongitude:-79.9486111111111},{verbatimCoordinates:"40:26:46.302N 79:56:55.903W",verbatimLatitude:"40:26:46.302N",verbatimLongitude:"79:56:55.903W",decimalLatitude:40.446195,decimalLongitude:-79.94886194444445},{verbatimCoordinates:"40\xb026\u203247\u2033N 79\xb058\u203236\u2033W",verbatimLatitude:"40\xb026\u203247\u2033N",verbatimLongitude:"79\xb058\u203236\u2033W",decimalLatitude:40.44638888888889,decimalLongitude:-79.97666666666667},{verbatimCoordinates:"40d 26\u2032 47\u2033 N 79d 58\u2032 36\u2033 W",verbatimLatitude:"40d 26\u2032 47\u2033 N",verbatimLongitude:"79d 58\u2032 36\u2033 W",decimalLatitude:40.44638888888889,decimalLongitude:-79.97666666666667},{verbatimCoordinates:"40.446195N 79.948862W",verbatimLatitude:"40.446195N",verbatimLongitude:"79.948862W",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40,446195\xb0 79,948862\xb0",verbatimLatitude:"40,446195\xb0",verbatimLongitude:"79,948862\xb0",decimalLatitude:40.446195,decimalLongitude:79.948862},{verbatimCoordinates:"40\xb0 26.7717, -79\xb0 56.93172",verbatimLatitude:"40\xb0 26.7717",verbatimLongitude:"-79\xb0 56.93172",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40.446195, -79.948862",verbatimLatitude:"40.446195",verbatimLongitude:"-79.948862",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"40.123256; -74.123256",verbatimLatitude:"40.123256",verbatimLongitude:"-74.123256",decimalLatitude:40.123256,decimalLongitude:-74.123256},{verbatimCoordinates:"18\xb024S 22\xb045E",verbatimLatitude:"18\xb024S",verbatimLongitude:"22\xb045E",decimalLatitude:-18.4,decimalLongitude:22.75},{verbatimCoordinates:"18.24S 22.45E",verbatimLatitude:"18.24S",verbatimLongitude:"22.45E",decimalLatitude:-18.4,decimalLongitude:22.75},{verbatimCoordinates:"27deg 15min 45.2sec S 18deg 32min 53.7sec E",verbatimLatitude:"27deg 15min 45.2sec S",verbatimLongitude:"18deg 32min 53.7sec E",decimalLatitude:-27.262555555555554,decimalLongitude:18.54825},{verbatimCoordinates:"-23.3245\xb0 S / 28.2344\xb0 E",verbatimLatitude:"-23.3245\xb0 S",verbatimLongitude:"28.2344\xb0 E",decimalLatitude:-23.3245,decimalLongitude:28.2344},{verbatimCoordinates:"40\xb0 26.7717 -79\xb0 56.93172",verbatimLatitude:"40\xb0 26.7717",verbatimLongitude:"-79\xb0 56.93172",decimalLatitude:40.446195,decimalLongitude:-79.948862},{verbatimCoordinates:"27.15.45S 18.32.53E",verbatimLatitude:"27.15.45S",verbatimLongitude:"18.32.53E",decimalLatitude:-27.2625,decimalLongitude:18.548055},{verbatimCoordinates:"S23.43563 \xb0 E22.45634 \xb0",verbatimLatitude:"S23.43563 \xb0",verbatimLongitude:"E22.45634 \xb0",decimalLatitude:-23.43563,decimalLongitude:22.45634},{verbatimCoordinates:"27,71372\xb0 S 23,07771\xb0 E",verbatimLatitude:"27,71372\xb0 S",verbatimLongitude:"23,07771\xb0 E",decimalLatitude:-27.71372,decimalLongitude:23.07771}]).map(t=>t.verbatimCoordinates);return i.formats=l,i});
package/converter.js CHANGED
@@ -235,7 +235,7 @@ function converter(coordsString, decimalPlaces) {
235
235
  }
236
236
 
237
237
  //just to be safe check latitude also...
238
- if (Math.abs(ddLng) >= 90) {
238
+ if (Math.abs(ddLat) >= 90) {
239
239
  throw new Error("invalid latitude value")
240
240
  }
241
241
 
@@ -309,13 +309,13 @@ function converter(coordsString, decimalPlaces) {
309
309
  }
310
310
 
311
311
  }
312
-
313
- //all done!!
314
- //just truncate the decimals appropriately
312
+
315
313
  if(isNaN(ddLat) && ddLat.includes(',')) {
316
314
  ddLat = ddLat.replace(',', '.')
317
315
  }
318
316
 
317
+ //all done!!
318
+ //just truncate the decimals appropriately
319
319
  ddLat = Number(Number(ddLat).toFixed(decimalPlaces))
320
320
 
321
321
  if(isNaN(ddLng) && ddLng.includes(',')) {
@@ -359,20 +359,24 @@ function checkMatch(match) { //test if the matched groups arrays are 'balanced'.
359
359
  }
360
360
 
361
361
  //regex for testing corresponding values match
362
- var numerictest = /^[-+]?\d+([\.,]{}\d+)?$/; //for testing numeric values
363
- var stringtest = /[A-Za-z]+/; //for testing string values (north, south, etc)
362
+ var numerictest = /^[-+]?\d+([\.,]{1}\d+)?$/; //for testing numeric values
363
+ var stringtest = /[eastsouthnorthwest]+/i; //for testing string values (north, south, etc)
364
364
 
365
365
 
366
366
  var halflen = filteredMatch.length/2;
367
- var result = true;
368
367
  for (var i = 0; i < halflen; i++) {
369
- if (numerictest.test(filteredMatch[i]) != numerictest.test(filteredMatch[i + halflen]) || stringtest.test(filteredMatch[i]) != stringtest.test(filteredMatch[i + halflen])) {
370
- result = false;
371
- break;
368
+ const leftside = filteredMatch[i]
369
+ const rightside = filteredMatch[i + halflen]
370
+ if ((numerictest.test(leftside) && numerictest.test(rightside)) || (stringtest.test(leftside) && stringtest.test(rightside)) || leftside == rightside) {
371
+ continue;
372
+ }
373
+ else {
374
+ return false
372
375
  }
373
376
  }
374
377
 
375
- return result;
378
+ return true;
379
+
376
380
  }
377
381
 
378
382
  //functions for coordinate validation
@@ -405,11 +409,16 @@ function coordsCloseEnough(coordsToTest) {
405
409
  }
406
410
 
407
411
  //Coordinates pattern matching regex
412
+
413
+ //decimal degrees
408
414
  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
+
409
416
  //degrees minutes seconds with '.' as separator - gives array with 15 values
410
- 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;
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;
418
+
411
419
  //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
412
420
  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;
421
+
413
422
  //everything else - gives array of 17 values
414
423
  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;
415
424
 
@@ -420,4 +429,4 @@ const to = Object.freeze({
420
429
 
421
430
  converter.to = to
422
431
 
423
- module.exports = converter
432
+ module.exports = converter
package/failFormats.js CHANGED
@@ -2,8 +2,11 @@
2
2
 
3
3
  const failingFormats = [
4
4
  '50°4\'17.698"south, 24.34532', //different formats on each side
5
- '90°4\'17.698"south, 23°4\'17.698"east',
6
- '50°4\'17.698"east, 23°4\'17.698"south',
5
+ '90°4\'17.698"south, 23°4\'17.698"east', //latitude out of bounds
6
+ '89°4\'17.698"south, 183°4\'17.698"east', //longitude out of bounds
7
+ '50°4\'17.698"east, 23°4\'17.698"south', //directions wrong way round
8
+ 'E23.34355,S25.324234', // directions wrong way round
9
+ '23°45\'12.2\'\'S 18.33\'56.7\'\'E', //symbols don't match
7
10
  ]
8
11
 
9
12
  module.exports = failingFormats
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geo-coordinates-parser",
3
- "version": "1.5.1",
3
+ "version": "1.5.4",
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 = '27,71372° S 23,07771° E'
2
+ const test = '27.45.34 S 23.23.23 E'
3
3
 
4
4
  try{
5
5
  let converted = convert(test)
package/testformats.js CHANGED
@@ -286,6 +286,20 @@ var otherFormats = [
286
286
  verbatimLongitude: '23,07771° E',
287
287
  decimalLatitude: -27.71372,
288
288
  decimalLongitude: 23.07771
289
+ },
290
+ {
291
+ verbatimCoordinates: '27.45.34 S 23.23.23 E',
292
+ verbatimLatitude: '27.45.34 S',
293
+ verbatimLongitude: '23.23.23 E',
294
+ decimalLatitude: -27.759444,
295
+ decimalLongitude: 23.38972222
296
+ },
297
+ {
298
+ verbatimCoordinates: 'S 27.45.34 E 23.23.23',
299
+ verbatimLatitude: 'S 27.45.34',
300
+ verbatimLongitude: 'E 23.23.23',
301
+ decimalLatitude: -27.759444,
302
+ decimalLongitude: 23.38972222
289
303
  }
290
304
  ]
291
305