From 8351e889716e460c29c82e74bd2d214cba29d543 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 20 May 2020 16:00:02 -0700 Subject: [PATCH] fix: allow passing no apiKey --- src/index.test.ts | 7 +------ src/index.ts | 9 ++++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index b1f7d155..864f7871 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -17,6 +17,7 @@ import { Loader, LoaderOptions } from "."; test.each([ + [{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback"], [ { apiKey: "foo" }, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo", @@ -114,9 +115,3 @@ test("loader should wait if already loading", () => { loader.load(); }); - -test("loader should throw exception if invalid key format", () => { - expect(() => new Loader({ apiKey: "" })).toThrow(); - expect(() => new Loader({ apiKey: {} as string })).toThrow(); - expect(() => new Loader({ apiKey: (1 as unknown) as string })).toThrow(); -}); diff --git a/src/index.ts b/src/index.ts index cf48c4ec..9c24c571 100644 --- a/src/index.ts +++ b/src/index.ts @@ -192,10 +192,6 @@ export class Loader { region, version, }: LoaderOptions) { - if (typeof apiKey !== "string" || !apiKey) { - throw "Invalid apiKey " + apiKey; - } - this.version = version; this.apiKey = apiKey; this.libraries = libraries; @@ -211,7 +207,10 @@ export class Loader { let url = this.URL; url += `?callback=${this.CALLBACK}`; - url += `&key=${this.apiKey}`; + + if (this.apiKey) { + url += `&key=${this.apiKey}`; + } if (this.libraries.length > 0) { url += `&libraries=${this.libraries.join(",")}`;