Skip to content

Commit

Permalink
fix: Add check for global URL constructor in fromUrl() (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnns authored Oct 20, 2020
1 parent cc45487 commit 4e32480
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/from-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ const urlPattern = /^[a-z]+:\/\//i;
export const NO_HOSTNAME: unique symbol = Symbol("NO_HOSTNAME");

export const fromUrl = (urlLike: string) => {
/* istanbul ignore next */
if (typeof URL !== "function") {
throw new Error(
"Looks like the new URL() constructor is not globally available in your environment. Please make sure to use a polyfill.",
);
}

// Extra check for non-TypeScript users
if (typeof urlLike !== "string") {
return NO_HOSTNAME;
Expand Down

0 comments on commit 4e32480

Please sign in to comment.