geo-coordinates-parser 1.4.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -1
- package/bundle/geocoordsparser.js +1 -1
- package/bundle/workflow.txt +2 -4
- package/conf.py +3 -0
- package/converter.js +28 -17
- package/failFormats.js +11 -0
- package/geocoordsparser.js +0 -0
- package/makeTestFormatsJSON.js +11 -0
- package/package.json +1 -1
- package/test.js +22 -9
- package/testFormats.json +303 -0
- package/testformats.js +16 -19
package/README.md
CHANGED
@@ -76,7 +76,8 @@ convert.formats
|
|
76
76
|
**<span style="color:red">Note that formats like 24.56S 26.48E are treated as degrees and minutes! And 24.0, 26.0 is treated as an error. If you don't want this behaviour you need to catch these cases with your own code before you use convert.</span>**
|
77
77
|
|
78
78
|
### Want to use it in the browser?
|
79
|
-
|
79
|
+
Add ```<script src="https://cdn.jsdelivr.net/npm/geo-coordinates-parser/bundle/geocoordsparser.js"></script>```
|
80
|
+
to your html head and you'll have the ```convert``` function available globally. You won't have .formats, .closeEnough or .toCoordinateFormat though, only the coordinates conversion function.
|
80
81
|
|
81
82
|
### Convert back to standard formats
|
82
83
|
Sometimes we might want to convert back to more traditional formats for representing coordinates, such as DMS or DM. This can be useful for standardizing coordinates. The convert function has an enum to help.
|
@@ -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});
|
package/bundle/workflow.txt
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
This is to bundle the function to make it available for browsers
|
2
2
|
|
3
|
-
|
3
|
+
browserify -p tinyify ./merge.js --standalone convert > ./bundle/geocoordsparser.js
|
4
4
|
|
5
|
-
|
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
package/converter.js
CHANGED
@@ -120,7 +120,8 @@ function converter(coordsString, decimalPlaces) {
|
|
120
120
|
if(match[1]){
|
121
121
|
latdir = match[1];
|
122
122
|
lngdir = match[9];
|
123
|
-
}
|
123
|
+
}
|
124
|
+
else if (match[8]){
|
124
125
|
latdir = match[8];
|
125
126
|
lngdir = match[16];
|
126
127
|
}
|
@@ -176,6 +177,19 @@ function converter(coordsString, decimalPlaces) {
|
|
176
177
|
}
|
177
178
|
}
|
178
179
|
|
180
|
+
if (ddLat == 0.0 || ddLng == 0.0) {
|
181
|
+
throw new Error('zero coordinate/s provided')
|
182
|
+
}
|
183
|
+
|
184
|
+
//some more validation: no zero coords or degrees only
|
185
|
+
if (Number(Math.round(ddLat)) == Number(ddLat)) {
|
186
|
+
throw new Error('degree only coordinate provided')
|
187
|
+
}
|
188
|
+
|
189
|
+
if (Number(Math.round(ddLng)) == Number(ddLng)) {
|
190
|
+
throw new Error('degree only coordinate provided')
|
191
|
+
}
|
192
|
+
|
179
193
|
//check longitude value - it can be wrong!
|
180
194
|
if (Math.abs(ddLng) >=180) {
|
181
195
|
throw new Error("invalid longitude value")
|
@@ -185,14 +199,18 @@ function converter(coordsString, decimalPlaces) {
|
|
185
199
|
|
186
200
|
//make sure the signs and cardinal directions match
|
187
201
|
var patt = /S|SOUTH/i;
|
188
|
-
if (patt.test(latdir))
|
189
|
-
if (ddLat > 0)
|
202
|
+
if (patt.test(latdir)) {
|
203
|
+
if (ddLat > 0) {
|
190
204
|
ddLat = -1 * ddLat;
|
205
|
+
}
|
206
|
+
}
|
191
207
|
|
192
208
|
patt = /W|WEST/i;
|
193
|
-
if (patt.test(lngdir))
|
194
|
-
if (ddLng > 0)
|
209
|
+
if (patt.test(lngdir)){
|
210
|
+
if (ddLng > 0) {
|
195
211
|
ddLng = -1 * ddLng;
|
212
|
+
}
|
213
|
+
}
|
196
214
|
|
197
215
|
|
198
216
|
//we need to get the verbatim coords from the string
|
@@ -223,7 +241,6 @@ function converter(coordsString, decimalPlaces) {
|
|
223
241
|
middle = (seps.length / 2) - 1
|
224
242
|
}
|
225
243
|
|
226
|
-
|
227
244
|
//walk through seps until we get to the middle
|
228
245
|
var splitIndex = 0;
|
229
246
|
|
@@ -285,27 +302,21 @@ function checkMatch(match) { //test if the matched groups arrays are 'balanced'.
|
|
285
302
|
if(!isNaN(match[0])){ //we've matched a number, not what we want....
|
286
303
|
return false
|
287
304
|
}
|
305
|
+
|
288
306
|
//first remove the empty values from the array
|
289
307
|
var filteredMatch = match.filter(x=>x);
|
290
308
|
|
291
309
|
//we need to shift the array because it contains the whole coordinates string in the first item
|
292
310
|
filteredMatch.shift();
|
293
311
|
|
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
|
312
|
+
//check the array length is an even number else exit
|
302
313
|
if (filteredMatch.length % 2 > 0) {
|
303
314
|
return false;
|
304
315
|
}
|
305
316
|
|
306
317
|
//regex for testing corresponding values match
|
307
|
-
var numerictest = /^[-+]
|
308
|
-
var stringtest = /[A-Za-z]+/; //
|
318
|
+
var numerictest = /^[-+]?\d+([\.,]{}\d+)?$/; //for testing numeric values
|
319
|
+
var stringtest = /[A-Za-z]+/; //for testing string values (north, south, etc)
|
309
320
|
|
310
321
|
|
311
322
|
var halflen = filteredMatch.length/2;
|
@@ -350,7 +361,7 @@ function coordsCloseEnough(coordsToTest) {
|
|
350
361
|
}
|
351
362
|
|
352
363
|
//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;
|
364
|
+
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
365
|
//degrees minutes seconds with '.' as separator - gives array with 15 values
|
355
366
|
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
367
|
//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,11 @@
|
|
1
|
+
//TODO These formats should throw...
|
2
|
+
|
3
|
+
const failingFormats = [
|
4
|
+
'N 52d12m42s E 000d0m0s', //degree only coordinate and zero coordinate
|
5
|
+
'N49 0.000 E02 33.314', //degree only coordinate
|
6
|
+
'0,0', //another zero coordinate, numbers only
|
7
|
+
'0, 24.34532', //zero coordinate on one size only
|
8
|
+
'50°4\'17.698"south, 24.34532', //different formats on each side
|
9
|
+
]
|
10
|
+
|
11
|
+
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.
|
3
|
+
"version": "1.5.0",
|
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
|
-
//
|
7
|
-
|
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")
|
package/testFormats.json
ADDED
@@ -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
@@ -265,27 +265,24 @@ var otherFormats = [
|
|
265
265
|
verbatimLongitude: '18.32.53E',
|
266
266
|
decimalLatitude: -27.2625,
|
267
267
|
decimalLongitude: 18.548055
|
268
|
+
},
|
269
|
+
{
|
270
|
+
verbatimCoordinates: 'S23.43563 ° E22.45634 °', //decimals with spaces before the symbol!!
|
271
|
+
verbatimLatitude: 'S23.43563 °',
|
272
|
+
verbatimLongitude: 'E22.45634 °',
|
273
|
+
decimalLatitude: -23.43563,
|
274
|
+
decimalLongitude: 22.45634
|
275
|
+
},
|
276
|
+
{
|
277
|
+
verbatimCoordinates: '27,71372° S 23,07771° E', //decimals with commas
|
278
|
+
verbatimLatitude: '27,71372° S',
|
279
|
+
verbatimLongitude: '23,07771° E',
|
280
|
+
decimalLatitude: -27.71372,
|
281
|
+
decimalLongitude: 23.07771
|
268
282
|
}
|
269
283
|
]
|
270
284
|
|
271
|
-
|
272
|
-
{
|
273
|
-
//issue https://github.com/ianengelbrecht/geo-coordinates-parser/issues/1
|
274
|
-
verbatimCoordinates: 'N 52d0m0s E 000d0m0s',
|
275
|
-
verbatimLatitude: 'N 52d0m0s',
|
276
|
-
verbatimLongitude: 'E 000d0m0s',
|
277
|
-
decimalLatitude: 52.00000,
|
278
|
-
decimalLongitude: 0.0000
|
279
|
-
},
|
280
|
-
{
|
281
|
-
// https://github.com/ianengelbrecht/geo-coordinates-parser/issues/1
|
282
|
-
verbatimCoordinates: 'N49 0.000 E02 33.314',
|
283
|
-
verbatimLatitude: 'N49 0.000',
|
284
|
-
verbatimLongitude: 'E02 33.314',
|
285
|
-
decimalLatitude: 49.00000,
|
286
|
-
decimalLongitude: 2.5552333333333333
|
287
|
-
}
|
288
|
-
]
|
285
|
+
|
289
286
|
|
290
287
|
function getAllTestFormats() {
|
291
288
|
var arr1 = []
|
@@ -298,7 +295,7 @@ function getAllTestFormats() {
|
|
298
295
|
}
|
299
296
|
})
|
300
297
|
|
301
|
-
return [...arr1, ...coordsRegexFormats, ...otherFormats
|
298
|
+
return [...arr1, ...coordsRegexFormats, ...otherFormats]
|
302
299
|
|
303
300
|
}
|
304
301
|
|