From 42fd8d357463ff353ef1cc92f31208914cbbcb01 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 13 Dec 2018 16:57:06 +0100 Subject: [PATCH] Use the URL global when available --- source/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index babe375..ba1f089 100644 --- a/source/index.ts +++ b/source/index.ts @@ -2,7 +2,10 @@ /// /// /// -import {URL} from 'url'; + +// TODO: Use the `URL` global when targeting Node.js 10 +// tslint:disable-next-line +const URLGlobal = typeof URL === 'undefined' ? require('url').URL : URL; type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; type Primitive = null | undefined | string | number | boolean | Symbol; @@ -195,7 +198,7 @@ namespace is { // tslint:disable-line:no-namespace } try { - new URL(value); // tslint:disable-line no-unused-expression + new URLGlobal(value); // tslint:disable-line no-unused-expression return true; } catch { return false;