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

google-maps-js-api-loader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-maps-js-api-loader - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

src/index.ts

25

dist/index.d.ts

@@ -9,2 +9,3 @@ import type { LoaderOptions, Library } from "./types";

}
declare type OnError = (err: ErrorEvent | Error) => void;
declare class Loader {

@@ -14,10 +15,14 @@ private static _resolve?;

private static _options?;
/**
* @throws error if options will be set more then 1 time
*/
private static [1]?;
private static [2]?;
private static [3]?;
private static _runListeners;
private static _cleanup;
static setOptions(options: LoaderOptions): void;
/**
* Callback which will be fired after loading starts
* Starts listening for given {@link status} changes and calls the given {@link callback} when it does
* @returns a function that can be used to remove the listener, which can then be invoked in cleanup logic
*/
static onLoadingStart: () => void;
static addListener(status: LoaderStatus.LOADING | LoaderStatus.LOADED, callback: () => void): () => void;
static addListener(status: LoaderStatus.ERROR, callback: OnError): () => void;
/** Current status of {@link Loader} */

@@ -28,9 +33,9 @@ static status: LoaderStatus;

*
* **Resolves** if [load](#load) is success
* **Resolves** if {@link load} is success
*
* **Rejects** when
* **Rejects**
*
* - Maps JavaScript API was loaded outside of this library
* - no options was [set](#setoptions)
* - script loading failed
* - if {@link google.maps} was loaded outside of this library
* - if no options was {@link setOptions set}
* - if script loading failed
*/

@@ -37,0 +42,0 @@ static readonly completion: Promise<void>;

2

dist/index.modern.js

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

var e;!function(e){e[e.NONE=0]="NONE",e[e.LOADING=1]="LOADING",e[e.LOADED=2]="LOADED",e[e.ERROR=3]="ERROR"}(e||(e={}));class o{static setOptions(e){o.setOptions=()=>{throw new Error("options already set")},o.o=e}static load(){if(!o.status){var e;let t;const n=o.o,r=o.t;if(n?null!=(e=window.google)&&e.maps&&(t="Google Maps already loaded"):t="no options was provided",t)r(new Error(t));else{o.status=1,o.onLoadingStart();const e={key:n.apiKey,v:n.version,libraries:n.libraries,channel:n.channel,client:n.client,language:n.language,region:n.region,map_ids:n.mapIds,auth_referrer_policy:n.authReferrerPolicy,callback:"__gmlc"},t=new URL(n.url||"https://maps.googleapis.com/maps/api/js");for(const o in e){const n=e[o];n&&t.searchParams.set(o,"string"==typeof n?n:n.join(","))}const i=t.toString();let{retryCount:s=2}=n;const{retryDelay:a=2e3}=n,c=()=>{const e=document.createElement("script"),o=o=>{s?setTimeout(()=>{s--,document.head.removeChild(e),c()},a):r(o)};e.type="text/javascript","defer"in n&&(e.defer=n.defer),"async"in n&&(e.async=n.async),"nonce"in n&&(e.nonce=n.nonce),e.src=i,e.addEventListener("load",()=>{e.removeEventListener("error",o)},{once:!0}),e.addEventListener("error",o),document.head.appendChild(e)};window.__gmlc=o.i,c()}delete o.o,delete o.t,delete o.i}return o.completion}}o.i=void 0,o.t=void 0,o.o=void 0,o.onLoadingStart=function(){},o.status=0,o.completion=new Promise((e,t)=>{o.i=()=>{o.status=2,e()},o.t=e=>{o.status=3,t(e)}}).finally(()=>{delete window.__gmlc});export{e as LoaderStatus,o as default};
const e=function(){};var t;!function(e){e[e.NONE=0]="NONE",e[e.LOADING=1]="LOADING",e[e.LOADED=2]="LOADED",e[e.ERROR=3]="ERROR"}(t||(t={}));class n{static t(e,t,o){n.status=e,t(o);const r=n[e].values();for(let t=n[e].size;t--;)r.next().value(o)}static o(e){n[e].clear(),delete n[e]}static setOptions(t){n.setOptions=e,n.i=t}static addListener(t,o){const r=n[t];return r?(r.add(o),()=>{r.delete(o)}):e}static load(){if(!n.status){var t;let o;const r=n.i,s=n.l;if(r?null!=(t=window.google)&&t.maps&&(o="Google Maps already loaded"):o="no options was provided",o)s(new Error(o));else{n.t(1,e),n.o(1);let{retryCount:t=2}=r;const{retryDelay:o=2e3}=r,i=new URL(r.url||"https://maps.googleapis.com/maps/api/js"),a={key:r.apiKey,v:r.version,libraries:r.libraries,channel:r.channel,client:r.client,language:r.language,region:r.region,map_ids:r.mapIds,auth_referrer_policy:r.authReferrerPolicy,callback:"__gmlc"};for(const e in a){const t=a[e];t&&i.searchParams.set(e,"string"==typeof t?t:t.join(","))}const c=()=>{const e=e=>{t--?setTimeout(()=>{c(),a.removeChild(n)},o):s(e)},n=document.createElement("script"),{head:a}=document;n.type="text/javascript","defer"in r&&(n.defer=r.defer),"async"in r&&(n.async=r.async),"nonce"in r&&(n.nonce=r.nonce),n.src=i.toString(),n.addEventListener("load",()=>{n.removeEventListener("error",e)},{once:!0}),n.addEventListener("error",e),a.appendChild(n)};window.__gmlc=n.p,c()}delete n.i,delete n.l,delete n.p}return n.completion}}n.p=void 0,n.l=void 0,n.i=void 0,n[1]=new Set,n[2]=new Set,n[3]=new Set,n.status=0,n.completion=new Promise((e,t)=>{function o(e,t){return o=>{n.t(e,t,o),n.o(2),n.o(3),delete n.t,delete n.o,delete window.__gmlc}}n.p=o(2,e),n.l=o(3,t)});export{t as LoaderStatus,n as default};
//# sourceMappingURL=index.modern.js.map

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

var n;!function(n){n[n.NONE=0]="NONE",n[n.LOADING=1]="LOADING",n[n.LOADED=2]="LOADED",n[n.ERROR=3]="ERROR"}(n||(n={}));var e=/*#__PURE__*/function(){function n(){}return n.setOptions=function(e){n.setOptions=function(){throw new Error("options already set")},n.o=e},n.load=function(){if(!n.status){var e,o,i=n.o,r=n.i;if(i?null!=(e=window.google)&&e.maps&&(o="Google Maps already loaded"):o="no options was provided",o)r(new Error(o));else{n.status=1,n.onLoadingStart();var t={key:i.apiKey,v:i.version,libraries:i.libraries,channel:i.channel,client:i.client,language:i.language,region:i.region,map_ids:i.mapIds,auth_referrer_policy:i.authReferrerPolicy,callback:"__gmlc"},a=new URL(i.url||"https://maps.googleapis.com/maps/api/js");for(var c in t){var d=t[c];d&&a.searchParams.set(c,"string"==typeof d?d:d.join(","))}var u=a.toString(),f=i.retryCount,l=void 0===f?2:f,s=i.retryDelay,v=void 0===s?2e3:s;window.__gmlc=n.t,function n(){var e=document.createElement("script"),o=function(o){l?setTimeout(function(){l--,document.head.removeChild(e),n()},v):r(o)};e.type="text/javascript","defer"in i&&(e.defer=i.defer),"async"in i&&(e.async=i.async),"nonce"in i&&(e.nonce=i.nonce),e.src=u,e.addEventListener("load",function(){e.removeEventListener("error",o)},{once:!0}),e.addEventListener("error",o),document.head.appendChild(e)}()}delete n.o,delete n.i,delete n.t}return n.completion},n}();e.t=void 0,e.i=void 0,e.o=void 0,e.onLoadingStart=function(){},e.status=0,e.completion=new Promise(function(n,o){e.t=function(){e.status=2,n()},e.i=function(n){e.status=3,o(n)}}).finally(function(){delete window.__gmlc});export{n as LoaderStatus,e as default};
var e,n=function(){};!function(e){e[e.NONE=0]="NONE",e[e.LOADING=1]="LOADING",e[e.LOADED=2]="LOADED",e[e.ERROR=3]="ERROR"}(e||(e={}));var o=/*#__PURE__*/function(){function e(){}return e.o=function(n,o,t){e.status=n,o(t);for(var i=e[n].values(),r=e[n].size;r--;)i.next().value(t)},e.t=function(n){e[n].clear(),delete e[n]},e.setOptions=function(o){e.setOptions=n,e.i=o},e.addListener=function(o,t){var i=e[o];return i?(i.add(t),function(){i.delete(t)}):n},e.load=function(){if(!e.status){var o,t,i=e.i,r=e.u;if(i?null!=(o=window.google)&&o.maps&&(t="Google Maps already loaded"):t="no options was provided",t)r(new Error(t));else{e.o(1,n),e.t(1);var a=i.retryCount,c=void 0===a?2:a,u=i.retryDelay,d=void 0===u?2e3:u,f=new URL(i.url||"https://maps.googleapis.com/maps/api/js"),l={key:i.apiKey,v:i.version,libraries:i.libraries,channel:i.channel,client:i.client,language:i.language,region:i.region,map_ids:i.mapIds,auth_referrer_policy:i.authReferrerPolicy,callback:"__gmlc"};for(var s in l){var v=l[s];v&&f.searchParams.set(s,"string"==typeof v?v:v.join(","))}window.__gmlc=e.l,function e(){var n=function(n){c--?setTimeout(function(){e(),t.removeChild(o)},d):r(n)},o=document.createElement("script"),t=document.head;o.type="text/javascript","defer"in i&&(o.defer=i.defer),"async"in i&&(o.async=i.async),"nonce"in i&&(o.nonce=i.nonce),o.src=f.toString(),o.addEventListener("load",function(){o.removeEventListener("error",n)},{once:!0}),o.addEventListener("error",n),t.appendChild(o)}()}delete e.i,delete e.u,delete e.l}return e.completion},e}();o.l=void 0,o.u=void 0,o.i=void 0,o[1]=new Set,o[2]=new Set,o[3]=new Set,o.status=0,o.completion=new Promise(function(e,n){function t(e,n){return function(t){o.o(e,n,t),o.t(2),o.t(3),delete o.o,delete o.t,delete window.__gmlc}}o.l=t(2,e),o.u=t(3,n)});export{e as LoaderStatus,o as default};
//# sourceMappingURL=index.module.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).googleMapsJsApiLoader={})}(this,function(e){var n;e.LoaderStatus=void 0,(n=e.LoaderStatus||(e.LoaderStatus={}))[n.NONE=0]="NONE",n[n.LOADING=1]="LOADING",n[n.LOADED=2]="LOADED",n[n.ERROR=3]="ERROR";var o=/*#__PURE__*/function(){function e(){}return e.setOptions=function(n){e.setOptions=function(){throw new Error("options already set")},e.o=n},e.load=function(){if(!e.status){var n,o,i=e.o,t=e.i;if(i?null!=(n=window.google)&&n.maps&&(o="Google Maps already loaded"):o="no options was provided",o)t(new Error(o));else{e.status=1,e.onLoadingStart();var r={key:i.apiKey,v:i.version,libraries:i.libraries,channel:i.channel,client:i.client,language:i.language,region:i.region,map_ids:i.mapIds,auth_referrer_policy:i.authReferrerPolicy,callback:"__gmlc"},a=new URL(i.url||"https://maps.googleapis.com/maps/api/js");for(var c in r){var d=r[c];d&&a.searchParams.set(c,"string"==typeof d?d:d.join(","))}var f=a.toString(),u=i.retryCount,l=void 0===u?2:u,s=i.retryDelay,p=void 0===s?2e3:s;window.__gmlc=e.t,function e(){var n=document.createElement("script"),o=function(o){l?setTimeout(function(){l--,document.head.removeChild(n),e()},p):t(o)};n.type="text/javascript","defer"in i&&(n.defer=i.defer),"async"in i&&(n.async=i.async),"nonce"in i&&(n.nonce=i.nonce),n.src=f,n.addEventListener("load",function(){n.removeEventListener("error",o)},{once:!0}),n.addEventListener("error",o),document.head.appendChild(n)}()}delete e.o,delete e.i,delete e.t}return e.completion},e}();o.t=void 0,o.i=void 0,o.o=void 0,o.onLoadingStart=function(){},o.status=0,o.completion=new Promise(function(e,n){o.t=function(){o.status=2,e()},o.i=function(e){o.status=3,n(e)}}).finally(function(){delete window.__gmlc}),e.default=o});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).googleMapsJsApiLoader={})}(this,function(e){var n,o=function(){};e.LoaderStatus=void 0,(n=e.LoaderStatus||(e.LoaderStatus={}))[n.NONE=0]="NONE",n[n.LOADING=1]="LOADING",n[n.LOADED=2]="LOADED",n[n.ERROR=3]="ERROR";var i=/*#__PURE__*/function(){function e(){}return e.o=function(n,o,i){e.status=n,o(i);for(var t=e[n].values(),r=e[n].size;r--;)t.next().value(i)},e.i=function(n){e[n].clear(),delete e[n]},e.setOptions=function(n){e.setOptions=o,e.t=n},e.addListener=function(n,i){var t=e[n];return t?(t.add(i),function(){t.delete(i)}):o},e.load=function(){if(!e.status){var n,i,t=e.t,r=e.u;if(t?null!=(n=window.google)&&n.maps&&(i="Google Maps already loaded"):i="no options was provided",i)r(new Error(i));else{e.o(1,o),e.i(1);var f=t.retryCount,c=void 0===f?2:f,d=t.retryDelay,a=void 0===d?2e3:d,u=new URL(t.url||"https://maps.googleapis.com/maps/api/js"),l={key:t.apiKey,v:t.version,libraries:t.libraries,channel:t.channel,client:t.client,language:t.language,region:t.region,map_ids:t.mapIds,auth_referrer_policy:t.authReferrerPolicy,callback:"__gmlc"};for(var s in l){var p=l[s];p&&u.searchParams.set(s,"string"==typeof p?p:p.join(","))}window.__gmlc=e.l,function e(){var n=function(n){c--?setTimeout(function(){e(),i.removeChild(o)},a):r(n)},o=document.createElement("script"),i=document.head;o.type="text/javascript","defer"in t&&(o.defer=t.defer),"async"in t&&(o.async=t.async),"nonce"in t&&(o.nonce=t.nonce),o.src=u.toString(),o.addEventListener("load",function(){o.removeEventListener("error",n)},{once:!0}),o.addEventListener("error",n),i.appendChild(o)}()}delete e.t,delete e.u,delete e.l}return e.completion},e}();i.l=void 0,i.u=void 0,i.t=void 0,i[1]=new Set,i[2]=new Set,i[3]=new Set,i.status=0,i.completion=new Promise(function(e,n){function o(e,n){return function(o){i.o(e,n,o),i.i(2),i.i(3),delete i.o,delete i.i,delete window.__gmlc}}i.l=o(2,e),i.u=o(3,n)}),e.default=i});
//# sourceMappingURL=index.umd.js.map
{
"name": "google-maps-js-api-loader",
"version": "2.1.0",
"description": "Async loader for Maps JavaScript API",
"version": "2.2.0",
"description": "Google Maps JavaScript API loader",
"repository": {

@@ -35,3 +35,4 @@ "type": "git",

"files": [
"dist"
"dist",
"src"
],

@@ -38,0 +39,0 @@ "keywords": [

@@ -5,3 +5,3 @@ # google-maps-js-api-loader

Async loader for `Maps JavaScript API`
`Google Maps JavaScript API` loader

@@ -11,3 +11,3 @@ ## Example

```ts
import Loader from "google-maps-js-api-loader";
import Loader, { LoaderStatus } from "google-maps-js-api-loader";

@@ -19,2 +19,8 @@ Loader.setOptions({

const unlisten = Loader.addListener(LoaderStatus.LOADED, () =>
console.log("google.maps is ready")
);
Loader.completion.then(() => console.log("google.maps is ready"));
await Loader.load();

@@ -33,16 +39,16 @@ ```

| 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` |
| LoaderOptions | Description | |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
| apiKey | Your [API key](https://developers.google.com/maps/documentation/javascript/get-api-key). The `Google 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 `Google Maps JavaScript API` to use | |
| libraries? | Array of additional `Google 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 `Google 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, `Google 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 attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-nonce) to the script | |
| async? | Adds [async attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async) to the script | |
| defer? | Adds [defer attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer) to the script | |
| retryCount? | Number of retries if script loading fails | `2` |
| retryDelay? | Delay between retries | `2000` |

@@ -57,3 +63,3 @@ ---

On the first call, it starts loading the `Maps JavaScript API` with the given [options](#setoptions)
On the first call, it starts loading the `Google Maps JavaScript API` with the given [options](#setoptions)

@@ -91,18 +97,21 @@ Returns ‎[completion](#completion)

**Rejects** when
**Rejects**
- `Maps JavaScript API` was loaded outside of this library
- no options was [set](#setoptions)
- script loading failed
- if `Google Maps JavaScript API` was loaded outside of this library
- if no options was [set](#setoptions)
- if script loading failed
---
### onLoadingStart
### addListener
```ts
static onLoadingStart?(): void
static addListener(status: LoaderStatus.LOADING | LoaderStatus.LOADED, callback: () => void): () => void;
static addListener(status: LoaderStatus.ERROR, callback: OnError): () => void;
```
Callback which will be fired after loading starts
Starts listening for given `status` changes and calls the given `callback` when it does
Returns a function that can be used to remove the listener, which can then be invoked in cleanup logic
---

@@ -109,0 +118,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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