Skip to content

Commit 996bdcd

Browse files
committed
chore: docs, formatting, linting, and minor changes
1 parent 4666330 commit 996bdcd

File tree

10 files changed

+69
-34
lines changed

10 files changed

+69
-34
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
insert_final_newline = true

.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
bracketSpacing: false,
3+
singleQuote: true,
4+
trailingComma: "all",
5+
arrowParens: "avoid",
6+
};

MIGRATION.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ functional approach. This simplifies the API and aligns it with
1010
[the recommended way](https://developers.google.com/maps/documentation/javascript/load-maps-js-api)
1111
to load the Google Maps JavaScript API.
1212

13-
- **v1.x:** You would create an instance of the `Loader` class with your configuration and then call methods like `load()` or `importLibrary()` on that instance.
14-
- **v2.x:** You now use two standalone functions: `setOptions()` to configure the API loader and `importLibrary()` to load specific libraries.
13+
- **v1.x:** You would create an instance of the `Loader` class with your
14+
configuration and then call methods like `load()` or `importLibrary()` on
15+
that instance.
16+
- **v2.x:** You now use two standalone functions: `setOptions()` to
17+
configure the API loader and `importLibrary()` to load specific libraries.
1518

1619
Generally, the Loader constructor can be replaced with a call to `setOptions()`,
17-
and the different methods used to actually load the API
20+
and the different methods used to actually load the API are all replaced
21+
with calls to `importLibrary()`.
1822

1923
## Key Changes
2024

@@ -49,7 +53,7 @@ loader.load().then(() => initMap());
4953
await loader.load();
5054
initMap();
5155

52-
// c) using callback – same as a)
56+
// c) using callback
5357
loader.loadCallback(() => {
5458
initMap();
5559
});
@@ -65,7 +69,7 @@ function initMap() {
6569

6670
### v2.x
6771

68-
The typical use case from versions 2.0 onwards is to use importLibrary to get
72+
The typical use case from versions 2.0 onwards is to use `importLibrary` to get
6973
access to the classes and features needed from the Maps JavaScript API.
7074

7175
```javascript
@@ -128,4 +132,5 @@ function initMap() {
128132
});
129133
}
130134
```
135+
131136
</details>

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ importLibrary("maps").then(({ Map }) => {
7373

7474
If you use custom HTML elements from the Google Maps JavaScript API (e.g.
7575
`<gmp-map>`, and `<gmp-advanced-marker>`), you need to import them as well.
76-
Note that you do not need to await the result of `importLibrary` in this case.
76+
Note that you do not need to await the result of `importLibrary()` in this case.
7777
The custom elements will upgrade automatically once the library is loaded
7878
and you can use the `whenDefined()` method to wait for the upgrade to
7979
complete.
@@ -85,11 +85,11 @@ import { setOptions, importLibrary } from "@googlemaps/js-api-loader";
8585
setOptions({ key: "your-api-key-here" });
8686

8787
// Start loading the libraries needed for custom elements.
88-
importLibrary("maps"); // needed for gmp-map
89-
importLibrary("marker"); // needed for gmp-advanced-marker
88+
importLibrary("maps"); // needed for <gmp-map>
89+
importLibrary("marker"); // needed for <gmp-advanced-marker>
9090

9191
// Wait for gmp-map to be upgraded and interact with it.
92-
await customElements.whenDefined('gmp-map');
92+
await customElements.whenDefined("gmp-map");
9393
const map = document.querySelector("gmp-map");
9494
// ...
9595
```
@@ -109,8 +109,8 @@ await importLibrary("core");
109109
### `setOptions(options: APIOptions): void`
110110

111111
Sets the options for loading the Google Maps JavaScript API and installs the
112-
global `google.maps.importLibrary` function that is used by the importLibrary
113-
function.
112+
global `google.maps.importLibrary()` function that is used by the
113+
`importLibrary()` function of this package.
114114

115115
This function should be called as early as possible in your application and
116116
should only be called once. Any further calls will not have any effect and
@@ -123,7 +123,7 @@ Below is a short summary of the accepted options, see the
123123
- `v: string`: The version of the Maps JavaScript API to load.
124124
- `language: string`: The language to use.
125125
- `region: string`: The region code to use.
126-
- `libraries: string[]`: additional libraries to load.
126+
- `libraries: string[]`: Additional libraries to load.
127127
- `authReferrerPolicy: string`: Set the referrer policy for the API requests.
128128
- `mapIds: string[]`: An array of map IDs to preload.
129129
- `channel: string`: Can be used to track your usage.

eslint.config.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import globals from "globals";
22
import tseslint from "typescript-eslint";
33
import pluginJest from "eslint-plugin-jest";
44
import eslintConfigPrettier from "eslint-config-prettier";
5+
import { defineConfig } from "eslint/config";
56

6-
export default tseslint.config(
7+
export default defineConfig(
78
{
8-
ignores: ["dist/", "node_modules/", "docs/", "src/bootstrap.js"],
9+
ignores: ["dist/", "node_modules/", "src/bootstrap.js"],
910
},
1011
{
1112
languageOptions: {
@@ -19,10 +20,6 @@ export default tseslint.config(
1920
sourceType: "module",
2021
},
2122
},
22-
rules: {
23-
"no-var": "error",
24-
"prefer-arrow-callback": "error",
25-
},
2623
},
2724
...tseslint.configs.recommended,
2825
{
@@ -47,11 +44,15 @@ export default tseslint.config(
4744
},
4845
},
4946
{
50-
...pluginJest.configs["flat/recommended"],
5147
files: ["**/*.test.ts"],
52-
rules: {
53-
...pluginJest.configs["flat/recommended"].rules,
54-
},
48+
...pluginJest.configs["flat/recommended"],
5549
},
5650
eslintConfigPrettier,
57-
);
51+
{
52+
rules: {
53+
"no-var": "error",
54+
"prefer-arrow-callback": "error",
55+
curly: "error",
56+
},
57+
}
58+
);

package-lock.json

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"eslint-plugin-jest": "^29.0.1",
5656
"eslint-plugin-prettier": "^5.5.4",
5757
"fast-deep-equal": "^3.1.3",
58+
"globals": "^16.4.0",
5859
"jest": "^30.1.3",
5960
"jest-environment-jsdom": "^30.1.2",
6061
"prettier": "^3.0.3",

src/deprecated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2025 Google LLC
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
5+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
66

77
import { MSG_DEPRECATED_LOADER } from "./messages.js";
88

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ type APILibraryName = keyof APILibraryMap;
6363
declare const __DEV__: boolean;
6464

6565
let setOptionsWasCalled_ = false;
66-
let options_: APIOptions = {};
6766

6867
/**
6968
* Sets the options for the Maps JavaScript API.
@@ -82,9 +81,7 @@ export function setOptions(options: APIOptions) {
8281
return;
8382
}
8483

85-
options_ = options;
86-
87-
installImportLibrary_(options_);
84+
installImportLibrary_(options);
8885
setOptionsWasCalled_ = true;
8986
}
9087

@@ -112,8 +109,9 @@ export async function importLibrary(libraryName: string): Promise<unknown> {
112109
logDevWarning(MSG_SET_OPTIONS_NOT_CALLED);
113110
}
114111

115-
if (!window?.google?.maps?.importLibrary)
112+
if (!window?.google?.maps?.importLibrary) {
116113
throw new Error("google.maps.importLibrary is not installed.");
114+
}
117115

118116
return (await google.maps.importLibrary(
119117
libraryName
@@ -140,7 +138,9 @@ function installImportLibrary_(options: APIOptions) {
140138

141139
// If the google.maps.importLibrary function already exists, bootstrap()
142140
// won't do anything, so we won't call it
143-
if (!importLibraryExists) bootstrap(options);
141+
if (!importLibraryExists) {
142+
bootstrap(options);
143+
}
144144
}
145145

146146
// export the deprecated (and non-functional) Loader class to trigger a strong

src/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const MSG_REPEATED_SET_OPTIONS = (options: APIOptions) =>
2727
`to the additional call (${JSON.stringify(options)}) will be ignored.`;
2828

2929
export const MSG_IMPORT_LIBRARY_EXISTS = (options: APIOptions) =>
30-
`The google.maps.importLibrary function is already defined, and ` +
30+
`The google.maps.importLibrary() function is already defined, and ` +
3131
`@googlemaps/js-api-loader will use the existing function instead of ` +
3232
`overwriting it. The options passed to setOptions ` +
3333
`(${JSON.stringify(options)}) will be ignored.`;

0 commit comments

Comments
 (0)