UNPKG

dms-conversion

Version:

A JavaScript library for converting between decimal degrees and degrees, minutes, and seconds (DMS).

1 lines 2.41 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.dms=e():t.dms=e()}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>i});var r=/^(-?\d+(?:\.\d+)?)[°:d]?\s?(?:(\d+(?:\.\d+)?)['′ʹ:]?\s?(?:(\d+(?:\.\d+)?)["″ʺ]?)?)?\s?([NSEW])?/i;function n(t){return t>0?Math.floor(t):Math.ceil(t)}var o=function(){function t(t,e){this._dd=t,this._hemisphere=/^[WE]|(?:lon)/i.test(e)?t<0?"W":"E":t<0?"S":"N"}return Object.defineProperty(t.prototype,"dd",{get:function(){return this._dd},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hemisphere",{get:function(){return this._hemisphere},enumerable:!1,configurable:!0}),t.prototype.getDmsArray=function(){return this.dmsArray},Object.defineProperty(t.prototype,"dmsArray",{get:function(){var t=Math.abs(this._dd),e=n(t),r=n(60*(t-e));return[e,r,(t-e-r/60)*Math.pow(60,2),this._hemisphere]},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){var e=isNaN(Number(t))?this.dmsArray[2]:this.dmsArray[2].toFixed(t);return"".concat(this.dmsArray[0],"°").concat(this.dmsArray[1],"′").concat(e,"″ ").concat(this.dmsArray[3])},t}();const i=function(){function t(t,e){if(this.lat=t,this.lon=e,"number"!=typeof t||"number"!=typeof e)throw TypeError("The longitude and latitude parameters must be numbers.");if(isNaN(e)||e<-180||e>180)throw RangeError("longitude must be between -180 and 180");if(isNaN(t)||t<-90||t>90)throw RangeError("latitude must be between -90 and 90");this._longitude=new o(e,"long"),this._latitude=new o(t,"lat")}return Object.defineProperty(t.prototype,"longitude",{get:function(){return this._longitude},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"latitude",{get:function(){return this._latitude},enumerable:!1,configurable:!0}),t.prototype.getDmsArrays=function(){return this.dmsArrays},Object.defineProperty(t.prototype,"dmsArrays",{get:function(){return{longitude:this.longitude.dmsArray,latitude:this.latitude.dmsArray}},enumerable:!1,configurable:!0}),t.prototype.toString=function(t){return[this.latitude,this.longitude].map((function(e){return e.toString(t)})).join(", ")},t.dmsRe=r,t}();return e.default})()));