New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 1.1.2 to 2.0.0

2

dist/google-maps-loader.modern.js

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

import t from"fast-deep-equal";import{stringifyUrl as e}from"query-string";function a(){return a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&(t[s]=a[s])}return t},a.apply(this,arguments)}const s=function(){};var o;!function(t){t[t.NONE=0]="NONE",t[t.LOADING=1]="LOADING",t[t.LOADED=2]="LOADED",t[t.ERROR=3]="ERROR"}(o||(o={}));class r{static get status(){return this._status}static get completion(){return this._promise}static get libraries(){return this._options.libraries||[]}static async load(r,i){if(this._options){if(!t(this._options,r))throw new Error("Loader must not be called again with different options")}else{if(window.google&&window.google.maps)throw new Error("Google Maps already loaded");let t;this._options=r,this._status=o.LOADING,(i||s)(),this._promise=new Promise((e,a)=>{window.__googleMapsCallback=()=>{this._status=o.LOADED,e(),delete window.__googleMapsCallback},t=t=>{this._status=o.ERROR,a(t)}}),((t,s)=>{const{params:o,url:r,nonce:i}=(t=>({params:{key:t.apiKey,channel:t.channel,client:t.client,v:t.version,language:t.language,region:t.region,map_ids:t.mapIds,libraries:t.libraries},url:t.url||"https://maps.googleapis.com/maps/api/js",nonce:t.nonce}))(t),n=document.createElement("script");n.src=e({url:r,query:a({},o,{callback:"__googleMapsCallback"})},{skipEmptyString:!0,arrayFormat:"comma"}),n.type="text/javascript",n.defer=!0,n.async=!0,n.addEventListener("error",s),i&&(n.nonce=i),document.head.appendChild(n)})(r,t)}return this._promise}}r._status=o.NONE,r._options=void 0,r._promise=void 0;export{o as LoaderStatus,r as default};
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={}));const t={promise:new Promise((e,o)=>{Object.defineProperties(t,{resolve:{value:e},reject:{value:o}})}),status:e.NONE};class o{static get status(){return t.status}static get completion(){return t.promise}static load(){if(t.status===e.NONE){if(!this.options)throw t.status=e.ERROR,new Error("no options was provided");if(window.google&&window.google.maps)throw t.status=e.ERROR,new Error("Google Maps already loaded");t.status=e.LOADING,this.onLoadingStart(),window.__googleMapsCallback=()=>{t.status=e.LOADED,t.resolve(),delete window.__googleMapsCallback},((o,s)=>{const a=document.createElement("script"),{nonce:r,defer:n,async:i}=o;void 0!==n&&(a.defer=n),void 0!==i&&(a.async=!0),r&&(a.nonce=r),a.src=(e=>{const t={key:e.apiKey,channel:e.channel,client:e.client,v:e.version,language:e.language,region:e.region,map_ids:e.mapIds,libraries:e.libraries,callback:"__googleMapsCallback",auth_referrer_policy:e.authReferrerPolicy},o=Object.keys(t),s=[];for(let e=o.length;e--;){const a=o[e],r=t[a];r&&s.push(`${a}=${Array.isArray(r)?r.join(","):r}`)}const a=e.url||"https://maps.googleapis.com/maps/api/js";return s.length?`${a}?${s.join("&")}`:a})(o),a.type="text/javascript",a.addEventListener("error",o=>{t.status=e.ERROR,t.reject(o)}),document.head.appendChild(a)})(this.options)}return t.promise}}o.options=void 0,o.onLoadingStart=function(){};export{e as LoaderStatus,o as default};
//# sourceMappingURL=google-maps-loader.modern.js.map

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

