Add check-types helper

This commit is contained in:
Sam Carlton 2021-11-28 23:31:55 -06:00
parent bc804d4664
commit fb46377e2c

19
helpers/check-types.js Normal file
View file

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