mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add check-types helper
This commit is contained in:
parent
bc804d4664
commit
fb46377e2c
1 changed files with 19 additions and 0 deletions
19
helpers/check-types.js
Normal file
19
helpers/check-types.js
Normal 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:"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue