Parse a URL, tolerating scheme-less inputs (https is assumed). Returns null if unparseable.
(url: string)
| 19 | |
| 20 | /** Parse a URL, tolerating scheme-less inputs (https is assumed). Returns null if unparseable. */ |
| 21 | function parseUrl(url: string): URL | null { |
| 22 | for (const candidate of [url, `https://${url}`]) { |
| 23 | try { |
| 24 | return new URL(candidate) |
| 25 | } catch {} |
| 26 | } |
| 27 | return null |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Whether `host` is one of `domains` or a subdomain of one (e.g. `m.youtube.com` |