From 4e3248096a50fc6f5cb35935f6f44bee72efd150 Mon Sep 17 00:00:00 2001 From: Johannes Ewald Date: Tue, 20 Oct 2020 14:19:40 +0200 Subject: [PATCH] fix: Add check for global URL constructor in fromUrl() (#119) --- src/from-url.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/from-url.ts b/src/from-url.ts index e491c48..c41b35f 100644 --- a/src/from-url.ts +++ b/src/from-url.ts @@ -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;