forked from shukerullah/react-geocode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MP20200107 - Typescript update related to shukerullah#24
- Loading branch information
1 parent
49eeda3
commit b2d82bf
Showing
4 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Type definitions for react-geocode 0.2.1 | ||
// Project: https://github.com/shukerullah/react-geocode/ | ||
// Definitions by: Mike Pouncy <https://github.com/pouncyisdead> | ||
|
||
declare module 'react-geocode' { | ||
const reactGeocode: { | ||
setApiKey(apiKey: string): void; | ||
setLanguage(language: string): void; | ||
setRegion(region: string): void; | ||
enableDebug(flag?: boolean): void; | ||
fromLatLng(lat: string, lng: string, apiKey?: string, language?: string, region?: string): Promise<any>; | ||
fromAddress(address: string, apiKey?: string, language?: string, region?: string): Promise<any>; | ||
}; | ||
|
||
export = reactGeocode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,22 @@ | |
* @package react-geocode | ||
* @author Pir Shukarulalh Shah <[email protected]> (http://www.shukarullah.com) | ||
*/ | ||
|
||
/** @type {boolean | null} */ | ||
let DEBUG = false; | ||
/** @type {string | null} */ | ||
let API_KEY = null; | ||
/** @type {string | null} */ | ||
let LANGUAGE = "en"; | ||
/** @type {string | number | boolean | null} */ | ||
let REGION = null; | ||
/** @type {string | null} */ | ||
const GOOGLE_API = "https://maps.google.com/maps/api/geocode/json"; | ||
|
||
/** | ||
* @param {string} message | ||
* @param {boolean} warn | ||
*/ | ||
function log(message, warn = false) { | ||
if (DEBUG) { | ||
if (warn) { | ||
|
@@ -20,6 +30,10 @@ function log(message, warn = false) { | |
} | ||
} | ||
|
||
/** | ||
* @param {RequestInfo} url | ||
* @returns {Promise<any>} | ||
*/ | ||
async function handleUrl(url) { | ||
const response = await fetch(url).catch(() => | ||
Promise.reject(new Error("Error fetching data")) | ||
|
@@ -45,7 +59,7 @@ async function handleUrl(url) { | |
); | ||
} | ||
|
||
export default { | ||
const reactGeocode = { | ||
/** | ||
* | ||
* | ||
|
@@ -89,8 +103,8 @@ export default { | |
* @param {string} lng | ||
* @param {string} [apiKey] | ||
* @param {string} [language] | ||
* @param {string} [region] | ||
* @returns {Promise} | ||
* @param {string | null} [region] | ||
* @returns {Promise<any>} | ||
*/ | ||
async fromLatLng(lat, lng, apiKey, language, region) { | ||
if (!lat || !lng) { | ||
|
@@ -113,6 +127,7 @@ export default { | |
|
||
if (region || REGION) { | ||
REGION = region || REGION; | ||
// @ts-ignore | ||
url += `®ion=${encodeURIComponent(REGION)}`; | ||
} | ||
|
||
|
@@ -125,8 +140,8 @@ export default { | |
* @param {string} address | ||
* @param {string} [apiKey] | ||
* @param {string} [language] | ||
* @param {string} [region] | ||
* @returns {Promise} | ||
* @param {string | null} [region] | ||
* @returns {Promise<any>} | ||
*/ | ||
async fromAddress(address, apiKey, language, region) { | ||
if (!address) { | ||
|
@@ -148,9 +163,12 @@ export default { | |
|
||
if (region || REGION) { | ||
REGION = region || REGION; | ||
// @ts-ignore | ||
url += `®ion=${encodeURIComponent(REGION)}`; | ||
} | ||
|
||
return handleUrl(url); | ||
} | ||
}; | ||
|
||
export default reactGeocode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { /* Enable incremental compilation */ | ||
"target": "ES5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */, | ||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"lib": [ "ES2015", "DOM" ] /* Specify library files to be included in the compilation. */, | ||
"allowJs": true /* Allow javascript files to be compiled. */, | ||
"checkJs": true /* Report errors in .js files. */, | ||
"declaration": true /* Generates corresponding '.d.ts' file. */, | ||
"noEmit": false /* Do not emit outputs. */, | ||
"strict": true /* Enable all strict type-checking options. */, | ||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */, | ||
"outDir": "lib/" | ||
} | ||
} |