Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geolib

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geolib - npm Package Compare versions

Comparing version 3.0.3 to 3.0.4

2

es/getDistance.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _getLatitude=_interopRequireDefault(require("./getLatitude"));var _getLongitude=_interopRequireDefault(require("./getLongitude"));var _toRad=_interopRequireDefault(require("./toRad"));var _constants=require("./constants");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var getDistance=function getDistance(from,to){var accuracy=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;accuracy=typeof accuracy!=="undefined"&&!isNaN(accuracy)?accuracy:1;var fromLat=(0,_getLatitude.default)(from);var fromLon=(0,_getLongitude.default)(from);var toLat=(0,_getLatitude.default)(to);var toLon=(0,_getLongitude.default)(to);var distance=Math.acos(Math.sin((0,_toRad.default)(toLat))*Math.sin((0,_toRad.default)(fromLat))+Math.cos((0,_toRad.default)(toLat))*Math.cos((0,_toRad.default)(fromLat))*Math.cos((0,_toRad.default)(fromLon)-(0,_toRad.default)(toLon)))*_constants.earthRadius;return Math.round(distance/accuracy)*accuracy};var _default=getDistance;exports.default=_default;
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _getLatitude=_interopRequireDefault(require("./getLatitude"));var _getLongitude=_interopRequireDefault(require("./getLongitude"));var _toRad=_interopRequireDefault(require("./toRad"));var _constants=require("./constants");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var normalizeACosArg=function normalizeACosArg(val){if(val>1){return 1}if(val<-1){return-1}return val};var getDistance=function getDistance(from,to){var accuracy=arguments.length>2&&arguments[2]!==undefined?arguments[2]:1;accuracy=typeof accuracy!=="undefined"&&!isNaN(accuracy)?accuracy:1;var fromLat=(0,_getLatitude.default)(from);var fromLon=(0,_getLongitude.default)(from);var toLat=(0,_getLatitude.default)(to);var toLon=(0,_getLongitude.default)(to);var distance=Math.acos(normalizeACosArg(Math.sin((0,_toRad.default)(toLat))*Math.sin((0,_toRad.default)(fromLat))+Math.cos((0,_toRad.default)(toLat))*Math.cos((0,_toRad.default)(fromLat))*Math.cos((0,_toRad.default)(fromLon)-(0,_toRad.default)(toLon))))*_constants.earthRadius;return Math.round(distance/accuracy)*accuracy};var _default=getDistance;exports.default=_default;

@@ -1,1 +0,1 @@

