From ffda35b6200530bfc19b12a2ca80b7ce411a41d2 Mon Sep 17 00:00:00 2001 From: Sam Svindland Date: Wed, 19 Feb 2025 16:16:10 -0500 Subject: [PATCH] remove dist and revert change to .gitignore --- .gitignore | 3 ++ dist/index.d.ts | 34 -------------- dist/index.es.js | 107 ------------------------------------------ dist/index.es.js.map | 1 - dist/index.umd.js | 3 -- dist/index.umd.js.map | 1 - 6 files changed, 3 insertions(+), 146 deletions(-) delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.es.js delete mode 100644 dist/index.es.js.map delete mode 100644 dist/index.umd.js delete mode 100644 dist/index.umd.js.map diff --git a/.gitignore b/.gitignore index 09c6bfa..3fd2583 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ npm-debug.log yarn-error.log yarn.lock +# Build output +/dist + # IDE and editor files .vscode/ .idea/ diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 3104c94..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -export declare enum RequestType { - ADDRESS = "address", - LATLNG = "latlng", - PLACE_ID = "place_id" -} -export declare enum OutputFormat { - XML = "xml", - JSON = "json" -} -export interface GeocodeOptions { - key?: string; - language?: string; - region?: string; - components?: string; - bounds?: string; - result_type?: string; - location_type?: string; - outputFormat: OutputFormat; - enable_address_descriptor?: boolean; -} -export declare function setDefaults(options: GeocodeOptions): void; -export declare function setKey(key: string): void; -export declare function setLanguage(language: string): void; -export declare function setRegion(region: string): void; -export declare function setComponents(components: string): void; -export declare function setBounds(bounds: string): void; -export declare function setResultType(resultType: string): void; -export declare function setLocationType(locationType: string): void; -export declare function setOutputFormat(outputFormat: OutputFormat): void; -export declare function enableAddressDescriptor(enableAddressDescriptor: boolean): void; -export declare function geocode(requestType: RequestType | string, value: string, options?: GeocodeOptions): Promise; -export declare function fromAddress(address: string, key?: string, language?: string, region?: string): Promise; -export declare function fromPlaceId(placeId: string, key?: string, language?: string, region?: string): Promise; -export declare function fromLatLng(lat: number, lng: number, key?: string, language?: string, region?: string, location_type?: string): Promise; diff --git a/dist/index.es.js b/dist/index.es.js deleted file mode 100644 index b3b7e1a..0000000 --- a/dist/index.es.js +++ /dev/null @@ -1,107 +0,0 @@ -var d = /* @__PURE__ */ ((t) => (t.ADDRESS = "address", t.LATLNG = "latlng", t.PLACE_ID = "place_id", t))(d || {}), p = /* @__PURE__ */ ((t) => (t.XML = "xml", t.JSON = "json", t))(p || {}); -const g = "https://maps.googleapis.com/maps/api/geocode"; -let s = { - outputFormat: "json" - /* JSON */ -}; -async function l(t) { - const { outputFormat: n, ...e } = t, r = new URLSearchParams( - e - ).toString(), o = `${g}/${n}?${r}`; - try { - const i = await (await fetch(o)).json(), { status: c, error_message: f } = i; - if (c === "OK") - return i; - throw new Error( - `Geocoding failed: ${f}. Server returned status code ${c}.` - ); - } catch (a) { - throw a instanceof Error ? new Error(`Geocoding request failed: ${a.message}`) : new Error(`Geocoding request failed with unknown error: ${a}`); - } -} -function m(t) { - s = { - ...s, - ...t - }; -} -function w(t) { - s.key = t; -} -function y(t) { - s.language = t; -} -function $(t) { - s.region = t; -} -function h(t) { - s.components = t; -} -function E(t) { - s.bounds = t; -} -function L(t) { - s.result_type = t; -} -function _(t) { - s.location_type = t; -} -function j(t) { - s.outputFormat = t; -} -function G(t) { - s.enable_address_descriptor = t; -} -function u(t, n, e) { - if (typeof t != "string" || typeof n != "string") - throw new Error( - `Both requestType and value are required and must be of type string. - requestType: ${typeof t}, value: ${typeof n}` - ); - const r = { - ...s, - ...e, - [t]: n - }; - return l(r); -} -function O(t, n, e, r) { - const o = { - outputFormat: "json" - /* JSON */ - }; - return n && (o.key = n), e && (o.language = e), r && (o.region = r), u("address", t, o); -} -function S(t, n, e, r) { - const o = { - outputFormat: "json" - /* JSON */ - }; - return n && (o.key = n), e && (o.language = e), r && (o.region = r), u("place_id", t, o); -} -function A(t, n, e, r, o, a) { - const i = { - outputFormat: "json" - /* JSON */ - }; - return e && (i.key = e), r && (i.language = r), o && (i.region = o), a && (i.location_type = a), u("latlng", `${t},${n}`, i); -} -export { - p as OutputFormat, - d as RequestType, - G as enableAddressDescriptor, - O as fromAddress, - A as fromLatLng, - S as fromPlaceId, - u as geocode, - E as setBounds, - h as setComponents, - m as setDefaults, - w as setKey, - y as setLanguage, - _ as setLocationType, - j as setOutputFormat, - $ as setRegion, - L as setResultType -}; -//# sourceMappingURL=index.es.js.map diff --git a/dist/index.es.js.map b/dist/index.es.js.map deleted file mode 100644 index c85e3c5..0000000 --- a/dist/index.es.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.es.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Enum defining possible request types for geocoding.\n */\nexport enum RequestType {\n ADDRESS = \"address\", // Geocoding by address\n LATLNG = \"latlng\", // Geocoding by latitude and longitude\n PLACE_ID = \"place_id\", // Geocoding by place ID\n}\n\n/**\n * Enum defining possible output formats for geocoding.\n */\nexport enum OutputFormat {\n XML = \"xml\", // Output format XML\n JSON = \"json\", // Output format JSON\n}\n\n/**\n * The URL of the Google Geocoding API.\n */\nconst GOOGLE_GEOCODE_API = \"https://maps.googleapis.com/maps/api/geocode\";\n\n/**\n * Options that can be passed to the geocoding requests.\n */\nexport interface GeocodeOptions {\n key?: string; // API key for the Google Maps Geocoding API.\n language?: string; // Language code for the response.\n region?: string; // Region code for the response.\n components?: string; // Component filtering for the response.\n bounds?: string; // Bounding box for the response.\n result_type?: string; // Result type filtering for the response.\n location_type?: string; // Location type filtering for the response.\n outputFormat: OutputFormat; // Desired output format (either XML or JSON)\n enable_address_descriptor?: boolean; // Whether to include an address descriptor in the reverse geocoding response.\n}\n\n/**\n * Response object from the geocoding API.\n */\ninterface GeocodeResponse {\n status: string;\n results: GeocodeResult[];\n address_descriptor?: AddressDescriptor;\n plus_code?: PlusCode;\n error_message?: string;\n}\n\n/**\n * The query parameters for geocoding requests.\n */\ninterface GeocodeQueryParams extends GeocodeOptions {\n place_id?: string; // The plce id to geocode\n address?: string; // The address to geocode\n latlng?: string; // The latitude/longitude of the location to geocode\n}\n\n/**\n * Default options for the geocoding requests.\n */\nlet defaultOptions: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n};\n\n/**\n * Performs a geocoding request to the Google Geocoding API.\n * @function geocodeRequest\n * @async\n * @param {GeocodeQueryParams} queryParams - The query parameters for the geocoding request.\n * @returns {Promise} - A promise that resolves with the geocoding response object.\n * @throws {Error} - Throws an error if the geocoding request fails.\n */\nasync function geocodeRequest(\n queryParams: GeocodeQueryParams,\n): Promise {\n const { outputFormat, ...restParams } = queryParams;\n const queryString = new URLSearchParams(\n restParams as Record,\n ).toString();\n const url = `${GOOGLE_GEOCODE_API}/${outputFormat}?${queryString}`;\n try {\n const response = await fetch(url);\n const json = await response.json();\n const { status, error_message } = json;\n\n if (status === \"OK\") {\n return json;\n }\n\n throw new Error(\n `Geocoding failed: ${error_message}. Server returned status code ${status}.`,\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Geocoding request failed: ${error.message}`);\n }\n throw new Error(`Geocoding request failed with unknown error: ${error}`);\n }\n}\n\n/**\n * Sets default options for geocoding requests.\n *\n * @param options - The default options to set.\n */\nexport function setDefaults(options: GeocodeOptions): void {\n defaultOptions = {\n ...defaultOptions,\n ...options,\n };\n}\n\n/**\n * Sets the API key to use for geocoding requests.\n *\n * @param key - The API key to set.\n */\nexport function setKey(key: string): void {\n defaultOptions.key = key;\n}\n\n/**\n * Sets the language to use for geocoding requests.\n *\n * @param language - The language to set.\n */\nexport function setLanguage(language: string): void {\n defaultOptions.language = language;\n}\n\n/**\n * Sets the region code to use for geocoding requests.\n *\n * @param region - The region code to set.\n */\nexport function setRegion(region: string): void {\n defaultOptions.region = region;\n}\n\n/**\n * Sets the component filter to use for geocoding requests.\n *\n * @param components - The component filter to set.\n */\nexport function setComponents(components: string): void {\n defaultOptions.components = components;\n}\n\n/**\n * Sets the bounding box to use for geocoding requests.\n *\n * @param bounds - The bounding box to set.\n */\nexport function setBounds(bounds: string): void {\n defaultOptions.bounds = bounds;\n}\n\n/**\n * Sets the result type filter to use for geocoding requests.\n * One or more address types to return, separated by a pipe (|).\n * Possible values are \"street_address\", \"route\", \"intersection\", \"political\", \"country\",\n * \"administrative_area_level_1\", \"administrative_area_level_2\", \"administrative_area_level_3\",\n * \"administrative_area_level_4\", \"administrative_area_level_5\", \"colloquial_area\", \"locality\",\n * \"ward\", \"sublocality\", \"neighborhood\", \"premise\", \"subpremise\", \"postal_code\", \"natural_feature\",\n * \"airport\", \"park\", \"point_of_interest\", and \"postal_code_prefix\".\n *\n * @param resultType - The result type to set.\n */\nexport function setResultType(resultType: string): void {\n defaultOptions.result_type = resultType;\n}\n\n/**\n * Sets the location type filter to use for geocoding requests.\n * One or more location types to return. Possible values are \"ROOFTOP\",\n * \"RANGE_INTERPOLATED\", \"GEOMETRIC_CENTER\", \"APPROXIMATE\".\n *\n * @param locationType - The location type to set.\n */\nexport function setLocationType(locationType: string): void {\n defaultOptions.location_type = locationType;\n}\n\n/**\n * Sets the desired output format for geocoding requests. The format can be either XML or JSON.\n *\n * @param outputFormat - The desired output format (either OutputFormat.XML or OutputFormat.JSON).\n */\nexport function setOutputFormat(outputFormat: OutputFormat): void {\n defaultOptions.outputFormat = outputFormat;\n}\n\n/**\n * Sets whether to include an address descriptor in the reverse geocoding response.\n *\n * @param enableAddressDescriptor - A boolean parameter indicating whether to include the address descriptor.\n */\nexport function enableAddressDescriptor(\n enableAddressDescriptor: boolean,\n): void {\n defaultOptions.enable_address_descriptor = enableAddressDescriptor;\n}\n\n/**\n * Sends a geocoding request to the Google Maps Geocoding API for a given address and returns the response.\n * @function geocode\n * @async\n * @param {RequestType} requestType - Identifier to specify the type of request (place_id, address, or latlng).\n * @param {string} value - The value to be used for geocoding (address, place_id, or latlng).\n * @param {GeocodeOptions} [options={}] - Additional options for the geocoding request.\n * @returns {Promise} - A promise that resolves with the geocoding response object.\n * @throws {Error} - Throws an error if the address is invalid or the geocoding request fails.\n */\nexport function geocode(\n requestType: RequestType | string,\n value: string,\n options?: GeocodeOptions,\n): Promise {\n if (typeof requestType !== \"string\" || typeof value !== \"string\") {\n throw new Error(\n `Both requestType and value are required and must be of type string. \n requestType: ${typeof requestType}, value: ${typeof value}`,\n );\n }\n\n const queryParams: GeocodeQueryParams = {\n ...defaultOptions,\n ...options,\n [requestType]: value,\n };\n return geocodeRequest(queryParams);\n}\n\n/**\n * @deprecated Use `geocode` instead.\n * Usage: geocode(\"address\", \"Washington\", *options)\n */\nexport function fromAddress(\n address: string,\n key?: string,\n language?: string,\n region?: string,\n) {\n const options: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n };\n if (key) {\n options.key = key;\n }\n if (language) {\n options.language = language;\n }\n if (region) {\n options.region = region;\n }\n return geocode(RequestType.ADDRESS, address, options);\n}\n\n/**\n * @deprecated use `geocode` instead\n * Usage: geocode(\"place_id\", \"ChIJd8BlQ2BZwokRAFUEcm_qrcA\", *options)\n */\nexport function fromPlaceId(\n placeId: string,\n key?: string,\n language?: string,\n region?: string,\n) {\n const options: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n };\n if (key) {\n options.key = key;\n }\n if (language) {\n options.language = language;\n }\n if (region) {\n options.region = region;\n }\n return geocode(RequestType.PLACE_ID, placeId, options);\n}\n\n/**\n * @deprecated use `geocode` instead\n * Usage: geocode(\"latlng\", \"40.714224,-73.961452\", *options)\n */\nexport function fromLatLng(\n lat: number,\n lng: number,\n key?: string,\n language?: string,\n region?: string,\n location_type?: string,\n) {\n const options: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n };\n if (key) {\n options.key = key;\n }\n if (language) {\n options.language = language;\n }\n if (region) {\n options.region = region;\n }\n if (location_type) {\n options.location_type = location_type;\n }\n return geocode(RequestType.LATLNG, `${lat},${lng}`, options);\n}\n\ninterface GeocodeResult {\n address_components: AddressComponent[];\n formatted_address: string;\n geometry: Geometry;\n place_id: string;\n plus_code: PlusCode;\n types: string[];\n}\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\n\ninterface Geometry {\n location: {\n lat: number;\n lng: number;\n };\n location_type: string;\n viewport: {\n lat: number;\n lng: number;\n };\n southwest: {\n lat: number;\n lng: number;\n };\n}\n\ninterface AddressDescriptor {\n area: AreaDescriptor[];\n landmarks: Landmark[];\n}\n\ninterface AreaDescriptor {\n containment: string;\n display_name: {\n language_code: string;\n text: string;\n };\n place_id: string;\n}\n\ninterface Landmark {\n display_name: {\n language_code: string;\n text: string;\n };\n straight_line_distance_meters: number;\n place_id: string;\n travel_distance_meters: number;\n spatial_relationship: string;\n types: string[];\n}\n\ninterface PlusCode {\n compound_code: string;\n global_code: string;\n}\n"],"names":["RequestType","OutputFormat","GOOGLE_GEOCODE_API","defaultOptions","geocodeRequest","queryParams","outputFormat","restParams","queryString","url","json","status","error_message","error","setDefaults","options","setKey","key","setLanguage","language","setRegion","region","setComponents","components","setBounds","bounds","setResultType","resultType","setLocationType","locationType","setOutputFormat","enableAddressDescriptor","geocode","requestType","value","fromAddress","address","fromPlaceId","placeId","fromLatLng","lat","lng","location_type"],"mappings":"AAGY,IAAAA,sBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,SAAS,UACTA,EAAA,WAAW,YAHDA,IAAAA,KAAA,CAAA,CAAA,GASAC,sBAAAA,OACVA,EAAA,MAAM,OACNA,EAAA,OAAO,QAFGA,IAAAA,KAAA,CAAA,CAAA;AAQZ,MAAMC,IAAqB;AAwC3B,IAAIC,IAAiC;AAAA,EACnC,cAAc;AAAA;AAChB;AAUA,eAAeC,EACbC,GAC0B;AAC1B,QAAM,EAAE,cAAAC,GAAc,GAAGC,EAAA,IAAeF,GAClCG,IAAc,IAAI;AAAA,IACtBD;AAAA,IACA,SAAS,GACLE,IAAM,GAAGP,CAAkB,IAAII,CAAY,IAAIE,CAAW;AAC5D,MAAA;AAEI,UAAAE,IAAO,OADI,MAAM,MAAMD,CAAG,GACJ,QACtB,EAAE,QAAAE,GAAQ,eAAAC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AMO,SAAS8B,EACdC,GACAnB,GACAE,GACAE,GACA;AACA,QAAMN,IAA0B;AAAA,IAC9B,cAAc;AAAA;AAAA,EAAA;AAEhB,SAAIE,MACFF,EAAQ,MAAME,IAEZE,MACFJ,EAAQ,WAAWI,IAEjBE,MACFN,EAAQ,SAASM,IAEZW,EAAQ,WAAqBI,GAASrB,CAAO;AACtD;AAMO,SAASsB,EACdC,GACArB,GACAE,GACAE,GACA;AACA,QAAMN,IAA0B;AAAA,IAC9B,cAAc;AAAA;AAAA,EAAA;AAEhB,SAAIE,MACFF,EAAQ,MAAME,IAEZE,MACFJ,EAAQ,WAAWI,IAEjBE,MACFN,EAAQ,SAASM,IAEZW,EAAQ,YAAsBM,GAASvB,CAAO;AACvD;AAMO,SAASwB,EACdC,GACAC,GACAxB,GACAE,GACAE,GACAqB,GACA;AACA,QAAM3B,IAA0B;AAAA,IAC9B,cAAc;AAAA;AAAA,EAAA;AAEhB,SAAIE,MACFF,EAAQ,MAAME,IAEZE,MACFJ,EAAQ,WAAWI,IAEjBE,MACFN,EAAQ,SAASM,IAEfqB,MACF3B,EAAQ,gBAAgB2B,IAEnBV,EAAQ,UAAoB,GAAGQ,CAAG,IAAIC,CAAG,IAAI1B,CAAO;AAC7D;"} \ No newline at end of file diff --git a/dist/index.umd.js b/dist/index.umd.js deleted file mode 100644 index b37267f..0000000 --- a/dist/index.umd.js +++ /dev/null @@ -1,3 +0,0 @@ -(function(t,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(t=typeof globalThis<"u"?globalThis:t||self,f(t["react-geocode"]={}))})(this,function(t){"use strict";var f=(e=>(e.ADDRESS="address",e.LATLNG="latlng",e.PLACE_ID="place_id",e))(f||{}),d=(e=>(e.XML="xml",e.JSON="json",e))(d||{});const l="https://maps.googleapis.com/maps/api/geocode";let s={outputFormat:"json"};async function m(e){const{outputFormat:o,...r}=e,i=new URLSearchParams(r).toString(),n=`${l}/${o}?${i}`;try{const u=await(await fetch(n)).json(),{status:g,error_message:D}=u;if(g==="OK")return u;throw new Error(`Geocoding failed: ${D}. Server returned status code ${g}.`)}catch(a){throw a instanceof Error?new Error(`Geocoding request failed: ${a.message}`):new Error(`Geocoding request failed with unknown error: ${a}`)}}function p(e){s={...s,...e}}function y(e){s.key=e}function L(e){s.language=e}function h(e){s.region=e}function w(e){s.components=e}function $(e){s.bounds=e}function E(e){s.result_type=e}function O(e){s.location_type=e}function _(e){s.outputFormat=e}function j(e){s.enable_address_descriptor=e}function c(e,o,r){if(typeof e!="string"||typeof o!="string")throw new Error(`Both requestType and value are required and must be of type string. - requestType: ${typeof e}, value: ${typeof o}`);const i={...s,...r,[e]:o};return m(i)}function S(e,o,r,i){const n={outputFormat:"json"};return o&&(n.key=o),r&&(n.language=r),i&&(n.region=i),c("address",e,n)}function b(e,o,r,i){const n={outputFormat:"json"};return o&&(n.key=o),r&&(n.language=r),i&&(n.region=i),c("place_id",e,n)}function A(e,o,r,i,n,a){const u={outputFormat:"json"};return r&&(u.key=r),i&&(u.language=i),n&&(u.region=n),a&&(u.location_type=a),c("latlng",`${e},${o}`,u)}t.OutputFormat=d,t.RequestType=f,t.enableAddressDescriptor=j,t.fromAddress=S,t.fromLatLng=A,t.fromPlaceId=b,t.geocode=c,t.setBounds=$,t.setComponents=w,t.setDefaults=p,t.setKey=y,t.setLanguage=L,t.setLocationType=O,t.setOutputFormat=_,t.setRegion=h,t.setResultType=E,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})}); -//# sourceMappingURL=index.umd.js.map diff --git a/dist/index.umd.js.map b/dist/index.umd.js.map deleted file mode 100644 index 6def974..0000000 --- a/dist/index.umd.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["/**\n * Enum defining possible request types for geocoding.\n */\nexport enum RequestType {\n ADDRESS = \"address\", // Geocoding by address\n LATLNG = \"latlng\", // Geocoding by latitude and longitude\n PLACE_ID = \"place_id\", // Geocoding by place ID\n}\n\n/**\n * Enum defining possible output formats for geocoding.\n */\nexport enum OutputFormat {\n XML = \"xml\", // Output format XML\n JSON = \"json\", // Output format JSON\n}\n\n/**\n * The URL of the Google Geocoding API.\n */\nconst GOOGLE_GEOCODE_API = \"https://maps.googleapis.com/maps/api/geocode\";\n\n/**\n * Options that can be passed to the geocoding requests.\n */\nexport interface GeocodeOptions {\n key?: string; // API key for the Google Maps Geocoding API.\n language?: string; // Language code for the response.\n region?: string; // Region code for the response.\n components?: string; // Component filtering for the response.\n bounds?: string; // Bounding box for the response.\n result_type?: string; // Result type filtering for the response.\n location_type?: string; // Location type filtering for the response.\n outputFormat: OutputFormat; // Desired output format (either XML or JSON)\n enable_address_descriptor?: boolean; // Whether to include an address descriptor in the reverse geocoding response.\n}\n\n/**\n * Response object from the geocoding API.\n */\ninterface GeocodeResponse {\n status: string;\n results: GeocodeResult[];\n address_descriptor?: AddressDescriptor;\n plus_code?: PlusCode;\n error_message?: string;\n}\n\n/**\n * The query parameters for geocoding requests.\n */\ninterface GeocodeQueryParams extends GeocodeOptions {\n place_id?: string; // The plce id to geocode\n address?: string; // The address to geocode\n latlng?: string; // The latitude/longitude of the location to geocode\n}\n\n/**\n * Default options for the geocoding requests.\n */\nlet defaultOptions: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n};\n\n/**\n * Performs a geocoding request to the Google Geocoding API.\n * @function geocodeRequest\n * @async\n * @param {GeocodeQueryParams} queryParams - The query parameters for the geocoding request.\n * @returns {Promise} - A promise that resolves with the geocoding response object.\n * @throws {Error} - Throws an error if the geocoding request fails.\n */\nasync function geocodeRequest(\n queryParams: GeocodeQueryParams,\n): Promise {\n const { outputFormat, ...restParams } = queryParams;\n const queryString = new URLSearchParams(\n restParams as Record,\n ).toString();\n const url = `${GOOGLE_GEOCODE_API}/${outputFormat}?${queryString}`;\n try {\n const response = await fetch(url);\n const json = await response.json();\n const { status, error_message } = json;\n\n if (status === \"OK\") {\n return json;\n }\n\n throw new Error(\n `Geocoding failed: ${error_message}. Server returned status code ${status}.`,\n );\n } catch (error: unknown) {\n if (error instanceof Error) {\n throw new Error(`Geocoding request failed: ${error.message}`);\n }\n throw new Error(`Geocoding request failed with unknown error: ${error}`);\n }\n}\n\n/**\n * Sets default options for geocoding requests.\n *\n * @param options - The default options to set.\n */\nexport function setDefaults(options: GeocodeOptions): void {\n defaultOptions = {\n ...defaultOptions,\n ...options,\n };\n}\n\n/**\n * Sets the API key to use for geocoding requests.\n *\n * @param key - The API key to set.\n */\nexport function setKey(key: string): void {\n defaultOptions.key = key;\n}\n\n/**\n * Sets the language to use for geocoding requests.\n *\n * @param language - The language to set.\n */\nexport function setLanguage(language: string): void {\n defaultOptions.language = language;\n}\n\n/**\n * Sets the region code to use for geocoding requests.\n *\n * @param region - The region code to set.\n */\nexport function setRegion(region: string): void {\n defaultOptions.region = region;\n}\n\n/**\n * Sets the component filter to use for geocoding requests.\n *\n * @param components - The component filter to set.\n */\nexport function setComponents(components: string): void {\n defaultOptions.components = components;\n}\n\n/**\n * Sets the bounding box to use for geocoding requests.\n *\n * @param bounds - The bounding box to set.\n */\nexport function setBounds(bounds: string): void {\n defaultOptions.bounds = bounds;\n}\n\n/**\n * Sets the result type filter to use for geocoding requests.\n * One or more address types to return, separated by a pipe (|).\n * Possible values are \"street_address\", \"route\", \"intersection\", \"political\", \"country\",\n * \"administrative_area_level_1\", \"administrative_area_level_2\", \"administrative_area_level_3\",\n * \"administrative_area_level_4\", \"administrative_area_level_5\", \"colloquial_area\", \"locality\",\n * \"ward\", \"sublocality\", \"neighborhood\", \"premise\", \"subpremise\", \"postal_code\", \"natural_feature\",\n * \"airport\", \"park\", \"point_of_interest\", and \"postal_code_prefix\".\n *\n * @param resultType - The result type to set.\n */\nexport function setResultType(resultType: string): void {\n defaultOptions.result_type = resultType;\n}\n\n/**\n * Sets the location type filter to use for geocoding requests.\n * One or more location types to return. Possible values are \"ROOFTOP\",\n * \"RANGE_INTERPOLATED\", \"GEOMETRIC_CENTER\", \"APPROXIMATE\".\n *\n * @param locationType - The location type to set.\n */\nexport function setLocationType(locationType: string): void {\n defaultOptions.location_type = locationType;\n}\n\n/**\n * Sets the desired output format for geocoding requests. The format can be either XML or JSON.\n *\n * @param outputFormat - The desired output format (either OutputFormat.XML or OutputFormat.JSON).\n */\nexport function setOutputFormat(outputFormat: OutputFormat): void {\n defaultOptions.outputFormat = outputFormat;\n}\n\n/**\n * Sets whether to include an address descriptor in the reverse geocoding response.\n *\n * @param enableAddressDescriptor - A boolean parameter indicating whether to include the address descriptor.\n */\nexport function enableAddressDescriptor(\n enableAddressDescriptor: boolean,\n): void {\n defaultOptions.enable_address_descriptor = enableAddressDescriptor;\n}\n\n/**\n * Sends a geocoding request to the Google Maps Geocoding API for a given address and returns the response.\n * @function geocode\n * @async\n * @param {RequestType} requestType - Identifier to specify the type of request (place_id, address, or latlng).\n * @param {string} value - The value to be used for geocoding (address, place_id, or latlng).\n * @param {GeocodeOptions} [options={}] - Additional options for the geocoding request.\n * @returns {Promise} - A promise that resolves with the geocoding response object.\n * @throws {Error} - Throws an error if the address is invalid or the geocoding request fails.\n */\nexport function geocode(\n requestType: RequestType | string,\n value: string,\n options?: GeocodeOptions,\n): Promise {\n if (typeof requestType !== \"string\" || typeof value !== \"string\") {\n throw new Error(\n `Both requestType and value are required and must be of type string. \n requestType: ${typeof requestType}, value: ${typeof value}`,\n );\n }\n\n const queryParams: GeocodeQueryParams = {\n ...defaultOptions,\n ...options,\n [requestType]: value,\n };\n return geocodeRequest(queryParams);\n}\n\n/**\n * @deprecated Use `geocode` instead.\n * Usage: geocode(\"address\", \"Washington\", *options)\n */\nexport function fromAddress(\n address: string,\n key?: string,\n language?: string,\n region?: string,\n) {\n const options: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n };\n if (key) {\n options.key = key;\n }\n if (language) {\n options.language = language;\n }\n if (region) {\n options.region = region;\n }\n return geocode(RequestType.ADDRESS, address, options);\n}\n\n/**\n * @deprecated use `geocode` instead\n * Usage: geocode(\"place_id\", \"ChIJd8BlQ2BZwokRAFUEcm_qrcA\", *options)\n */\nexport function fromPlaceId(\n placeId: string,\n key?: string,\n language?: string,\n region?: string,\n) {\n const options: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n };\n if (key) {\n options.key = key;\n }\n if (language) {\n options.language = language;\n }\n if (region) {\n options.region = region;\n }\n return geocode(RequestType.PLACE_ID, placeId, options);\n}\n\n/**\n * @deprecated use `geocode` instead\n * Usage: geocode(\"latlng\", \"40.714224,-73.961452\", *options)\n */\nexport function fromLatLng(\n lat: number,\n lng: number,\n key?: string,\n language?: string,\n region?: string,\n location_type?: string,\n) {\n const options: GeocodeOptions = {\n outputFormat: OutputFormat.JSON,\n };\n if (key) {\n options.key = key;\n }\n if (language) {\n options.language = language;\n }\n if (region) {\n options.region = region;\n }\n if (location_type) {\n options.location_type = location_type;\n }\n return geocode(RequestType.LATLNG, `${lat},${lng}`, options);\n}\n\ninterface GeocodeResult {\n address_components: AddressComponent[];\n formatted_address: string;\n geometry: Geometry;\n place_id: string;\n plus_code: PlusCode;\n types: string[];\n}\n\ninterface AddressComponent {\n long_name: string;\n short_name: string;\n types: string[];\n}\n\ninterface Geometry {\n location: {\n lat: number;\n lng: number;\n };\n location_type: string;\n viewport: {\n lat: number;\n lng: number;\n };\n southwest: {\n lat: number;\n lng: number;\n };\n}\n\ninterface AddressDescriptor {\n area: AreaDescriptor[];\n landmarks: Landmark[];\n}\n\ninterface AreaDescriptor {\n containment: string;\n display_name: {\n language_code: string;\n text: string;\n };\n place_id: string;\n}\n\ninterface Landmark {\n display_name: {\n language_code: string;\n text: string;\n };\n straight_line_distance_meters: number;\n place_id: string;\n travel_distance_meters: number;\n spatial_relationship: string;\n types: string[];\n}\n\ninterface PlusCode {\n compound_code: string;\n global_code: string;\n}\n"],"names":["RequestType","OutputFormat","GOOGLE_GEOCODE_API","defaultOptions","geocodeRequest","queryParams","outputFormat","restParams","queryString","url","json","status","error_message","error","setDefaults","options","setKey","key","setLanguage","language","setRegion","region","setComponents","components","setBounds","bounds","setResultType","resultType","setLocationType","locationType","setOutputFormat","enableAddressDescriptor","geocode","requestType","value","fromAddress","address","fromPlaceId","placeId","fromLatLng","lat","lng","location_type"],"mappings":"wOAGY,IAAAA,GAAAA,IACVA,EAAA,QAAU,UACVA,EAAA,OAAS,SACTA,EAAA,SAAW,WAHDA,IAAAA,GAAA,CAAA,CAAA,EASAC,GAAAA,IACVA,EAAA,IAAM,MACNA,EAAA,KAAO,OAFGA,IAAAA,GAAA,CAAA,CAAA,EAQZ,MAAMC,EAAqB,+CAwC3B,IAAIC,EAAiC,CACnC,aAAc,MAChB,EAUA,eAAeC,EACbC,EAC0B,CAC1B,KAAM,CAAE,aAAAC,EAAc,GAAGC,CAAA,EAAeF,EAClCG,EAAc,IAAI,gBACtBD,GACA,SAAS,EACLE,EAAM,GAAGP,CAAkB,IAAII,CAAY,IAAIE,CAAW,GAC5D,GAAA,CAEI,MAAAE,EAAO,MADI,MAAM,MAAMD,CAAG,GACJ,OACtB,CAAE,OAAAE,EAAQ,cAAAC,CAAkB,EAAAF,EAElC,GAAIC,IAAW,KACN,OAAAD,EAGT,MAAM,IAAI,MACR,qBAAqBE,CAAa,iCAAiCD,CAAM,GAAA,QAEpEE,EAAgB,CACvB,MAAIA,aAAiB,MACb,IAAI,MAAM,6BAA6BA,EAAM,OAAO,EAAE,EAExD,IAAI,MAAM,gDAAgDA,CAAK,EAAE,CACzE,CACF,CAOO,SAASC,EAAYC,EAA+B,CACxCZ,EAAA,CACf,GAAGA,EACH,GAAGY,CAAA,CAEP,CAOO,SAASC,EAAOC,EAAmB,CACxCd,EAAe,IAAMc,CACvB,CAOO,SAASC,EAAYC,EAAwB,CAClDhB,EAAe,SAAWgB,CAC5B,CAOO,SAASC,EAAUC,EAAsB,CAC9ClB,EAAe,OAASkB,CAC1B,CAOO,SAASC,EAAcC,EAA0B,CACtDpB,EAAe,WAAaoB,CAC9B,CAOO,SAASC,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