google-maps-js-api-loader
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -1,3 +0,3 @@ | ||
import { LoaderOptions } from "./types"; | ||
export { LoaderOptions }; | ||
import type { LoaderOptions, Library } from "./types"; | ||
export type { LoaderOptions, Library }; | ||
export declare enum LoaderStatus { | ||
@@ -10,14 +10,30 @@ NONE = 0, | ||
declare class Loader { | ||
static options: LoaderOptions; | ||
private static _resolve?; | ||
private static _reject?; | ||
private static _options?; | ||
/** | ||
* @throws error if options will be set more then 1 time | ||
*/ | ||
static setOptions(options: LoaderOptions): void; | ||
/** | ||
* Callback which will be fired after loading starts | ||
*/ | ||
static onLoadingStart: () => void; | ||
/** Current status of {@link Loader} */ | ||
static get status(): LoaderStatus; | ||
static status: LoaderStatus; | ||
/** | ||
* Promise of loading, it has pending status even if {@link load} not called yet (can be useful if you want to do something after loading done, but don't want to start loading) | ||
* Promise of loading | ||
* | ||
* **Resolves** if [load](#load) is success | ||
* | ||
* **Rejects** when | ||
* | ||
* - Maps JavaScript API was loaded outside of this library | ||
* - no options was [set](#setoptions) | ||
* - script loading failed | ||
*/ | ||
static get completion(): Promise<void>; | ||
static readonly completion: Promise<void>; | ||
/** | ||
* Starts loading of Google Maps JavaScript API with given {@link options} (if it not loaded yet) | ||
* @returns {} {@link completion} | ||
* @throws error if {@link google.maps} already loaded by something else or if no {@link options} was provided | ||
* On the first call, it starts loading {@link google.maps} with the given {@link options} | ||
* @returns {@link completion} | ||
*/ | ||
@@ -24,0 +40,0 @@ static load(): Promise<void>; |
@@ -1,11 +0,68 @@ | ||
import type { LoaderOptions as _LoaderOptions } from "@googlemaps/js-api-loader"; | ||
export declare type LoaderOptions = Omit<_LoaderOptions, "id" | "retries"> & { | ||
export declare type Library = "drawing" | "geometry" | "localContext" | "places" | "visualization"; | ||
export declare type LoaderOptions = { | ||
/** | ||
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async | ||
* Your [API key](https://developers.google.com/maps/documentation/javascript/get-api-key). The Maps JavaScript API will not load unless a valid API key is specified | ||
*/ | ||
apiKey: string; | ||
/** | ||
* @deprecated | ||
* @see https://developers.google.com/maps/premium/overview | ||
*/ | ||
channel?: string; | ||
/** | ||
* @deprecated use {@link LoaderOptions.apiKey apiKey} instead | ||
* @see https://developers.google.com/maps/premium/overview | ||
*/ | ||
client?: string; | ||
/** | ||
* The [version](https://developers.google.com/maps/documentation/javascript/versions) of the Maps JavaScript API to use | ||
*/ | ||
version?: string; | ||
/** | ||
* Array of additional Maps JavaScript API [libraries](https://developers.google.com/maps/documentation/javascript/libraries) to load | ||
*/ | ||
libraries?: Library[]; | ||
/** | ||
* The [language](https://developers.google.com/maps/documentation/javascript/localization) to use. This affects the names of controls, copyright notices, driving directions, and control labels, as well as the responses to service requests. See the [list of supported languages](https://developers.google.com/maps/faq#languagesupport) | ||
*/ | ||
language?: string; | ||
/** | ||
* The [region](https://developers.google.com/maps/documentation/javascript/localization#Region) code to use. This alters the map's behavior based on a given country or territory | ||
*/ | ||
region?: string; | ||
/** | ||
* @deprecated Passing `mapIds` is no longer required in the script tag | ||
*/ | ||
mapIds?: string[]; | ||
/** | ||
* Maps JS customers can configure HTTP Referrer Restrictions in the Cloud Console to limit which URLs are allowed to use a particular API Key. By default, these restrictions can be configured to allow only certain paths to use an API Key. If any URL on the same domain or origin may use the API Key, you can set `"origin"` to limit the amount of data sent when authorizing requests from the Maps JavaScript API. This is available starting in version **3.46**. When this parameter is specified and HTTP Referrer Restrictions are enabled on Cloud Console, Maps JavaScript API will only be able to load if there is an HTTP Referrer Restriction that matches the current website's domain without a path specified | ||
*/ | ||
authReferrerPolicy?: "origin"; | ||
/** | ||
* Use a custom url and path to load the Google Maps API script | ||
* @default "https://maps.googleapis.com/maps/api/js" | ||
*/ | ||
url?: string; | ||
/** | ||
* Adds {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce nonce} attribute to the script | ||
*/ | ||
nonce?: string; | ||
/** | ||
* Adds {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async async} attribute to the script | ||
*/ | ||
async?: boolean; | ||
/** | ||
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer | ||
* Adds {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer defer} attribute to the script | ||
*/ | ||
defer?: boolean; | ||
/** | ||
* Number of retries if script loading fails | ||
* @default 2 | ||
*/ | ||
retryCount?: number; | ||
/** | ||
* Delay between retries | ||
* @default 2000 | ||
*/ | ||
retryDelay?: number; | ||
}; |
@@ -1,4 +0,2 @@ | ||
import { LoaderOptions } from "./types"; | ||
export declare const CALLBACK_NAME = "__googleMapsCallback"; | ||
export declare const CALLBACK_NAME = "__gmlc"; | ||
export declare const noop: () => void; | ||
export declare const handleScript: (options: LoaderOptions, reject: (err: ErrorEvent) => void) => void; |
{ | ||
"name": "google-maps-js-api-loader", | ||
"version": "2.0.1", | ||
"description": "Wrapper for the loading of Google Maps JavaScript API script in the browser", | ||
"version": "2.1.0", | ||
"description": "Async loader for Maps JavaScript API", | ||
"repository": { | ||
@@ -18,9 +18,9 @@ "type": "git", | ||
"exports": { | ||
"require": "./dist/google-maps-loader.cjs", | ||
"default": "./dist/google-maps-loader.modern.js" | ||
"require": "./dist/index.cjs", | ||
"default": "./dist/index.modern.js" | ||
}, | ||
"main": "./dist/google-maps-loader.cjs", | ||
"module": "./dist/google-maps-loader.module.js", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.module.js", | ||
"types": "./dist/index.d.ts", | ||
"unpkg": "./dist/google-maps-loader.umd.js", | ||
"unpkg": "./dist/index.umd.js", | ||
"scripts": { | ||
@@ -30,9 +30,6 @@ "build": "microbundle", | ||
}, | ||
"dependencies": { | ||
"@googlemaps/js-api-loader": "^1.14.1" | ||
}, | ||
"devDependencies": { | ||
"@types/google.maps": "^3.48.7", | ||
"microbundle": "^0.15.0", | ||
"typescript": "^4.6.4" | ||
"@types/google.maps": "^3.50.2", | ||
"microbundle": "^0.15.1", | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -39,0 +36,0 @@ "files": [ |
@@ -5,3 +5,3 @@ # google-maps-js-api-loader | ||
Async loader for google maps api | ||
Async loader for `Maps JavaScript API` | ||
@@ -13,6 +13,6 @@ ## Example | ||
Loader.options = { | ||
Loader.setOptions({ | ||
apiKey: API_KEY, | ||
// ...some other options | ||
}; | ||
}); | ||
@@ -24,10 +24,25 @@ await Loader.load(); | ||
### options | ||
### setOptions | ||
```ts | ||
static options: LoaderOptions | ||
static setOptions(options: LoaderOptions): void | ||
``` | ||
Loader options (query parameters for script url and some script attributes), should be set before [load](#load) execution | ||
Loader options should be set before [load](#load) execution | ||
| LoaderOptions | Description | | | ||
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | | ||
| apiKey | Your [API key](https://developers.google.com/maps/documentation/javascript/get-api-key). The `Maps JavaScript API` will not load unless a valid API key is specified | | | ||
| version? | The [version](https://developers.google.com/maps/documentation/javascript/versions) of the `Maps JavaScript API` to use | | | ||
| libraries? | Array of additional `Maps JavaScript API` [libraries](https://developers.google.com/maps/documentation/javascript/libraries) to load | | | ||
| language? | The [language](https://developers.google.com/maps/documentation/javascript/localization) to use. This affects the names of controls, copyright notices, driving directions, and control labels, as well as the responses to service requests. See the [list of supported languages](https://developers.google.com/maps/faq#languagesupport) | | | ||
| region? | The [region](https://developers.google.com/maps/documentation/javascript/localization#Region) code to use. This alters the map's behavior based on a given country or territory | | | ||
| authReferrerPolicy? | Maps JS customers can configure HTTP Referrer Restrictions in the Cloud Console to limit which URLs are allowed to use a particular API Key. By default, these restrictions can be configured to allow only certain paths to use an API Key. If any URL on the same domain or origin may use the API Key, you can set `"origin"` to limit the amount of data sent when authorizing requests from the `Maps JavaScript API`. This is available starting in version **3.46**. When this parameter is specified and HTTP Referrer Restrictions are enabled on Cloud Console, `Maps JavaScript API` will only be able to load if there is an HTTP Referrer Restriction that matches the current website's domain without a path specified | | | ||
| url? | Use a custom url and path to load the Google Maps API script | | | ||
| nonce? | Adds [nonce](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce) attribute to the script | | | ||
| async? | Adds [async](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async) attribute to the script | | | ||
| defer? | Adds [defer](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer) attribute to the script | | | ||
| retryCount? | Number of retries if script loading fails | `2` | | ||
| retryDelay? | Delay between retries | `2000` | | ||
--- | ||
@@ -38,8 +53,8 @@ | ||
```ts | ||
async static load(): Promise<void> | ||
static load(): Promise<void> | ||
``` | ||
Starts loading of Google Maps JavaScript API with given [options](#options) (if it not loaded yet), returns [completion](#completion) | ||
On the first call, it starts loading the `Maps JavaScript API` with the given [options](#setoptions) | ||
> throws error if google.maps already loaded by something else or if no [options](#options) was provided | ||
Returns [completion](#completion) | ||
@@ -68,11 +83,29 @@ --- | ||
```ts | ||
static completion: Promise<void> | ||
static readonly completion: Promise<void> | ||
``` | ||
Promise of loading, it has pending status even if [load](#load) not called yet (can be useful if you want to do something after loading done, but don't want to start loading) | ||
Promise of loading | ||
**Resolves** if [load](#load) is success | ||
**Rejects** when | ||
- `Maps JavaScript API` was loaded outside of this library | ||
- no options was [set](#setoptions) | ||
- script loading failed | ||
--- | ||
### onLoadingStart | ||
```ts | ||
static onLoadingStart?(): void | ||
``` | ||
Callback which will be fired after loading starts | ||
--- | ||
## License | ||
MIT © [Krombik](https://github.com/Krombik) |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
53996
0
146
107
1
- Removed@googlemaps/js-api-loader@^1.14.1
- Removed@googlemaps/js-api-loader@1.16.8(transitive)