react-geocode
Advanced tools
Comparing version
194
lib/index.js
@@ -1,193 +0,1 @@ | ||
"use strict"; | ||
let regeneratorRuntime = require("regenerator-runtime"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var handleUrl = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(url) { | ||
var response, json; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return fetch(url).catch(function (error) { | ||
return Promise.reject(new Error("Error fetching data")); | ||
}); | ||
case 2: | ||
response = _context.sent; | ||
_context.next = 5; | ||
return response.json().catch(function () { | ||
log("Error parsing server response"); | ||
return Promise.reject(new Error("Error parsing server response")); | ||
}); | ||
case 5: | ||
json = _context.sent; | ||
if (!(json.status === "OK")) { | ||
_context.next = 9; | ||
break; | ||
} | ||
log(json); | ||
return _context.abrupt("return", json); | ||
case 9: | ||
log("Server returned status code " + json.status, true); | ||
return _context.abrupt("return", Promise.reject(new Error("Server returned status code " + json.status))); | ||
case 11: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function handleUrl(_x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
/** | ||
* React Geocode Module | ||
* | ||
* @package react-geocode | ||
* @author Pir Shukarulalh Shah <shuker_rashdi@hotmail.com> (http://www.shukarullah.com) | ||
*/ | ||
var DEBUG = false; | ||
var API_KEY = null; | ||
var GOOGLE_API = "https://maps.google.com/maps/api/geocode/json"; | ||
function log(message) { | ||
var warn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
if (DEBUG) { | ||
if (warn) { | ||
console.warn(message); | ||
} else { | ||
console.log(message); | ||
} | ||
} | ||
} | ||
exports.default = { | ||
/** | ||
* | ||
* | ||
* @param {string} apiKey | ||
*/ | ||
setApiKey: function setApiKey(apiKey) { | ||
API_KEY = apiKey; | ||
}, | ||
/** | ||
* | ||
* | ||
* @param {boolean} [flag=true] | ||
*/ | ||
enableDebug: function enableDebug() { | ||
var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
DEBUG = flag; | ||
}, | ||
/** | ||
* | ||
* | ||
* @param {string} lat | ||
* @param {string} lng | ||
* @param {string} [apiKey] | ||
* @returns {Promise} | ||
*/ | ||
fromLatLng: function fromLatLng(lat, lng, apiKey) { | ||
var _this = this; | ||
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { | ||
var latLng, url; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!(!lat || !lng)) { | ||
_context2.next = 3; | ||
break; | ||
} | ||
log("Provided coordinates are invalid", true); | ||
return _context2.abrupt("return", Promise.reject(new Error("Provided coordinates are invalid"))); | ||
case 3: | ||
latLng = lat + "," + lng; | ||
url = GOOGLE_API + "?latlng=" + encodeURI(latLng); | ||
if (apiKey || API_KEY) { | ||
API_KEY = apiKey || API_KEY; | ||
url += "&key=" + API_KEY; | ||
} | ||
return _context2.abrupt("return", handleUrl(url)); | ||
case 7: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, _this); | ||
}))(); | ||
}, | ||
/** | ||
* | ||
* | ||
* @param {string} address | ||
* @param {string} [apiKey] | ||
* @returns {Promise} | ||
*/ | ||
fromAddress: function fromAddress(address, apiKey) { | ||
var _this2 = this; | ||
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { | ||
var url; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (address) { | ||
_context3.next = 3; | ||
break; | ||
} | ||
log("Provided address is invalid", true); | ||
return _context3.abrupt("return", Promise.reject(new Error("Provided address is invalid"))); | ||
case 3: | ||
url = GOOGLE_API + "?address=" + encodeURI(address); | ||
if (apiKey || API_KEY) { | ||
API_KEY = apiKey || API_KEY; | ||
url += "&key=" + API_KEY; | ||
} | ||
return _context3.abrupt("return", handleUrl(url)); | ||
case 6: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, _this2); | ||
}))(); | ||
} | ||
}; | ||
"use strict";var handleUrl=function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function b(c){var d,e;return regeneratorRuntime.wrap(function(g){for(;;)switch(g.prev=g.next){case 0:return g.next=2,fetch(c).catch(function(){return Promise.reject(new Error("Error fetching data"))});case 2:return d=g.sent,g.next=5,d.json().catch(function(){return log("Error parsing server response"),Promise.reject(new Error("Error parsing server response"))});case 5:if(e=g.sent,"OK"!==e.status){g.next=9;break}return log(e),g.abrupt("return",e);case 9:return log("Server returned status code "+e.status,!0),g.abrupt("return",Promise.reject(new Error("Server returned status code "+e.status)));case 11:case"end":return g.stop();}},b,this)}));return function(){return a.apply(this,arguments)}}();Object.defineProperty(exports,"__esModule",{value:!0});function _asyncToGenerator(a){return function(){var b=a.apply(this,arguments);return new Promise(function(c,d){function e(f,g){try{var h=b[f](g),i=h.value}catch(j){return void d(j)}return h.done?void c(i):Promise.resolve(i).then(function(j){e("next",j)},function(j){e("throw",j)})}return e("next")})}}var DEBUG=!1,API_KEY=null,GOOGLE_API="https://maps.google.com/maps/api/geocode/json";function log(a){var b=1<arguments.length&&arguments[1]!==void 0&&arguments[1];DEBUG&&(b?console.warn(a):console.log(a))}exports.default={setApiKey:function setApiKey(a){API_KEY=a},enableDebug:function enableDebug(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:!0;DEBUG=a},fromLatLng:function fromLatLng(a,b,c){var d=this;return _asyncToGenerator(regeneratorRuntime.mark(function e(){var f,g;return regeneratorRuntime.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(a&&b){i.next=3;break}return log("Provided coordinates are invalid",!0),i.abrupt("return",Promise.reject(new Error("Provided coordinates are invalid")));case 3:return f=a+","+b,g=GOOGLE_API+"?latlng="+encodeURI(f),(c||API_KEY)&&(API_KEY=c||API_KEY,g+="&key="+API_KEY),i.abrupt("return",handleUrl(g));case 7:case"end":return i.stop();}},e,d)}))()},fromAddress:function fromAddress(a,b){var c=this;return _asyncToGenerator(regeneratorRuntime.mark(function d(){var e;return regeneratorRuntime.wrap(function(g){for(;;)switch(g.prev=g.next){case 0:if(a){g.next=3;break}return log("Provided address is invalid",!0),g.abrupt("return",Promise.reject(new Error("Provided address is invalid")));case 3:return e=GOOGLE_API+"?address="+encodeURI(a),(b||API_KEY)&&(API_KEY=b||API_KEY,e+="&key="+API_KEY),g.abrupt("return",handleUrl(e));case 6:case"end":return g.stop();}},d,c)}))()}}; |
{ | ||
"name": "react-geocode", | ||
"version": "0.0.9", | ||
"description": | ||
"A React module to transform a description of a location (i.e. street address, town name, etc.) into geographic coordinates (i.e. latitude and longitude) and vice versa.", | ||
"version": "0.1.0", | ||
"description": "A React module to transform a description of a location (i.e. street address, town name, etc.) into geographic coordinates (i.e. latitude and longitude) and vice versa.", | ||
"main": "./lib/index.js", | ||
@@ -19,4 +18,3 @@ "repository": { | ||
], | ||
"author": | ||
"Pir Shukarulalh Shah <shuker_rashdi@hotmail.com> (http://www.shukarullah.com)", | ||
"author": "Pir Shukarulalh Shah <shuker_rashdi@hotmail.com> (http://www.shukarullah.com)", | ||
"license": "MIT", | ||
@@ -23,0 +21,0 @@ "bugs": { |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
0
-100%6591
-29.05%0
-100%2
100%