From fb46377e2cb0449c3ab04281f287b5d8b023c045 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 28 Nov 2021 23:31:55 -0600 Subject: [PATCH] Add check-types helper --- helpers/check-types.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 helpers/check-types.js diff --git a/helpers/check-types.js b/helpers/check-types.js new file mode 100644 index 0000000..65c2ded --- /dev/null +++ b/helpers/check-types.js @@ -0,0 +1,19 @@ +// Universal Imports Only + +export function isString( maybeString ) { + return (typeof maybeString === 'string' || maybeString instanceof String) +} + +export function isValidHttpUrl( string ) { + if ( !isString( string ) ) return false + + let url + + try { + url = new URL(string) + } catch (_) { + return false + } + + return url.protocol === "http:" || url.protocol === "https:" +}