Repository: googlemaps/js-api-loader
Pull request #486 (2021-12-31 06:05:46)

build(deps-dev): bump @types/jest from 27.0.2 to 27.4.0
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 27.0.2 to 27.4.0.
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@types/jest&package-manager=npm_and_yarn&previous-version=27.0.2&new-version=27.4.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov[bot]: # [Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/486?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps) Report
> Merging [#486](https://codecov.io/gh/googlemaps/js-api-loader/pull/486?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps) (b16a1a6) into [main](https://codecov.io/gh/googlemaps/js-api-loader/commit/973e6e4e1265dc46da660efce8beafc59481cccd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps) (973e6e4) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/googlemaps/js-api-loader/pull/486/graphs/tree.svg?width=650&height=150&src=pr&token=aAmgcWFXMs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps)](https://codecov.io/gh/googlemaps/js-api-loader/pull/486?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps)

```diff
@@            Coverage Diff            @@
##              main      #486   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          123       123           
  Branches        25        25           
=========================================
  Hits           123       123           
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/486?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/googlemaps/js-api-loader/pull/486?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps). Last update [9945c5c...b16a1a6](https://codecov.io/gh/googlemaps/js-api-loader/pull/486?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=googlemaps).


Patch:
diff --git a/package-lock.json b/package-lock.json
index 3a35aac..c38782e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "@googlemaps/js-api-loader",
-  "version": "1.12.12",
+  "version": "1.13.1",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -4053,9 +4053,9 @@
       "dev": true
     },
     "@types/google.maps": {
-      "version": "3.46.0",
-      "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.46.0.tgz",
-      "integrity": "sha512-TvrN/+XkDSblCrkx9bJXSrYOrDeUgiPl1ec215vv4mYBuvU3YOAq0XVB32dV6r7ySctqJO1M7aEgVJsJZOgrmQ==",
+      "version": "3.47.2",
+      "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.47.2.tgz",
+      "integrity": "sha512-mFmt428CY4UN49U8KH5J4RfcdkeRu6SZyPIXxU1MA0pnHb4pqn/c/whawTodB3pkKWe8F9fXfUlpBFsk9HucXw==",
       "dev": true
     },
     "@types/graceful-fs": {
@@ -4098,9 +4098,9 @@
       }
     },
     "@types/jest": {
-      "version": "27.0.2",
-      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.0.2.tgz",
-      "integrity": "sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==",
+      "version": "27.4.0",
+      "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.4.0.tgz",
+      "integrity": "sha512-gHl8XuC1RZ8H2j5sHv/JqsaxXkDDM9iDOgu0Wp8sjs4u/snb2PVehyWXJPr+ORA0RPpgw231mnutWI1+0hgjIQ==",
       "dev": true,
       "requires": {
         "jest-diff": "^27.0.0",
@@ -4108,9 +4108,9 @@
       },
       "dependencies": {
         "@jest/types": {
-          "version": "27.1.1",
-          "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.1.1.tgz",
-          "integrity": "sha512-yqJPDDseb0mXgKqmNqypCsb85C22K1aY5+LUxh7syIM9n/b0AsaltxNy+o6tt29VcfGDpYEve175bm3uOhcehA==",
+          "version": "27.4.2",
+          "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.4.2.tgz",
+          "integrity": "sha512-j35yw0PMTPpZsUoOBiuHzr1zTYoad1cVIE0ajEjcrJONxxrko/IRGKkXx3os0Nsi4Hu3+5VmDbVfq5WhG/pWAg==",
           "dev": true,
           "requires": {
             "@types/istanbul-lib-coverage": "^2.0.0",
@@ -4136,31 +4136,31 @@
           "dev": true
         },
         "jest-diff": {
-          "version": "27.2.0",
-          "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-27.2.0.tgz",
-          "integrity": "sha512-QSO9WC6btFYWtRJ3Hac0sRrkspf7B01mGrrQEiCW6TobtViJ9RWL0EmOs/WnBsZDsI/Y2IoSHZA2x6offu0sYw==",
+          "version": "27.4.2",
+          "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-27.4.2.tgz",
+          "integrity": "sha512-ujc9ToyUZDh9KcqvQDkk/gkbf6zSaeEg9AiBxtttXW59H/AcqEYp1ciXAtJp+jXWva5nAf/ePtSsgWwE5mqp4Q==",
           "dev": true,
           "requires": {
             "chalk": "^4.0.0",
-            "diff-sequences": "^27.0.6",
-            "jest-get-type": "^27.0.6",
-            "pretty-format": "^27.2.0"
+            "diff-sequences": "^27.4.0",
+            "jest-get-type": "^27.4.0",
+            "pretty-format": "^27.4.2"
           }
         },
         "jest-get-type": {
-          "version": "27.0.6",
-          "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-27.0.6.tgz",
-          "integrity": "sha512-XTkK5exIeUbbveehcSR8w0bhH+c0yloW/Wpl+9vZrjzztCPWrxhHwkIFpZzCt71oRBsgxmuUfxEqOYoZI2macg==",
+          "version": "27.4.0",
+          "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-27.4.0.tgz",
+          "integrity": "sha512-tk9o+ld5TWq41DkK14L4wox4s2D9MtTpKaAVzXfr5CUKm5ZK2ExcaFE0qls2W71zE/6R2TxxrK9w2r6svAFDBQ==",
           "dev": true
         },
         "pretty-format": {
-          "version": "27.2.0",
-          "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.2.0.tgz",
-          "integrity": "sha512-KyJdmgBkMscLqo8A7K77omgLx5PWPiXJswtTtFV7XgVZv2+qPk6UivpXXO+5k6ZEbWIbLoKdx1pZ6ldINzbwTA==",
+          "version": "27.4.2",
+          "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.4.2.tgz",
+          "integrity": "sha512-p0wNtJ9oLuvgOQDEIZ9zQjZffK7KtyR6Si0jnXULIDwrlNF8Cuir3AZP0hHv0jmKuNN/edOnbMjnzd4uTcmWiw==",
           "dev": true,
           "requires": {
-            "@jest/types": "^27.1.1",
-            "ansi-regex": "^5.0.0",
+            "@jest/types": "^27.4.2",
+            "ansi-regex": "^5.0.1",
             "ansi-styles": "^5.0.0",
             "react-is": "^17.0.1"
           }
@@ -5472,9 +5472,9 @@
       "dev": true
     },
     "diff-sequences": {
-      "version": "27.0.6",
-      "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.0.6.tgz",
-      "integrity": "sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==",
+      "version": "27.4.0",
+      "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.4.0.tgz",
+      "integrity": "sha512-YqiQzkrsmHMH5uuh8OdQFU9/ZpADnwzml8z0O5HvRNda+5UZsaX/xN+AAxfR2hWq1Y7HZnAzO9J5lJXOuDz2Ww==",
       "dev": true
     },
     "dir-glob": {
diff --git a/package.json b/package.json
index 72354a0..0f936ee 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@googlemaps/js-api-loader",
-  "version": "1.12.12",
+  "version": "1.13.1",
   "description": "Wrapper for the loading of Google Maps JavaScript API script in the browser",
   "keywords": [
     "google",
diff --git a/src/index.ts b/src/index.ts
index e8fc2f3..f476a84 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -27,7 +27,7 @@ declare global {
 
 export const DEFAULT_ID = "__googleMapsScriptId";
 
-type Libraries = (
+export type Libraries = (
   | "drawing"
   | "geometry"
   | "localContext"
@@ -165,6 +165,16 @@ export interface LoaderOptions {
   retries?: number;
 }
 
+/**
+ * The status of the [[Loader]].
+ */
+export enum LoaderStatus {
+  INITIALIZED,
+  LOADING,
+  SUCCESS,
+  FAILURE,
+}
+
 /**
  * [[Loader]] makes it easier to add Google Maps JavaScript API to your application
  * dynamically using
@@ -314,6 +324,19 @@ export class Loader {
     };
   }
 
+  public get status(): LoaderStatus {
+    if (this.errors.length) {
+      return LoaderStatus.FAILURE;
+    }
+    if (this.done) {
+      return LoaderStatus.SUCCESS;
+    }
+    if (this.loading) {
+      return LoaderStatus.LOADING;
+    }
+    return LoaderStatus.INITIALIZED;
+  }
+
   private get failed(): boolean {
     return this.done && !this.loading && this.errors.length >= this.retries + 1;
   }


Test patch:
diff --git a/src/index.test.ts b/src/index.test.ts
index 43fe595..06242cd 100644
--- a/src/index.test.ts
+++ b/src/index.test.ts
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 /* eslint @typescript-eslint/no-explicit-any: 0 */
-import { DEFAULT_ID, Loader, LoaderOptions } from ".";
+import { DEFAULT_ID, Loader, LoaderOptions, LoaderStatus } from ".";
 
 jest.useFakeTimers();
 
@@ -54,6 +54,7 @@ test.each([
 ])("createUrl is correct", (options: LoaderOptions, expected: string) => {
   const loader = new Loader(options);
   expect(loader.createUrl()).toEqual(expected);
+  expect(loader.status).toBe(LoaderStatus.INITIALIZED);
 });
 
 test("uses default id if empty string", () => {
@@ -128,6 +129,7 @@ test("script onerror should reject promise", async () => {
   expect(loader["done"]).toBeTruthy();
   expect(loader["loading"]).toBeFalsy();
   expect(loader["errors"].length).toBe(1);
+  expect(loader.status).toBe(LoaderStatus.FAILURE);
 });
 
 test("script onerror should reject promise with multiple loaders", async () => {
@@ -301,6 +303,7 @@ test("singleton should be used", () => {
 
   loader["done"] = true;
   expect(extraLoader["done"]).toBe(loader["done"]);
+  expect(loader.status).toBe(LoaderStatus.SUCCESS);
 });
 
 test("singleton should throw with different options", () => {
@@ -333,7 +336,7 @@ test("loader should resolve immediately when failed loading", async () => {
 test("loader should wait if already loading", () => {
   const loader = new Loader({ apiKey: "foo", retries: 0 });
   loader["loading"] = true;
-
+  expect(loader.status).toBe(LoaderStatus.LOADING);
   loader.load();
 });