geo-coordinates-parser 1.4.3 → 1.5.1

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,r){const i=Number(t);let a;a=r?i>=0?"N":"S":i>=0?"E":"W";const n=Math.abs(i),o=Math.floor(n),s=60*(n-o);if("DM"==e)return`${o}\xb0 ${s.toFixed(3).replace(/\.0+$/,"")}' ${a}`;const d=Math.floor(s);return`${o}\xb0 ${d}' ${(60*(s-d)).toFixed(1).replace(/\.0$/,"")}" ${a}`}var e=function(e){if(!["DMS","DM"].includes(e))throw new Error("invalid format specified");if(this.decimalCoordinates&&this.decimalCoordinates.trim()){const r=this.decimalCoordinates.split(",").map(t=>t.trim());return`${t(r[0],e,!0)}, ${t(r[1],e,!1)}`}throw new Error("no decimal coordinates to convert")};function r(t,r){r||(r=5),t=t.replace(/\s\s+/g," ").trim();var a=null,l=null,f="",c="",E=[],S=!1;if(o.test(t)){if(!(S=i(E=o.exec(t))))throw new Error("invalid decimal coordinate format");a=E[2],l=E[6],a.includes(",")&&(a=a.replace(",",".")),l.includes(",")&&(l=l.replace(",",".")),E[1]?(f=E[1],c=E[5]):E[4]&&(f=E[4],c=E[8])}else if(s.test(t)){if(!(S=i(E=s.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(E[2])),E[4]&&(a+=E[4]/60),E[6]&&(a+=E[6]/3600),parseInt(E[2])<0&&(a*=-1),l=Math.abs(parseInt(E[9])),E[11]&&(l+=E[11]/60),E[13]&&(l+=E[13]/3600),parseInt(E[9])<0&&(l*=-1),E[1]?(f=E[1],c=E[8]):E[7]&&(f=E[7],c=E[14])}else if(d.test(t)){if(!(S=i(E=d.exec(t))))throw new Error("invalid DMS coordinates format");a=Math.abs(parseInt(E[2])),E[4]&&(a+=E[4]/60,E[3]||(E[3]=" ")),E[6]&&(a+=E[6]/3600,E[5]||(E[5]=" ")),parseInt(E[2])<0&&(a*=-1),l=Math.abs(parseInt(E[10])),E[12]&&(l+=E[12]/60,E[11]||(E[11]=" ")),E[14]&&(l+=E[14]/3600,E[13]||(E[13]=" ")),parseInt(E[10])<0&&(l*=-1),E[1]?(f=E[1],c=E[9]):E[8]&&(f=E[8],c=E[16])}else if(u.test(t)){if(!(S=i(E=u.exec(t))))throw new Error("invalid coordinates format");a=Math.abs(parseInt(E[2])),E[4]&&(a+=E[4]/60,E[3]||(E[3]=" ")),E[6]&&(a+=E[6]/3600,E[5]||(E[5]=" ")),parseInt(E[2])<0&&(a*=-1),l=Math.abs(parseInt(E[10])),E[12]&&(l+=E[12]/60,E[11]||(E[11]=" ")),E[14]&&(l+=E[14]/3600,E[13]||(E[13]=" ")),parseInt(E[10])<0&&(l*=-1),E[1]?(f=E[1],c=E[9]):E[8]&&(f=E[8],c=E[16])}if(Math.abs(l)>=180)throw new Error("invalid longitude value");if(S){var b=/S|SOUTH/i;b.test(f)&&a>0&&(a*=-1),(b=/W|WEST/i).test(c)&&l>0&&(l*=-1);var m,N,h=E[0].trim(),T=h.match(/[,/;\u0020]/g);if(null==T){var p=Math.floor(t.length/2);m=h.substring(0,p).trim(),N=h.substring(p).trim()}else{var x=0;if(0==(p=T.length%2==1?Math.floor(T.length/2):T.length/2-1))x=h.indexOf(T[0]),m=h.substring(0,x).trim(),N=h.substring(x+1).trim();else{for(var M=0,v=0;M<=p;)v=(x=h.indexOf(T[M],v))+1,M++;m=h.substring(0,x).trim(),N=h.substring(x+1).trim()}}return isNaN(a)&&a.includes(",")&&(a=a.replace(",",".")),a=Number(Number(a).toFixed(r)),isNaN(l)&&l.includes(",")&&(l=l.replace(",",".")),l=Number(Number(l).toFixed(r)),Object.freeze({verbatimCoordinates:h,verbatimLatitude:m,verbatimLongitude:N,decimalLatitude:a,decimalLongitude:l,decimalCoordinates:`${a},${l}`,closeEnough:n,toCoordinateFormat:e})}throw new Error("coordinates pattern match failed")}function i(t){if(!isNaN(t[0]))return!1;var e=t.filter(t=>t);if(e.shift(),e.length%2>0)return!1;for(var r=/^[-+]?(\d+|\d+\.\d*|\d*\.\d+)$/,i=/[A-Za-z]+/,a=e.length/2,n=!0,o=0;o<a;o++)if(r.test(e[o])!=r.test(e[o+a])||i.test(e[o])!=i.test(e[o+a])){n=!1;break}return n}function a(t,e){var r=Math.abs(t-e);return diff=Number(r.toFixed(6)),diff<=1e-5}function n(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 a(this.decimalLatitude,Number(e[0]))&&a(this.decimalLongitude,e[1])}throw new Error("coords being tested must be separated by a comma")}var o=/(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))([\u2022\xba\xb0]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))([\u2022\xba\xb0]?)[\s]*(EAST|WEST|[EW])?/i,s=/(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,d=/(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,u=/(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 l=Object.freeze({DMS:"DMS",DM:"DM"});return r.to=l,r});
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,10 +1,8 @@
1
1
  This is to bundle the function to make it available for browsers
2
2
 
3
- Inside /bundle run the following
3
+ browserify -p tinyify ./merge.js --standalone convert > ./bundle/geocoordsparser.js
4
4
 
5
- browserify -p tinyify ../converter.js --standalone convert > geocoordsparser.js
6
-
7
- Then npm publish
5
+ Then update version in package.json, then npm publish, then git...
8
6
 
9
7
  geocoordsparser.js can then be included in <script> tags
10
8
  This puts a function called convert into the global environment
package/conf.py ADDED
@@ -0,0 +1,3 @@
1
+ def converter(coordsString, decimalPlaces):
2
+ if decimalPlaces == None:
3
+ decimalPlaces = 5
package/converter.js CHANGED
@@ -38,12 +38,24 @@ function converter(coordsString, decimalPlaces) {
38
38
  if(ddLng.includes(',')) {
39
39
  ddLng = ddLng.replace(',', '.');
40
40
  }
41
+
42
+ //validation, we don't want things like 23.00000
43
+
44
+ //some more validation: no zero coords or degrees only
45
+ if (Number(Math.round(ddLat)) == Number(ddLat)) {
46
+ throw new Error('degree only coordinate provided')
47
+ }
48
+
49
+ if (Number(Math.round(ddLng)) == Number(ddLng)) {
50
+ throw new Error('degree only coordinate provided')
51
+ }
41
52
 
42
53
  //get directions
43
- if(match[1]){
54
+ if(match[1]) {
44
55
  latdir = match[1];
45
56
  lngdir = match[5];
46
- } else if (match[4]){
57
+ }
58
+ else if (match[4]) {
47
59
  latdir = match[4];
48
60
  lngdir = match[8];
49
61
  }
@@ -58,25 +70,41 @@ function converter(coordsString, decimalPlaces) {
58
70
  match = dms_periods.exec(coordsString);
59
71
  matchSuccess = checkMatch(match);
60
72
  if (matchSuccess){
73
+
61
74
  ddLat = Math.abs(parseInt(match[2]));
62
- if (match[4])
75
+
76
+ if (match[4]) {
63
77
  ddLat += match[4]/60;
64
- if (match[6])
78
+ }
79
+
80
+ if (match[6]){
65
81
  ddLat += match[6]/3600;
66
- if (parseInt(match[2]) < 0) //needed to
82
+ }
83
+
84
+ if (parseInt(match[2]) < 0) {
67
85
  ddLat = -1 * ddLat;
86
+ }
87
+
68
88
  ddLng = Math.abs(parseInt(match[9]));
69
- if (match[11])
89
+
90
+ if (match[11]) {
70
91
  ddLng += match[11]/60;
71
- if (match[13])
92
+ }
93
+
94
+ if (match[13]) {
72
95
  ddLng += match[13]/3600;
73
- if (parseInt(match[9]) < 0) //needed to
96
+ }
97
+
98
+ if (parseInt(match[9]) < 0) {
74
99
  ddLng = -1 * ddLng;
75
-
76
- if(match[1]){
100
+ }
101
+
102
+ //the compass directions
103
+ if(match[1]) {
77
104
  latdir = match[1];
78
105
  lngdir = match[8];
79
- } else if (match[7]){
106
+ }
107
+ else if (match[7]) {
80
108
  latdir = match[7];
81
109
  lngdir = match[14];
82
110
  }
@@ -89,38 +117,52 @@ function converter(coordsString, decimalPlaces) {
89
117
  else if (dms_abbr.test(coordsString)) {
90
118
  match = dms_abbr.exec(coordsString);
91
119
  matchSuccess = checkMatch(match);
92
- if (matchSuccess){
120
+
121
+ if (matchSuccess) {
93
122
  ddLat = Math.abs(parseInt(match[2]));
94
- if (match[4]){
123
+ if (match[4]) {
95
124
  ddLat += match[4]/60;
96
- if(!match[3])
125
+ if(!match[3]) {
97
126
  match[3] = ' ';
127
+ }
98
128
  }
129
+
99
130
  if (match[6]) {
100
131
  ddLat += match[6]/3600;
101
- if(!match[5])
132
+ if(!match[5]) {
102
133
  match[5] = ' ';
134
+ }
103
135
  }
104
- if (parseInt(match[2]) < 0)
136
+
137
+ if (parseInt(match[2]) < 0) {
105
138
  ddLat = -1 * ddLat;
139
+ }
140
+
106
141
  ddLng = Math.abs(parseInt(match[10]));
107
- if (match[12]){
142
+
143
+ if (match[12]) {
108
144
  ddLng += match[12]/60;
109
- if(!match[11])
145
+ if(!match[11]) {
110
146
  match[11] = ' ';
147
+ }
111
148
  }
112
- if (match[14]){
149
+
150
+ if (match[14]) {
113
151
  ddLng += match[14]/3600;
114
- if(!match[13])
152
+ if(!match[13]) {
115
153
  match[13] = ' ';
154
+ }
116
155
  }
117
- if (parseInt(match[10]) < 0)
156
+
157
+ if (parseInt(match[10]) < 0) {
118
158
  ddLng = -1 * ddLng;
159
+ }
119
160
 
120
- if(match[1]){
161
+ if(match[1]) {
121
162
  latdir = match[1];
122
163
  lngdir = match[9];
123
- } else if (match[8]){
164
+ }
165
+ else if (match[8]) {
124
166
  latdir = match[8];
125
167
  lngdir = match[16];
126
168
  }
@@ -133,39 +175,50 @@ function converter(coordsString, decimalPlaces) {
133
175
  else if (coords_other.test(coordsString)) {
134
176
  match = coords_other.exec(coordsString);
135
177
  matchSuccess = checkMatch(match);
136
- if (matchSuccess){
178
+
179
+ if (matchSuccess) {
137
180
  ddLat = Math.abs(parseInt(match[2]));
138
181
  if (match[4]){
139
182
  ddLat += match[4]/60;
140
- if(!match[3])
183
+ if(!match[3]) {
141
184
  match[3] = ' ';
185
+ }
142
186
  }
187
+
143
188
  if (match[6]) {
144
189
  ddLat += match[6]/3600;
145
- if(!match[5])
190
+ if(!match[5]) {
146
191
  match[5] = ' ';
192
+ }
147
193
  }
148
- if (parseInt(match[2]) < 0)
194
+
195
+ if (parseInt(match[2]) < 0) {
149
196
  ddLat = -1 * ddLat;
197
+ }
150
198
 
151
199
  ddLng = Math.abs(parseInt(match[10]));
152
- if (match[12]){
200
+ if (match[12]) {
153
201
  ddLng += match[12]/60;
154
- if(!match[11])
202
+ if(!match[11]) {
155
203
  match[11] = ' ';
204
+ }
156
205
  }
157
- if (match[14]){
206
+
207
+ if (match[14]) {
158
208
  ddLng += match[14]/3600;
159
- if(!match[13])
209
+ if(!match[13]) {
160
210
  match[13] = ' ';
211
+ }
161
212
  }
162
- if (parseInt(match[10]) < 0)
213
+
214
+ if (parseInt(match[10]) < 0) {
163
215
  ddLng = -1 * ddLng;
164
-
165
- if(match[1]){
216
+ }
217
+
218
+ if(match[1]) {
166
219
  latdir = match[1];
167
220
  lngdir = match[9];
168
- } else if (match[8]){
221
+ } else if (match[8]) {
169
222
  latdir = match[8];
170
223
  lngdir = match[16];
171
224
  }
@@ -177,22 +230,31 @@ function converter(coordsString, decimalPlaces) {
177
230
  }
178
231
 
179
232
  //check longitude value - it can be wrong!
180
- if (Math.abs(ddLng) >=180) {
233
+ if (Math.abs(ddLng) >= 180) {
181
234
  throw new Error("invalid longitude value")
182
235
  }
236
+
237
+ //just to be safe check latitude also...
238
+ if (Math.abs(ddLng) >= 90) {
239
+ throw new Error("invalid latitude value")
240
+ }
183
241
 
184
242
  if (matchSuccess){
185
243
 
186
244
  //make sure the signs and cardinal directions match
187
245
  var patt = /S|SOUTH/i;
188
- if (patt.test(latdir))
189
- if (ddLat > 0)
246
+ if (patt.test(latdir)) {
247
+ if (ddLat > 0) {
190
248
  ddLat = -1 * ddLat;
249
+ }
250
+ }
191
251
 
192
252
  patt = /W|WEST/i;
193
- if (patt.test(lngdir))
194
- if (ddLng > 0)
253
+ if (patt.test(lngdir)){
254
+ if (ddLng > 0) {
195
255
  ddLng = -1 * ddLng;
256
+ }
257
+ }
196
258
 
197
259
 
198
260
  //we need to get the verbatim coords from the string
@@ -223,7 +285,6 @@ function converter(coordsString, decimalPlaces) {
223
285
  middle = (seps.length / 2) - 1
224
286
  }
225
287
 
226
-
227
288
  //walk through seps until we get to the middle
228
289
  var splitIndex = 0;
229
290
 
@@ -285,27 +346,21 @@ function checkMatch(match) { //test if the matched groups arrays are 'balanced'.
285
346
  if(!isNaN(match[0])){ //we've matched a number, not what we want....
286
347
  return false
287
348
  }
349
+
288
350
  //first remove the empty values from the array
289
351
  var filteredMatch = match.filter(x=>x);
290
352
 
291
353
  //we need to shift the array because it contains the whole coordinates string in the first item
292
354
  filteredMatch.shift();
293
355
 
294
- /*
295
- //if minutes or seconds are out of bounds, the array length is wrong
296
- if (filteredMatch.length == 4) {
297
- return false
298
- }
299
- */
300
-
301
- //then check the array length is an even number else exit
356
+ //check the array length is an even number else exit
302
357
  if (filteredMatch.length % 2 > 0) {
303
358
  return false;
304
359
  }
305
360
 
306
361
  //regex for testing corresponding values match
307
- var numerictest = /^[-+]?(\d+|\d+\.\d*|\d*\.\d+)$/; //for testing numeric values
308
- var stringtest = /[A-Za-z]+/; //strings - the contents of strings are already matched when this is used
362
+ var numerictest = /^[-+]?\d+([\.,]{}\d+)?$/; //for testing numeric values
363
+ var stringtest = /[A-Za-z]+/; //for testing string values (north, south, etc)
309
364
 
310
365
 
311
366
  var halflen = filteredMatch.length/2;
@@ -350,7 +405,7 @@ function coordsCloseEnough(coordsToTest) {
350
405
  }
351
406
 
352
407
  //Coordinates pattern matching regex
353
- var dd_re = /(NORTH|SOUTH|[NS])?[\s]*([+-]?[0-8]?[0-9](?:[\.,]\d{3,}))([•º°]?)[\s]*(NORTH|SOUTH|[NS])?[\s]*[,/;]?[\s]*(EAST|WEST|[EW])?[\s]*([+-]?[0-1]?[0-9]?[0-9](?:[\.,]\d{3,}))([•º°]?)[\s]*(EAST|WEST|[EW])?/i;
408
+ 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;
354
409
  //degrees minutes seconds with '.' as separator - gives array with 15 values
355
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;
356
411
  //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
package/failFormats.js ADDED
@@ -0,0 +1,9 @@
1
+ //TODO These formats should throw...
2
+
3
+ const failingFormats = [
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',
7
+ ]
8
+
9
+ module.exports = failingFormats
File without changes
@@ -0,0 +1,11 @@
1
+ const fs = require('fs');
2
+ const testFormats = require('./testformats')
3
+
4
+ fs.writeFile("testFormats.json", JSON.stringify(testFormats, null, 2), 'utf8', function (err) {
5
+ if (err) {
6
+ console.log("An error occured while writing JSON Object to File.");
7
+ return console.log(err);
8
+ }
9
+
10
+ console.log("JSON file has been saved.");
11
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geo-coordinates-parser",
3
- "version": "1.4.3",
3
+ "version": "1.5.1",
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/test.js CHANGED
@@ -1,11 +1,11 @@
1
1
  const convert = require('./converter')
2
2
  const testFormats = require('./testformats')
3
+ const failingFormats = require('./failFormats')
3
4
 
4
5
  let allPassed = true;
5
6
 
6
- //find the first one that doesn't work
7
- testFormats.some(t => { //.some so we can break
8
-
7
+ //FORMATS THAT SHOULD BE CONVERTED
8
+ for (const t of testFormats) {
9
9
  try {
10
10
  var converted = convert(t.verbatimCoordinates, 8)
11
11
 
@@ -18,7 +18,6 @@ testFormats.some(t => { //.some so we can break
18
18
  console.log(t.decimalLatitude)
19
19
  console.log(t.decimalLongitude)
20
20
  allPassed = false;
21
- return true;
22
21
  }
23
22
 
24
23
 
@@ -29,20 +28,34 @@ testFormats.some(t => { //.some so we can break
29
28
  console.log('got', converted.verbatimLatitude, 'should be ', t.verbatimLatitude)
30
29
  console.log('got', converted.verbatimLongitude, 'should be', t.verbatimLongitude)
31
30
  allPassed = false;
32
- return true
33
31
  }
34
32
 
35
-
36
33
  }
37
34
  catch(err) {
38
35
  console.log("Failed to convert the following format")
39
36
  console.log(t.verbatimCoordinates)
40
37
  console.log(err.message)
41
38
  allPassed = false;
42
- return true;
43
39
  }
44
-
45
- })
40
+ }
41
+
42
+
43
+ //FORMATS THAT SHOULD NOT BE CONVERTED
44
+ const converting = []
45
+ for (const f of failingFormats) {
46
+ try {
47
+ let converted = convert(f)
48
+ converting.push(f)
49
+ allPassed = false
50
+ }
51
+ catch {
52
+ //nothing here
53
+ }
54
+ }
55
+
56
+ if(converting.length) {
57
+ console.log("The following coordinates should NOT have converted successfully: " + converting.join(' | '))
58
+ }
46
59
 
47
60
  if (allPassed) {
48
61
  console.log("all formats successfully converted")
@@ -0,0 +1,303 @@
1
+ [
2
+ {
3
+ "verbatimCoordinates": "40.123, -74.123",
4
+ "verbatimLatitude": "40.123",
5
+ "verbatimLongitude": "-74.123",
6
+ "decimalLatitude": 40.123,
7
+ "decimalLongitude": -74.123
8
+ },
9
+ {
10
+ "verbatimCoordinates": "40.123° N 74.123° W",
11
+ "verbatimLatitude": "40.123° N",
12
+ "verbatimLongitude": "74.123° W",
13
+ "decimalLatitude": 40.123,
14
+ "decimalLongitude": -74.123
15
+ },
16
+ {
17
+ "verbatimCoordinates": "40.123° N 74.123° W",
18
+ "verbatimLatitude": "40.123° N",
19
+ "verbatimLongitude": "74.123° W",
20
+ "decimalLatitude": 40.123,
21
+ "decimalLongitude": -74.123
22
+ },
23
+ {
24
+ "verbatimCoordinates": "40° 7´ 22.8\" N 74° 7´ 22.8\" W",
25
+ "verbatimLatitude": "40° 7´ 22.8\" N",
26
+ "verbatimLongitude": "74° 7´ 22.8\" W",
27
+ "decimalLatitude": 40.123,
28
+ "decimalLongitude": -74.123
29
+ },
30
+ {
31
+ "verbatimCoordinates": "40° 7.38’ , -74° 7.38’",
32
+ "verbatimLatitude": "40° 7.38’",
33
+ "verbatimLongitude": "-74° 7.38’",
34
+ "decimalLatitude": 40.123,
35
+ "decimalLongitude": -74.123
36
+ },
37
+ {
38
+ "verbatimCoordinates": "N40°7’22.8’’, W74°7’22.8’’",
39
+ "verbatimLatitude": "N40°7’22.8’’",
40
+ "verbatimLongitude": "W74°7’22.8’’",
41
+ "decimalLatitude": 40.123,
42
+ "decimalLongitude": -74.123
43
+ },
44
+ {
45
+ "verbatimCoordinates": "40°7’22.8\"N, 74°7’22.8\"W",
46
+ "verbatimLatitude": "40°7’22.8\"N",
47
+ "verbatimLongitude": "74°7’22.8\"W",
48
+ "decimalLatitude": 40.123,
49
+ "decimalLongitude": -74.123
50
+ },
51
+ {
52
+ "verbatimCoordinates": "40°7'22.8\"N, 74°7'22.8\"W",
53
+ "verbatimLatitude": "40°7'22.8\"N",
54
+ "verbatimLongitude": "74°7'22.8\"W",
55
+ "decimalLatitude": 40.123,
56
+ "decimalLongitude": -74.123
57
+ },
58
+ {
59
+ "verbatimCoordinates": "40 7 22.8, -74 7 22.8",
60
+ "verbatimLatitude": "40 7 22.8",
61
+ "verbatimLongitude": "-74 7 22.8",
62
+ "decimalLatitude": 40.123,
63
+ "decimalLongitude": -74.123
64
+ },
65
+ {
66
+ "verbatimCoordinates": "40.123 -74.123",
67
+ "verbatimLatitude": "40.123",
68
+ "verbatimLongitude": "-74.123",
69
+ "decimalLatitude": 40.123,
70
+ "decimalLongitude": -74.123
71
+ },
72
+ {
73
+ "verbatimCoordinates": "40.123°,-74.123°",
74
+ "verbatimLatitude": "40.123°",
75
+ "verbatimLongitude": "-74.123°",
76
+ "decimalLatitude": 40.123,
77
+ "decimalLongitude": -74.123
78
+ },
79
+ {
80
+ "verbatimCoordinates": "40.123N74.123W",
81
+ "verbatimLatitude": "40.123N",
82
+ "verbatimLongitude": "74.123W",
83
+ "decimalLatitude": 40.123,
84
+ "decimalLongitude": -74.123
85
+ },
86
+ {
87
+ "verbatimCoordinates": "4007.38N7407.38W",
88
+ "verbatimLatitude": "4007.38N",
89
+ "verbatimLongitude": "7407.38W",
90
+ "decimalLatitude": 40.123,
91
+ "decimalLongitude": -74.123
92
+ },
93
+ {
94
+ "verbatimCoordinates": "40°7’22.8\"N, 74°7’22.8\"W",
95
+ "verbatimLatitude": "40°7’22.8\"N",
96
+ "verbatimLongitude": "74°7’22.8\"W",
97
+ "decimalLatitude": 40.123,
98
+ "decimalLongitude": -74.123
99
+ },
100
+ {
101
+ "verbatimCoordinates": "400722.8N740722.8W",
102
+ "verbatimLatitude": "400722.8N",
103
+ "verbatimLongitude": "740722.8W",
104
+ "decimalLatitude": 40.123,
105
+ "decimalLongitude": -74.123
106
+ },
107
+ {
108
+ "verbatimCoordinates": "N 40 7.38 W 74 7.38",
109
+ "verbatimLatitude": "N 40 7.38",
110
+ "verbatimLongitude": "W 74 7.38",
111
+ "decimalLatitude": 40.123,
112
+ "decimalLongitude": -74.123
113
+ },
114
+ {
115
+ "verbatimCoordinates": "40:7:22.8N 74:7:22.8W",
116
+ "verbatimLatitude": "40:7:22.8N",
117
+ "verbatimLongitude": "74:7:22.8W",
118
+ "decimalLatitude": 40.123,
119
+ "decimalLongitude": -74.123
120
+ },
121
+ {
122
+ "verbatimCoordinates": "40:7:23N,74:7:23W",
123
+ "verbatimLatitude": "40:7:23N",
124
+ "verbatimLongitude": "74:7:23W",
125
+ "decimalLatitude": 40.1230555555,
126
+ "decimalLongitude": -74.1230555555
127
+ },
128
+ {
129
+ "verbatimCoordinates": "40°7’23\"N 74°7’23\"W",
130
+ "verbatimLatitude": "40°7’23\"N",
131
+ "verbatimLongitude": "74°7’23\"W",
132
+ "decimalLatitude": 40.1230555555,
133
+ "decimalLongitude": -74.12305555555555
134
+ },
135
+ {
136
+ "verbatimCoordinates": "40°7’23\" -74°7’23\"",
137
+ "verbatimLatitude": "40°7’23\"",
138
+ "verbatimLongitude": "-74°7’23\"",
139
+ "decimalLatitude": 40.1230555555,
140
+ "decimalLongitude": -74.123055555
141
+ },
142
+ {
143
+ "verbatimCoordinates": "40d 7’ 23\" N 74d 7’ 23\" W",
144
+ "verbatimLatitude": "40d 7’ 23\" N",
145
+ "verbatimLongitude": "74d 7’ 23\" W",
146
+ "decimalLatitude": 40.1230555555,
147
+ "decimalLongitude": -74.123055555
148
+ },
149
+ {
150
+ "verbatimCoordinates": "40.123N 74.123W",
151
+ "verbatimLatitude": "40.123N",
152
+ "verbatimLongitude": "74.123W",
153
+ "decimalLatitude": 40.123,
154
+ "decimalLongitude": -74.123
155
+ },
156
+ {
157
+ "verbatimCoordinates": "40° 7.38, -74° 7.38",
158
+ "verbatimLatitude": "40° 7.38",
159
+ "verbatimLongitude": "-74° 7.38",
160
+ "decimalLatitude": 40.123,
161
+ "decimalLongitude": -74.123
162
+ },
163
+ {
164
+ "verbatimCoordinates": "40° 7.38, -74° 7.38",
165
+ "verbatimLatitude": "40° 7.38",
166
+ "verbatimLongitude": "-74° 7.38",
167
+ "decimalLatitude": 40.123,
168
+ "decimalLongitude": -74.123
169
+ },
170
+ {
171
+ "verbatimCoordinates": "40 7 22.8; -74 7 22.8",
172
+ "verbatimLatitude": "40 7 22.8",
173
+ "verbatimLongitude": "-74 7 22.8",
174
+ "decimalLatitude": 40.123,
175
+ "decimalLongitude": -74.123
176
+ },
177
+ {
178
+ "verbatimCoordinates": "50°4'17.698\"south, 14°24'2.826\"east",
179
+ "verbatimLatitude": "50°4'17.698\"south",
180
+ "verbatimLongitude": "14°24'2.826\"east",
181
+ "decimalLatitude": -50.07158277777778,
182
+ "decimalLongitude": 14.400785
183
+ },
184
+ {
185
+ "verbatimCoordinates": "50d4m17.698S 14d24m2.826E",
186
+ "verbatimLatitude": "50d4m17.698S",
187
+ "verbatimLongitude": "14d24m2.826E",
188
+ "decimalLatitude": -50.07158277777778,
189
+ "decimalLongitude": 14.400785
190
+ },
191
+ {
192
+ "verbatimCoordinates": "40:26:46N,79:56:55W",
193
+ "verbatimLatitude": "40:26:46N",
194
+ "verbatimLongitude": "79:56:55W",
195
+ "decimalLatitude": 40.44611111111111,
196
+ "decimalLongitude": -79.9486111111111
197
+ },
198
+ {
199
+ "verbatimCoordinates": "40:26:46.302N 79:56:55.903W",
200
+ "verbatimLatitude": "40:26:46.302N",
201
+ "verbatimLongitude": "79:56:55.903W",
202
+ "decimalLatitude": 40.446195,
203
+ "decimalLongitude": -79.94886194444445
204
+ },
205
+ {
206
+ "verbatimCoordinates": "40°26′47″N 79°58′36″W",
207
+ "verbatimLatitude": "40°26′47″N",
208
+ "verbatimLongitude": "79°58′36″W",
209
+ "decimalLatitude": 40.44638888888889,
210
+ "decimalLongitude": -79.97666666666667
211
+ },
212
+ {
213
+ "verbatimCoordinates": "40d 26′ 47″ N 79d 58′ 36″ W",
214
+ "verbatimLatitude": "40d 26′ 47″ N",
215
+ "verbatimLongitude": "79d 58′ 36″ W",
216
+ "decimalLatitude": 40.44638888888889,
217
+ "decimalLongitude": -79.97666666666667
218
+ },
219
+ {
220
+ "verbatimCoordinates": "40.446195N 79.948862W",
221
+ "verbatimLatitude": "40.446195N",
222
+ "verbatimLongitude": "79.948862W",
223
+ "decimalLatitude": 40.446195,
224
+ "decimalLongitude": -79.948862
225
+ },
226
+ {
227
+ "verbatimCoordinates": "40,446195° 79,948862°",
228
+ "verbatimLatitude": "40,446195°",
229
+ "verbatimLongitude": "79,948862°",
230
+ "decimalLatitude": 40.446195,
231
+ "decimalLongitude": 79.948862
232
+ },
233
+ {
234
+ "verbatimCoordinates": "40° 26.7717, -79° 56.93172",
235
+ "verbatimLatitude": "40° 26.7717",
236
+ "verbatimLongitude": "-79° 56.93172",
237
+ "decimalLatitude": 40.446195,
238
+ "decimalLongitude": -79.948862
239
+ },
240
+ {
241
+ "verbatimCoordinates": "40.446195, -79.948862",
242
+ "verbatimLatitude": "40.446195",
243
+ "verbatimLongitude": "-79.948862",
244
+ "decimalLatitude": 40.446195,
245
+ "decimalLongitude": -79.948862
246
+ },
247
+ {
248
+ "verbatimCoordinates": "40.123256; -74.123256",
249
+ "verbatimLatitude": "40.123256",
250
+ "verbatimLongitude": "-74.123256",
251
+ "decimalLatitude": 40.123256,
252
+ "decimalLongitude": -74.123256
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
+ },
261
+ {
262
+ "verbatimCoordinates": "27deg 15min 45.2sec S 18deg 32min 53.7sec E",
263
+ "verbatimLatitude": "27deg 15min 45.2sec S",
264
+ "verbatimLongitude": "18deg 32min 53.7sec E",
265
+ "decimalLatitude": -27.262555555555554,
266
+ "decimalLongitude": 18.54825
267
+ },
268
+ {
269
+ "verbatimCoordinates": "-23.3245° S / 28.2344° E",
270
+ "verbatimLatitude": "-23.3245° S",
271
+ "verbatimLongitude": "28.2344° E",
272
+ "decimalLatitude": -23.3245,
273
+ "decimalLongitude": 28.2344
274
+ },
275
+ {
276
+ "verbatimCoordinates": "40° 26.7717 -79° 56.93172",
277
+ "verbatimLatitude": "40° 26.7717",
278
+ "verbatimLongitude": "-79° 56.93172",
279
+ "decimalLatitude": 40.446195,
280
+ "decimalLongitude": -79.948862
281
+ },
282
+ {
283
+ "verbatimCoordinates": "27.15.45S 18.32.53E",
284
+ "verbatimLatitude": "27.15.45S",
285
+ "verbatimLongitude": "18.32.53E",
286
+ "decimalLatitude": -27.2625,
287
+ "decimalLongitude": 18.548055
288
+ },
289
+ {
290
+ "verbatimCoordinates": "S23.43563 ° E22.45634 °",
291
+ "verbatimLatitude": "S23.43563 °",
292
+ "verbatimLongitude": "E22.45634 °",
293
+ "decimalLatitude": -23.43563,
294
+ "decimalLongitude": 22.45634
295
+ },
296
+ {
297
+ "verbatimCoordinates": "27,71372° S 23,07771° E",
298
+ "verbatimLatitude": "27,71372° S",
299
+ "verbatimLongitude": "23,07771° E",
300
+ "decimalLatitude": -27.71372,
301
+ "decimalLongitude": 23.07771
302
+ }
303
+ ]
package/testformats.js CHANGED
@@ -225,7 +225,14 @@ var coordsRegexFormats = [
225
225
  verbatimLongitude: '-74.123256',
226
226
  decimalLatitude: 40.123256,
227
227
  decimalLongitude: -74.123256
228
- }
228
+ },
229
+ {
230
+ verbatimCoordinates: '18°24S 22°45E', //this is read as degrees and minutes
231
+ verbatimLatitude: '18°24S',
232
+ verbatimLongitude: '22°45E',
233
+ decimalLatitude: -18.4,
234
+ decimalLongitude: 22.75
235
+ }
229
236
  ]
230
237
 
231
238
  var otherFormats = [
@@ -266,6 +273,13 @@ var otherFormats = [
266
273
  decimalLatitude: -27.2625,
267
274
  decimalLongitude: 18.548055
268
275
  },
276
+ {
277
+ verbatimCoordinates: 'S23.43563 ° E22.45634 °', //decimals with spaces before the symbol!!
278
+ verbatimLatitude: 'S23.43563 °',
279
+ verbatimLongitude: 'E22.45634 °',
280
+ decimalLatitude: -23.43563,
281
+ decimalLongitude: 22.45634
282
+ },
269
283
  {
270
284
  verbatimCoordinates: '27,71372° S 23,07771° E', //decimals with commas
271
285
  verbatimLatitude: '27,71372° S',
@@ -275,24 +289,7 @@ var otherFormats = [
275
289
  }
276
290
  ]
277
291
 
278
- let userProvidedFormats = [
279
- {
280
- //issue https://github.com/ianengelbrecht/geo-coordinates-parser/issues/1
281
- verbatimCoordinates: 'N 52d0m0s E 000d0m0s',
282
- verbatimLatitude: 'N 52d0m0s',
283
- verbatimLongitude: 'E 000d0m0s',
284
- decimalLatitude: 52.00000,
285
- decimalLongitude: 0.0000
286
- },
287
- {
288
- // https://github.com/ianengelbrecht/geo-coordinates-parser/issues/1
289
- verbatimCoordinates: 'N49 0.000 E02 33.314',
290
- verbatimLatitude: 'N49 0.000',
291
- verbatimLongitude: 'E02 33.314',
292
- decimalLatitude: 49.00000,
293
- decimalLongitude: 2.5552333333333333
294
- }
295
- ]
292
+
296
293
 
297
294
  function getAllTestFormats() {
298
295
  var arr1 = []
@@ -305,7 +302,7 @@ function getAllTestFormats() {
305
302
  }
306
303
  })
307
304
 
308
- return [...arr1, ...coordsRegexFormats, ...otherFormats, ...userProvidedFormats]
305
+ return [...arr1, ...coordsRegexFormats, ...otherFormats]
309
306
 
310
307
  }
311
308