import e from"fast-deep-equal";import{stringifyUrl as r}from"query-string";function t(){return t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},t.apply(this,arguments)}var n,o=function(){};!function(e){e[e.NONE=0]="NONE",e[e.LOADING=1]="LOADING",e[e.LOADED=2]="LOADED",e[e.ERROR=3]="ERROR"}(n||(n={}));var a=/*#__PURE__*/function(){function a(){}var i,s;return a.load=function(a,i){try{var s=this;if(s._options){if(!e(s._options,a))throw new Error("Loader must not be called again with different options")}else{if(window.google&&window.google.maps)throw new Error("Google Maps already loaded");var l;s._options=a,s._status=n.LOADING,(i||o)(),s._promise=new Promise(function(e,r){window.__googleMapsCallback=function(){s._status=n.LOADED,e(),delete window.__googleMapsCallback},l=function(e){s._status=n.ERROR,r(e)}}),function(e,n){var o=function(e){return{params:{key:e.apiKey,channel:e.channel,client:e.client,v:e.version,language:e.language,region:e.region,map_ids:e.mapIds,libraries:e.libraries},url:e.url||"https://maps.googleapis.com/maps/api/js",nonce:e.nonce}}(e),a=o.params,i=o.url,s=o.nonce,l=document.createElement("script");l.src=r({url:i,query:t({},a,{callback:"__googleMapsCallback"})},{skipEmptyString:!0,arrayFormat:"comma"}),l.type="text/javascript",l.defer=!0,l.async=!0,l.addEventListener("error",n),s&&(l.nonce=s),document.head.appendChild(l)}(a,l)}return Promise.resolve(s._promise)}catch(e){return Promise.reject(e)}},i=a,(s=[{key:"status",get:function(){return this._status}},{key:"completion",get:function(){return this._promise}},{key:"libraries",get:function(){return this._options.libraries||[]}}])&&function(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(i,s),Object.defineProperty(i,"prototype",{writable:!1}),a}();a._status=n.NONE,a._options=void 0,a._promise=void 0;export{n as LoaderStatus,a as default};
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={}));var t={promise:new Promise(function(e,o){Object.defineProperties(t,{resolve:{value:e},reject:{value:o}})}),status:e.NONE},o=/*#__PURE__*/function(){function o(){}var r,n;return o.load=function(){if(t.status===e.NONE){if(!this.options)throw t.status=e.ERROR,new Error("no options was provided");if(window.google&&window.google.maps)throw t.status=e.ERROR,new Error("Google Maps already loaded");t.status=e.LOADING,this.onLoadingStart(),window.__googleMapsCallback=function(){t.status=e.LOADED,t.resolve(),delete window.__googleMapsCallback},o=this.options,r=function(o){t.status=e.ERROR,t.reject(o)},n=document.createElement("script"),a=o.nonce,s=o.async,void 0!==(i=o.defer)&&(n.defer=i),void 0!==s&&(n.async=!0),a&&(n.nonce=a),n.src=function(e){for(var t={key:e.apiKey,channel:e.channel,client:e.client,v:e.version,language:e.language,region:e.region,map_ids:e.mapIds,libraries:e.libraries,callback:"__googleMapsCallback",auth_referrer_policy:e.authReferrerPolicy},o=Object.keys(t),r=[],n=o.length;n--;){var a=o[n],i=t[a];i&&r.push(a+"="+(Array.isArray(i)?i.join(","):i))}var s=e.url||"https://maps.googleapis.com/maps/api/js";return r.length?s+"?"+r.join("&"):s}(o),n.type="text/javascript",n.addEventListener("error",r),document.head.appendChild(n)}var o,r,n,a,i,s;return t.promise},r=o,(n=[{key:"status",get:function(){return t.status}},{key:"completion",get:function(){return t.promise}}])&&function(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(r,n),Object.defineProperty(r,"prototype",{writable:!1}),o}();o.options=void 0,o.onLoadingStart=function(){};export{e as LoaderStatus,o as default};
//# sourceMappingURL=google-maps-loader.module.js.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fast-deep-equal"),require("query-string")):"function"==typeof define&&define.amd?define(["exports","fast-deep-equal","query-string"],t):t((e||self).googleMapsJsApiLoader={},e.fastDeepEqual,e.queryString)}(this,function(e,t,r){function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/n(t);function a(){return a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a.apply(this,arguments)}var i,s="__googleMapsCallback",u=function(){};e.LoaderStatus=void 0,(i=e.LoaderStatus||(e.LoaderStatus={}))[i.NONE=0]="NONE",i[i.LOADING=1]="LOADING",i[i.LOADED=2]="LOADED",i[i.ERROR=3]="ERROR";var l=/*#__PURE__*/function(){function t(){}var n,i;return t.load=function(t,n){try{var i=this;if(i._options){if(!o.default(i._options,t))throw new Error("Loader must not be called again with different options")}else{if(window.google&&window.google.maps)throw new Error("Google Maps already loaded");var l;i._options=t,i._status=e.LoaderStatus.LOADING,(n||u)(),i._promise=new Promise(function(t,r){window[s]=function(){i._status=e.LoaderStatus.LOADED,t(),delete window[s]},l=function(t){i._status=e.LoaderStatus.ERROR,r(t)}}),function(e,t){var n=function(e){return{params:{key:e.apiKey,channel:e.channel,client:e.client,v:e.version,language:e.language,region:e.region,map_ids:e.mapIds,libraries:e.libraries},url:e.url||"https://maps.googleapis.com/maps/api/js",nonce:e.nonce}}(e),o=n.params,i=n.url,u=n.nonce,l=document.createElement("script");l.src=r.stringifyUrl({url:i,query:a({},o,{callback:s})},{skipEmptyString:!0,arrayFormat:"comma"}),l.type="text/javascript",l.defer=!0,l.async=!0,l.addEventListener("error",t),u&&(l.nonce=u),document.head.appendChild(l)}(t,l)}return Promise.resolve(i._promise)}catch(e){return Promise.reject(e)}},n=t,(i=[{key:"status",get:function(){return this._status}},{key:"completion",get:function(){return this._promise}},{key:"libraries",get:function(){return this._options.libraries||[]}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n,i),Object.defineProperty(n,"prototype",{writable:!1}),t}();l._status=e.LoaderStatus.NONE,l._options=void 0,l._promise=void 0,e.default=l});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).googleMapsJsApiLoader={})}(this,function(e){var t,o="__googleMapsCallback";e.LoaderStatus=void 0,(t=e.LoaderStatus||(e.LoaderStatus={}))[t.NONE=0]="NONE",t[t.LOADING=1]="LOADING",t[t.LOADED=2]="LOADED",t[t.ERROR=3]="ERROR";var r={promise:new Promise(function(e,t){Object.defineProperties(r,{resolve:{value:e},reject:{value:t}})}),status:e.LoaderStatus.NONE},a=/*#__PURE__*/function(){function t(){}var a,n;return t.load=function(){if(r.status===e.LoaderStatus.NONE){if(!this.options)throw r.status=e.LoaderStatus.ERROR,new Error("no options was provided");if(window.google&&window.google.maps)throw r.status=e.LoaderStatus.ERROR,new Error("Google Maps already loaded");r.status=e.LoaderStatus.LOADING,this.onLoadingStart(),window[o]=function(){r.status=e.LoaderStatus.LOADED,r.resolve(),delete window[o]},t=this.options,a=function(t){r.status=e.LoaderStatus.ERROR,r.reject(t)},n=document.createElement("script"),i=t.nonce,u=t.async,void 0!==(s=t.defer)&&(n.defer=s),void 0!==u&&(n.async=!0),i&&(n.nonce=i),n.src=function(e){for(var t={key:e.apiKey,channel:e.channel,client:e.client,v:e.version,language:e.language,region:e.region,map_ids:e.mapIds,libraries:e.libraries,callback:o,auth_referrer_policy:e.authReferrerPolicy},r=Object.keys(t),a=[],n=r.length;n--;){var i=r[n],s=t[i];s&&a.push(i+"="+(Array.isArray(s)?s.join(","):s))}var u=e.url||"https://maps.googleapis.com/maps/api/js";return a.length?u+"?"+a.join("&"):u}(t),n.type="text/javascript",n.addEventListener("error",a),document.head.appendChild(n)}var t,a,n,i,s,u;return r.promise},a=t,(n=[{key:"status",get:function(){return r.status}},{key:"completion",get:function(){return r.promise}}])&&function(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a,n),Object.defineProperty(a,"prototype",{writable:!1}),t}();a.options=void 0,a.onLoadingStart=function(){},e.default=a});
//# sourceMappingURL=google-maps-loader.umd.js.map

@@ -10,18 +10,17 @@ import { LoaderOptions } from "./types";

declare class Loader {
private static _status;
private static _options;
private static _promise;
/** Current status of {@link Loader Loader} */
static options: LoaderOptions;
static onLoadingStart: () => void;
/** Current status of {@link Loader} */
static get status(): LoaderStatus;
/** Promise from {@link Loader.load load} first call */
/**
* 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)
*/
static get completion(): Promise<void>;
/** List of [libraries](https://developers.google.com/maps/documentation/javascript/libraries) from {@link Loader.load load} options */
static get libraries(): import("@googlemaps/js-api-loader").Libraries;
/**
* Asynchronously loads Google Maps JavaScript API with given options, can be called multiple times
* @returns promise from the first call
* @throws error if google.maps already exists on the first call or if the options are different from the first call
* 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
*/
static load(options: LoaderOptions, onLoadingStart?: () => void): Promise<void>;
static load(): Promise<void>;
}
export default Loader;

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

import { LoaderOptions as _LoaderOptions } from "@googlemaps/js-api-loader";
export declare type LoaderOptions = Omit<_LoaderOptions, "id" | "retries">;
import type { LoaderOptions as _LoaderOptions } from "@googlemaps/js-api-loader";
export declare type LoaderOptions = Omit<_LoaderOptions, "id" | "retries"> & {
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async
*/
async?: boolean;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer
*/
defer?: boolean;
};
{
"name": "google-maps-js-api-loader",
"version": "1.1.2",
"version": "2.0.0",
"description": "Wrapper for the loading of Google Maps JavaScript API script in the browser",

@@ -30,10 +30,8 @@ "repository": {

"dependencies": {
"@googlemaps/js-api-loader": "^1.13.2",
"query-string": "^7.1.0",
"fast-deep-equal": "^3.1.3"
"@googlemaps/js-api-loader": "^1.14.1"
},
"devDependencies": {
"@types/google.maps": "^3.47.3",
"microbundle": "^0.14.2",
"typescript": "^4.5.5"
"@types/google.maps": "^3.48.7",
"microbundle": "^0.15.0",
"typescript": "^4.6.4"
},

@@ -40,0 +38,0 @@ "files": [

@@ -12,30 +12,31 @@ # google-maps-js-api-loader

await Loader.load({
Loader.options = {
apiKey: API_KEY,
// ...some other options
});
};
// or
await Loader.load();
```
// start load in root file
Loader.load({
apiKey: API_KEY,
// ...some other options
});
## API
// and then await it in nested files
await Loader.completion;
### options
```ts
static options: LoaderOptions
```
## API
Loader options (query parameters for script url and some script attributes), should be set before [load](#load) execution
---
### load
```ts
async static load(options: LoaderOptions, onLoadingStart?: () => void): Promise<void>
async static load(): Promise<void>
```
Asynchronously loads Google Maps JavaScript API with given options, can be called multiple times, but always returns promise from the first call
Starts loading of Google Maps JavaScript API with given [options](#options) (if it not loaded yet), returns [completion](#completion)
> Note: it throws an error if google.maps already exists on the first call or if the options are different from the first call
> throws error if google.maps already loaded by something else or if no [options](#options) was provided

@@ -67,24 +68,8 @@ ---

Promise from [load](#load) first call
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)
---
### libraries
```ts
static libraries: Libraries
```
List of [libraries](https://developers.google.com/maps/documentation/javascript/libraries) from [options](#loaderoptions)
---
### LoaderOptions
Options structure is similar to [@googlemaps/js-api-loader](https://github.com/googlemaps/js-api-loader)
---
## License
MIT © [Krombik](https://github.com/Krombik)

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

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