Skip to content

Commit 1427b5e

Browse files
authored
fix: allow passing no apiKey (#8)
1 parent 70efae8 commit 1427b5e

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/index.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import { Loader, LoaderOptions } from ".";
1818

1919
test.each([
20+
[{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback"],
2021
[
2122
{ apiKey: "foo" },
2223
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo",
@@ -114,9 +115,3 @@ test("loader should wait if already loading", () => {
114115

115116
loader.load();
116117
});
117-
118-
test("loader should throw exception if invalid key format", () => {
119-
expect(() => new Loader({ apiKey: "" })).toThrow();
120-
expect(() => new Loader({ apiKey: {} as string })).toThrow();
121-
expect(() => new Loader({ apiKey: (1 as unknown) as string })).toThrow();
122-
});

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ export class Loader {
192192
region,
193193
version,
194194
}: LoaderOptions) {
195-
if (typeof apiKey !== "string" || !apiKey) {
196-
throw "Invalid apiKey " + apiKey;
197-
}
198-
199195
this.version = version;
200196
this.apiKey = apiKey;
201197
this.libraries = libraries;
@@ -211,7 +207,10 @@ export class Loader {
211207
let url = this.URL;
212208

213209
url += `?callback=${this.CALLBACK}`;
214-
url += `&key=${this.apiKey}`;
210+
211+
if (this.apiKey) {
212+
url += `&key=${this.apiKey}`;
213+
}
215214

216215
if (this.libraries.length > 0) {
217216
url += `&libraries=${this.libraries.join(",")}`;

0 commit comments

Comments
 (0)