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:" +}