Skip to content

Commit

Permalink
feat(api-loader): allow string-array for libraries parameter
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
usefulthink committed Jan 3, 2023
1 parent 6bcbffa commit 2857bff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/load-maps-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type MapsApiOptions = {
key: string;
libraries?: string;
libraries?: string | string[];
v?: string;
};

Expand All @@ -11,13 +11,17 @@ export async function loadMapsApi(apiOptions: MapsApiOptions): Promise<void> {
return mapsApiLoaded;
}

if (Array.isArray(apiOptions.libraries)) {
apiOptions.libraries = apiOptions.libraries.join(',');
}

const apiUrl = new URL('https://maps.googleapis.com/maps/api/js');
for (const [key, value] of Object.entries(apiOptions)) {
if (value === undefined) {
continue;
}

apiUrl.searchParams.set(key, value);
apiUrl.searchParams.set(key, value as string);
}
apiUrl.searchParams.set('callback', '__maps_callback__');

Expand Down

0 comments on commit 2857bff

Please sign in to comment.