( maybeUrl, allowUnsecure = false )
| 24 | |
| 25 | |
| 26 | export function isValidHttpUrl( maybeUrl, allowUnsecure = false ) { |
| 27 | if ( !isString( maybeUrl ) ) return false |
| 28 | |
| 29 | let url |
| 30 | |
| 31 | try { |
| 32 | url = new URL(maybeUrl) |
| 33 | } catch (_) { |
| 34 | return false |
| 35 | } |
| 36 | |
| 37 | if ( allowUnsecure ) { |
| 38 | return url.protocol === "http:" || url.protocol === "https:" |
| 39 | } |
| 40 | |
| 41 | return url.protocol === "https:" |
| 42 | } |
| 43 | |
| 44 | export function isValidImageUrl ( maybeUrl ) { |
| 45 | if ( !isValidHttpUrl( maybeUrl ) ) return false |
no test coverage detected