!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.geolib=n():t.geolib=n()}("undefined"!=typeof self?self:this,function(){return function(t){var n={};function r(e){if(n[e])return n[e].exports;var i=n[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)r.d(e,i,function(n){return t[n]}.bind(null,i));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=0)}([function(t,n,r){"use strict";r.r(n);var e=/^([0-9]{1,3})°\s*([0-9]{1,3}(?:\.(?:[0-9]{1,}))?)['′]\s*(([0-9]{1,3}(\.([0-9]{1,}))?)["″]\s*)?([NEOSW]?)$/,i=["lng","lon","longitude",0],o=["lat","latitude",1],a=["alt","altitude","elevation","elev",2],u={m:1,km:.001,cm:100,mm:1e3,mi:1/1609.344,sm:1/1852.216,ft:100/30.48,in:100/2.54,yd:1/.9144},c=3600,f={m2:1,km2:1e-6,ha:1e-4,a:.01,ft2:10.763911,yd2:1.19599,in2:1550.0031};f.sqm=f.m2,f.sqkm=f.km2,f.sqft=f.ft2,f.sqyd=f.yd2,f.sqin=f.in2;var s=function(t,n){return n.reduce(function(n,r){if(null==t)throw new Error("'".concat(t,"' is no valid coordinate."));return t.hasOwnProperty(r)&&void 0!==r&&void 0===n?(n=r,r):n},void 0)},l=function(t){var n=t.toString().trim();return!isNaN(parseFloat(n))&&parseFloat(n)===Number(n)},d=function(t){return e.test(t.toString().trim())},h=function(t){var n=new RegExp(e).exec(t);if(null==n)throw new Error("Given value is not in sexagesimal format");var r=Number(n[2])/60||0,i=Number(n[4])/3600||0,o=parseFloat(n[1])+r+i;return["S","W"].includes(n[7])?-o:o};function g(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}var m=function(t){var n=s(t,i),r=s(t,o),e=s(t,a);return function(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{},e=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.forEach(function(n){g(t,n,r[n])})}return t}({latitude:r,longitude:n},e?{altitude:e}:{})},v=function t(n){return l(n)?!(parseFloat(n)>90||n<-90):!!d(n)&&t(h(n))},M=function t(n){return l(n)?!(parseFloat(n)>180||n<-180):!!d(n)&&t(h(n))},p=function(t){var n=m(t),r=n.latitude,e=n.longitude;if(Array.isArray(t)&&t.length>=2)return M(t[0])&&v(t[1]);if(void 0===r||void 0===e)return!1;var i=t[e],o=t[r];return void 0!==o&&void 0!==i&&!1!==v(o)&&!1!==M(i)};function y(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}var b=function t(n){if(l(n))return Number(n);if(d(n))return h(n);if(p(n)){var r=m(n);return Array.isArray(n)?n.map(function(n,r){return[0,1].includes(r)?t(n):n}):function(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{},e=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.forEach(function(n){y(t,n,r[n])})}return t}({},n,r.latitude&&y({},r.latitude,t(n[r.latitude])),r.longitude&&y({},r.longitude,t(n[r.longitude])))}return Array.isArray(n)?n.map(function(n){return p(n)?t(n):n}):n},S=function(t,n){var r=s(t,o);if(null!=r){var e=t[r];return!0===n?e:b(e)}},N=function(t,n){var r=s(t,i);if(null!=r){var e=t[r];return!0===n?e:b(e)}},P=function(t){return t*Math.PI/180},w=function(t){return 180*t/Math.PI},x=function(t,n,r){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:6371e3,i=S(t),o=N(t),a=n/e,u=P(r),c=P(i),f=P(o),s=Math.asin(Math.sin(c)*Math.cos(a)+Math.cos(c)*Math.sin(a)*Math.cos(u)),l=f+Math.atan2(Math.sin(u)*Math.sin(a)*Math.cos(c),Math.cos(a)-Math.sin(c)*Math.sin(s)),d=w(l);return(d<-180||d>180)&&(l=(l+3*Math.PI)%(2*Math.PI)-Math.PI,d=w(l)),{latitude:w(s),longitude:d}},E=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"m",r=f[n];if(r)return t*r;throw new Error("Invalid unit used for area conversion.")},O=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"m",r=u[n];if(r)return t*r;throw new Error("Invalid unit used for distance conversion.")},L=function(t){switch(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"kmh"){case"kmh":return t*c*u.km;case"mph":return t*c*u.mi;default:return t}};function j(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var r=[],e=!0,i=!1,o=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(r.push(a.value),!n||r.length!==n);e=!0);}catch(t){i=!0,o=t}finally{try{e||null==u.return||u.return()}finally{if(i)throw o}}return r}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var W=function(t){var n=Math.pow(10,12);return Math.round(t*n)/n},I=function(t){var n=j(t.toString().split("."),2),r=n[0],e=n[1],i=Math.abs(Number(r)),o=W(60*Number("0."+(e||0))),a=Math.floor(o),u=W(60*(o%a||0));return i+"° "+Number(a.toFixed(6)).toString().split(".").map(function(t,n){return 0===n?t.padStart(2,"0"):t}).join(".")+"' "+Number(u.toFixed(4)).toString().split(".").map(function(t,n){return 0===n?t.padStart(2,"0"):t}).join(".")+'"'},D=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;r=void 0===r||isNaN(r)?1:r;var e=S(t),i=N(t),o=S(n),a=N(n),u=6378137*Math.acos(Math.sin(P(o))*Math.sin(P(e))+Math.cos(P(o))*Math.cos(P(e))*Math.cos(P(i)-P(a)));return Math.round(u/r)*r},A=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:D;return r="function"==typeof r?r:D,n.slice().sort(function(n,e){return r(t,n)-r(t,e)})},F=function(t,n){return A(t,n)[0]},k=function(t){var n=0;if(t.length>2){for(var r,e,i,o=0;o<t.length;o++){o===t.length-2?(r=t.length-2,e=t.length-1,i=0):o===t.length-1?(r=t.length-1,e=0,i=1):(r=o,e=o+1,i=o+2);var a=N(t[r]),u=S(t[e]),c=N(t[i]);n+=(P(c)-P(a))*Math.sin(P(u))}n=6378137*n*6378137/2}return Math.abs(n)},C=function(t){if(!1===Array.isArray(t)||0===t.length)throw new Error("No points were given.");return t.reduce(function(t,n){var r=S(n),e=N(n);return{maxLat:Math.max(r,t.maxLat),minLat:Math.min(r,t.minLat),maxLng:Math.max(e,t.maxLng),minLng:Math.min(e,t.minLng)}},{maxLat:-1/0,minLat:1/0,maxLng:-1/0,minLng:1/0})},q=function(t,n){var r,e,i=S(t),o=N(t),a=P(i),u=P(o),c=n/6378137,f=a-c,s=a+c,l=P(90),d=P(-90),h=P(180),g=P(-180);if(f>d&&s<l){var m=Math.asin(Math.sin(c)/Math.cos(a));(r=u-m)<g&&(r+=2*Math.PI),(e=u+m)>h&&(e-=2*Math.PI)}else f=Math.max(f,d),s=Math.min(s,l),r=g,e=h;return[{latitude:w(f),longitude:w(r)},{latitude:w(s),longitude:w(e)}]},B=function(t){if(!1===Array.isArray(t)||0===t.length)return!1;var n=t.length,r=t.reduce(function(t,n){var r=P(S(n)),e=P(N(n));return{X:t.X+Math.cos(r)*Math.cos(e),Y:t.Y+Math.cos(r)*Math.sin(e),Z:t.Z+Math.sin(r)}},{X:0,Y:0,Z:0}),e=r.X/n,i=r.Y/n,o=r.Z/n;return{longitude:w(Math.atan2(i,e)),latitude:w(Math.atan2(o,Math.sqrt(e*e+i*i)))}},_=function(t){var n=C(t),r=n.minLat+(n.maxLat-n.minLat)/2,e=n.minLng+(n.maxLng-n.minLng)/2;return{latitude:parseFloat(r.toFixed(6)),longitude:parseFloat(e.toFixed(6))}},R=function(t,n){var r=P(N(n))-P(N(t)),e=Math.log(Math.tan(P(S(n))/2+Math.PI/4)/Math.tan(P(S(t))/2+Math.PI/4));return Math.abs(r)>Math.PI&&(r=r>0?-1*(2*Math.PI-r):2*Math.PI+r),(w(Math.atan2(r,e))+360)%360},T=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:R,e="function"==typeof r?r(t,n):R(t,n);if(isNaN(e))throw new Error("Could not calculate bearing for given points. Check your bearing function");switch(Math.round(e/22.5)){case 1:return"NNE";case 2:return"NE";case 3:return"ENE";case 4:return"E";case 5:return"ESE";case 6:return"SE";case 7:return"SSE";case 8:return"S";case 9:return"SSW";case 10:return"SW";case 11:return"WSW";case 12:return"W";case 13:return"WNW";case 14:return"NW";case 15:return"NNW";default:return"N"}},$=function(t,n,r){var e=D(n,t),i=D(t,r),o=D(n,r),a=Math.acos((e*e+o*o-i*i)/(2*e*o)),u=Math.acos((i*i+o*o-e*e)/(2*i*o));return a>Math.PI/2?e:u>Math.PI/2?i:Math.sin(a)*e},X=function(t,n){var r=S(n),e=N(n),i=S(t),o=N(t);return(w(Math.atan2(Math.sin(P(e)-P(o))*Math.cos(P(r)),Math.cos(P(i))*Math.sin(P(r))-Math.sin(P(i))*Math.cos(P(r))*Math.cos(P(e)-P(o))))+360)%360};function Y(t){return(Y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var Z=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D;return t.reduce(function(t,r){return"object"===Y(t)&&null!==t.last&&(t.distance+=n(r,t.last)),t.last=r,t},{last:null,distance:0}).distance},V=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;r=void 0===r||isNaN(r)?1:r;var e,i,o,a,u,c,f,s=S(t),l=N(t),d=S(n),h=N(n),g=6356752.314245,m=P(h-l),v=Math.atan(.9966471893352525*Math.tan(P(parseFloat(s)))),M=Math.atan(.9966471893352525*Math.tan(P(parseFloat(d)))),p=Math.sin(v),y=Math.cos(v),b=Math.sin(M),w=Math.cos(M),x=m,E=100;do{var O=Math.sin(x),L=Math.cos(x);if(0===(c=Math.sqrt(w*O*(w*O)+(y*b-p*w*L)*(y*b-p*w*L))))return 0;e=p*b+y*w*L,i=Math.atan2(c,e),u=e-2*p*b/(a=1-(o=y*w*O/c)*o),isNaN(u)&&(u=0);var j=1/298.257223563/16*a*(4+1/298.257223563*(4-3*a));f=x,x=m+1/298.257223563*(1-j)*o*(i+j*c*(u+j*e*(2*u*u-1)))}while(Math.abs(x-f)>1e-12&&--E>0);if(0===E)return NaN;var W=272331606109.84375*a/(g*g),I=W/1024*(256+W*(W*(74-47*W)-128)),D=g*(1+W/16384*(4096+W*(W*(320-175*W)-768)))*(i-I*c*(u+I/4*(e*(2*u*u-1)-I/6*u*(4*c*c-3)*(4*u*u-3))));return Math.round(D/r)*r},G=function(t){return/^NNE|NE|NNW|N$/.test(t)?"N":/^ENE|E|ESE|SE$/.test(t)?"E":/^SSE|S|SSW|SW$/.test(t)?"S":/^WSW|W|WNW|NW$/.test(t)?"W":void 0},K=function(t,n){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:D)(t,n)/(Number(n.time)-Number(t.time))*1e3},z=function(t,n,r){return D(n,t)+D(t,r)===D(n,r)},H=function(t,n){for(var r=!1,e=n.length,i=-1,o=e-1;++i<e;o=i)(N(n[i])<=N(t)&&N(t)<N(n[o])||N(n[o])<=N(t)&&N(t)<N(n[i]))&&S(t)<(S(n[o])-S(n[i]))*(N(t)-N(n[i]))/(N(n[o])-N(n[i]))+S(n[i])&&(r=!r);return r},J=function(t,n,r,e){return $(t,n,r)<e},Q=function(t,n,r){return D(t,n)<r};r.d(n,"computeDestinationPoint",function(){return x}),r.d(n,"convertArea",function(){return E}),r.d(n,"convertDistance",function(){return O}),r.d(n,"convertSpeed",function(){return L}),r.d(n,"decimalToSexagesimal",function(){return I}),r.d(n,"findNearest",function(){return F}),r.d(n,"getAreaOfPolygon",function(){return k}),r.d(n,"getBounds",function(){return C}),r.d(n,"getBoundsOfDistance",function(){return q}),r.d(n,"getCenter",function(){return B}),r.d(n,"getCenterOfBounds",function(){return _}),r.d(n,"getCompassDirection",function(){return T}),r.d(n,"getCoordinateKey",function(){return s}),r.d(n,"getCoordinateKeys",function(){return m}),r.d(n,"getDistance",function(){return D}),r.d(n,"getDistanceFromLine",function(){return $}),r.d(n,"getGreatCircleBearing",function(){return X}),r.d(n,"getLatitude",function(){return S}),r.d(n,"getLongitude",function(){return N}),r.d(n,"getPathLength",function(){return Z}),r.d(n,"getPreciseDistance",function(){return V}),r.d(n,"getRhumbLineBearing",function(){return R}),r.d(n,"getRoughCompassDirection",function(){return G}),r.d(n,"getSpeed",function(){return K}),r.d(n,"isDecimal",function(){return l}),r.d(n,"isPointInLine",function(){return z}),r.d(n,"isPointInPolygon",function(){return H}),r.d(n,"isPointNearLine",function(){return J}),r.d(n,"isPointWithinRadius",function(){return Q}),r.d(n,"isSexagesimal",function(){return d}),r.d(n,"isValidCoordinate",function(){return p}),r.d(n,"isValidLatitude",function(){return v}),r.d(n,"isValidLongitude",function(){return M}),r.d(n,"orderByDistance",function(){return A}),r.d(n,"sexagesimalToDecimal",function(){return h}),r.d(n,"toDecimal",function(){return b}),r.d(n,"toRad",function(){return P}),r.d(n,"toDeg",function(){return w})}])});
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.geolib=n():t.geolib=n()}("undefined"!=typeof self?self:this,function(){return function(t){var n={};function r(e){if(n[e])return n[e].exports;var i=n[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,n){if(1&n&&(t=r(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var i in t)r.d(e,i,function(n){return t[n]}.bind(null,i));return e},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=0)}([function(t,n,r){"use strict";r.r(n);var e=/^([0-9]{1,3})°\s*([0-9]{1,3}(?:\.(?:[0-9]{1,}))?)['′]\s*(([0-9]{1,3}(\.([0-9]{1,}))?)["″]\s*)?([NEOSW]?)$/,i=["lng","lon","longitude",0],o=["lat","latitude",1],a=["alt","altitude","elevation","elev",2],u={m:1,km:.001,cm:100,mm:1e3,mi:1/1609.344,sm:1/1852.216,ft:100/30.48,in:100/2.54,yd:1/.9144},c=3600,f={m2:1,km2:1e-6,ha:1e-4,a:.01,ft2:10.763911,yd2:1.19599,in2:1550.0031};f.sqm=f.m2,f.sqkm=f.km2,f.sqft=f.ft2,f.sqyd=f.yd2,f.sqin=f.in2;var s=function(t,n){return n.reduce(function(n,r){if(null==t)throw new Error("'".concat(t,"' is no valid coordinate."));return t.hasOwnProperty(r)&&void 0!==r&&void 0===n?(n=r,r):n},void 0)},l=function(t){var n=t.toString().trim();return!isNaN(parseFloat(n))&&parseFloat(n)===Number(n)},d=function(t){return e.test(t.toString().trim())},h=function(t){var n=new RegExp(e).exec(t);if(null==n)throw new Error("Given value is not in sexagesimal format");var r=Number(n[2])/60||0,i=Number(n[4])/3600||0,o=parseFloat(n[1])+r+i;return["S","W"].includes(n[7])?-o:o};function g(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}var m=function(t){var n=s(t,i),r=s(t,o),e=s(t,a);return function(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{},e=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.forEach(function(n){g(t,n,r[n])})}return t}({latitude:r,longitude:n},e?{altitude:e}:{})},v=function t(n){return l(n)?!(parseFloat(n)>90||n<-90):!!d(n)&&t(h(n))},M=function t(n){return l(n)?!(parseFloat(n)>180||n<-180):!!d(n)&&t(h(n))},p=function(t){var n=m(t),r=n.latitude,e=n.longitude;if(Array.isArray(t)&&t.length>=2)return M(t[0])&&v(t[1]);if(void 0===r||void 0===e)return!1;var i=t[e],o=t[r];return void 0!==o&&void 0!==i&&!1!==v(o)&&!1!==M(i)};function y(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}var b=function t(n){if(l(n))return Number(n);if(d(n))return h(n);if(p(n)){var r=m(n);return Array.isArray(n)?n.map(function(n,r){return[0,1].includes(r)?t(n):n}):function(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{},e=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.forEach(function(n){y(t,n,r[n])})}return t}({},n,r.latitude&&y({},r.latitude,t(n[r.latitude])),r.longitude&&y({},r.longitude,t(n[r.longitude])))}return Array.isArray(n)?n.map(function(n){return p(n)?t(n):n}):n},S=function(t,n){var r=s(t,o);if(null!=r){var e=t[r];return!0===n?e:b(e)}},N=function(t,n){var r=s(t,i);if(null!=r){var e=t[r];return!0===n?e:b(e)}},P=function(t){return t*Math.PI/180},w=function(t){return 180*t/Math.PI},x=function(t,n,r){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:6371e3,i=S(t),o=N(t),a=n/e,u=P(r),c=P(i),f=P(o),s=Math.asin(Math.sin(c)*Math.cos(a)+Math.cos(c)*Math.sin(a)*Math.cos(u)),l=f+Math.atan2(Math.sin(u)*Math.sin(a)*Math.cos(c),Math.cos(a)-Math.sin(c)*Math.sin(s)),d=w(l);return(d<-180||d>180)&&(l=(l+3*Math.PI)%(2*Math.PI)-Math.PI,d=w(l)),{latitude:w(s),longitude:d}},E=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"m",r=f[n];if(r)return t*r;throw new Error("Invalid unit used for area conversion.")},O=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"m",r=u[n];if(r)return t*r;throw new Error("Invalid unit used for distance conversion.")},L=function(t){switch(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"kmh"){case"kmh":return t*c*u.km;case"mph":return t*c*u.mi;default:return t}};function j(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var r=[],e=!0,i=!1,o=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(r.push(a.value),!n||r.length!==n);e=!0);}catch(t){i=!0,o=t}finally{try{e||null==u.return||u.return()}finally{if(i)throw o}}return r}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var W=function(t){var n=Math.pow(10,12);return Math.round(t*n)/n},I=function(t){var n=j(t.toString().split("."),2),r=n[0],e=n[1],i=Math.abs(Number(r)),o=W(60*Number("0."+(e||0))),a=Math.floor(o),u=W(60*(o%a||0));return i+"° "+Number(a.toFixed(6)).toString().split(".").map(function(t,n){return 0===n?t.padStart(2,"0"):t}).join(".")+"' "+Number(u.toFixed(4)).toString().split(".").map(function(t,n){return 0===n?t.padStart(2,"0"):t}).join(".")+'"'},D=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;r=void 0===r||isNaN(r)?1:r;var e,i=S(t),o=N(t),a=S(n),u=N(n),c=6378137*Math.acos((e=Math.sin(P(a))*Math.sin(P(i))+Math.cos(P(a))*Math.cos(P(i))*Math.cos(P(o)-P(u)))>1?1:e<-1?-1:e);return Math.round(c/r)*r},A=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:D;return r="function"==typeof r?r:D,n.slice().sort(function(n,e){return r(t,n)-r(t,e)})},F=function(t,n){return A(t,n)[0]},k=function(t){var n=0;if(t.length>2){for(var r,e,i,o=0;o<t.length;o++){o===t.length-2?(r=t.length-2,e=t.length-1,i=0):o===t.length-1?(r=t.length-1,e=0,i=1):(r=o,e=o+1,i=o+2);var a=N(t[r]),u=S(t[e]),c=N(t[i]);n+=(P(c)-P(a))*Math.sin(P(u))}n=6378137*n*6378137/2}return Math.abs(n)},C=function(t){if(!1===Array.isArray(t)||0===t.length)throw new Error("No points were given.");return t.reduce(function(t,n){var r=S(n),e=N(n);return{maxLat:Math.max(r,t.maxLat),minLat:Math.min(r,t.minLat),maxLng:Math.max(e,t.maxLng),minLng:Math.min(e,t.minLng)}},{maxLat:-1/0,minLat:1/0,maxLng:-1/0,minLng:1/0})},q=function(t,n){var r,e,i=S(t),o=N(t),a=P(i),u=P(o),c=n/6378137,f=a-c,s=a+c,l=P(90),d=P(-90),h=P(180),g=P(-180);if(f>d&&s<l){var m=Math.asin(Math.sin(c)/Math.cos(a));(r=u-m)<g&&(r+=2*Math.PI),(e=u+m)>h&&(e-=2*Math.PI)}else f=Math.max(f,d),s=Math.min(s,l),r=g,e=h;return[{latitude:w(f),longitude:w(r)},{latitude:w(s),longitude:w(e)}]},B=function(t){if(!1===Array.isArray(t)||0===t.length)return!1;var n=t.length,r=t.reduce(function(t,n){var r=P(S(n)),e=P(N(n));return{X:t.X+Math.cos(r)*Math.cos(e),Y:t.Y+Math.cos(r)*Math.sin(e),Z:t.Z+Math.sin(r)}},{X:0,Y:0,Z:0}),e=r.X/n,i=r.Y/n,o=r.Z/n;return{longitude:w(Math.atan2(i,e)),latitude:w(Math.atan2(o,Math.sqrt(e*e+i*i)))}},_=function(t){var n=C(t),r=n.minLat+(n.maxLat-n.minLat)/2,e=n.minLng+(n.maxLng-n.minLng)/2;return{latitude:parseFloat(r.toFixed(6)),longitude:parseFloat(e.toFixed(6))}},R=function(t,n){var r=P(N(n))-P(N(t)),e=Math.log(Math.tan(P(S(n))/2+Math.PI/4)/Math.tan(P(S(t))/2+Math.PI/4));return Math.abs(r)>Math.PI&&(r=r>0?-1*(2*Math.PI-r):2*Math.PI+r),(w(Math.atan2(r,e))+360)%360},T=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:R,e="function"==typeof r?r(t,n):R(t,n);if(isNaN(e))throw new Error("Could not calculate bearing for given points. Check your bearing function");switch(Math.round(e/22.5)){case 1:return"NNE";case 2:return"NE";case 3:return"ENE";case 4:return"E";case 5:return"ESE";case 6:return"SE";case 7:return"SSE";case 8:return"S";case 9:return"SSW";case 10:return"SW";case 11:return"WSW";case 12:return"W";case 13:return"WNW";case 14:return"NW";case 15:return"NNW";default:return"N"}},$=function(t,n,r){var e=D(n,t),i=D(t,r),o=D(n,r),a=Math.acos((e*e+o*o-i*i)/(2*e*o)),u=Math.acos((i*i+o*o-e*e)/(2*i*o));return a>Math.PI/2?e:u>Math.PI/2?i:Math.sin(a)*e},X=function(t,n){var r=S(n),e=N(n),i=S(t),o=N(t);return(w(Math.atan2(Math.sin(P(e)-P(o))*Math.cos(P(r)),Math.cos(P(i))*Math.sin(P(r))-Math.sin(P(i))*Math.cos(P(r))*Math.cos(P(e)-P(o))))+360)%360};function Y(t){return(Y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var Z=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D;return t.reduce(function(t,r){return"object"===Y(t)&&null!==t.last&&(t.distance+=n(r,t.last)),t.last=r,t},{last:null,distance:0}).distance},V=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;r=void 0===r||isNaN(r)?1:r;var e,i,o,a,u,c,f,s=S(t),l=N(t),d=S(n),h=N(n),g=6356752.314245,m=P(h-l),v=Math.atan(.9966471893352525*Math.tan(P(parseFloat(s)))),M=Math.atan(.9966471893352525*Math.tan(P(parseFloat(d)))),p=Math.sin(v),y=Math.cos(v),b=Math.sin(M),w=Math.cos(M),x=m,E=100;do{var O=Math.sin(x),L=Math.cos(x);if(0===(c=Math.sqrt(w*O*(w*O)+(y*b-p*w*L)*(y*b-p*w*L))))return 0;e=p*b+y*w*L,i=Math.atan2(c,e),u=e-2*p*b/(a=1-(o=y*w*O/c)*o),isNaN(u)&&(u=0);var j=1/298.257223563/16*a*(4+1/298.257223563*(4-3*a));f=x,x=m+1/298.257223563*(1-j)*o*(i+j*c*(u+j*e*(2*u*u-1)))}while(Math.abs(x-f)>1e-12&&--E>0);if(0===E)return NaN;var W=272331606109.84375*a/(g*g),I=W/1024*(256+W*(W*(74-47*W)-128)),D=g*(1+W/16384*(4096+W*(W*(320-175*W)-768)))*(i-I*c*(u+I/4*(e*(2*u*u-1)-I/6*u*(4*c*c-3)*(4*u*u-3))));return Math.round(D/r)*r},G=function(t){return/^NNE|NE|NNW|N$/.test(t)?"N":/^ENE|E|ESE|SE$/.test(t)?"E":/^SSE|S|SSW|SW$/.test(t)?"S":/^WSW|W|WNW|NW$/.test(t)?"W":void 0},K=function(t,n){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:D)(t,n)/(Number(n.time)-Number(t.time))*1e3},z=function(t,n,r){return D(n,t)+D(t,r)===D(n,r)},H=function(t,n){for(var r=!1,e=n.length,i=-1,o=e-1;++i<e;o=i)(N(n[i])<=N(t)&&N(t)<N(n[o])||N(n[o])<=N(t)&&N(t)<N(n[i]))&&S(t)<(S(n[o])-S(n[i]))*(N(t)-N(n[i]))/(N(n[o])-N(n[i]))+S(n[i])&&(r=!r);return r},J=function(t,n,r,e){return $(t,n,r)<e},Q=function(t,n,r){return D(t,n)<r};r.d(n,"computeDestinationPoint",function(){return x}),r.d(n,"convertArea",function(){return E}),r.d(n,"convertDistance",function(){return O}),r.d(n,"convertSpeed",function(){return L}),r.d(n,"decimalToSexagesimal",function(){return I}),r.d(n,"findNearest",function(){return F}),r.d(n,"getAreaOfPolygon",function(){return k}),r.d(n,"getBounds",function(){return C}),r.d(n,"getBoundsOfDistance",function(){return q}),r.d(n,"getCenter",function(){return B}),r.d(n,"getCenterOfBounds",function(){return _}),r.d(n,"getCompassDirection",function(){return T}),r.d(n,"getCoordinateKey",function(){return s}),r.d(n,"getCoordinateKeys",function(){return m}),r.d(n,"getDistance",function(){return D}),r.d(n,"getDistanceFromLine",function(){return $}),r.d(n,"getGreatCircleBearing",function(){return X}),r.d(n,"getLatitude",function(){return S}),r.d(n,"getLongitude",function(){return N}),r.d(n,"getPathLength",function(){return Z}),r.d(n,"getPreciseDistance",function(){return V}),r.d(n,"getRhumbLineBearing",function(){return R}),r.d(n,"getRoughCompassDirection",function(){return G}),r.d(n,"getSpeed",function(){return K}),r.d(n,"isDecimal",function(){return l}),r.d(n,"isPointInLine",function(){return z}),r.d(n,"isPointInPolygon",function(){return H}),r.d(n,"isPointNearLine",function(){return J}),r.d(n,"isPointWithinRadius",function(){return Q}),r.d(n,"isSexagesimal",function(){return d}),r.d(n,"isValidCoordinate",function(){return p}),r.d(n,"isValidLatitude",function(){return v}),r.d(n,"isValidLongitude",function(){return M}),r.d(n,"orderByDistance",function(){return A}),r.d(n,"sexagesimalToDecimal",function(){return h}),r.d(n,"toDecimal",function(){return b}),r.d(n,"toRad",function(){return P}),r.d(n,"toDeg",function(){return w})}])});
{
"name": "geolib",
"version": "3.0.3",
"version": "3.0.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc