(url: string, allowLocalhost: boolean)
| 13 | } |
| 14 | |
| 15 | function getUsableOrigin(url: string, allowLocalhost: boolean) { |
| 16 | try { |
| 17 | const parsedUrl = new URL(url) |
| 18 | if (!allowLocalhost && isLocalhost(parsedUrl.hostname)) { |
| 19 | return null |
| 20 | } |
| 21 | return parsedUrl.origin |
| 22 | } catch { |
| 23 | return null |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | function isLocalhost(hostname: string) { |
| 28 | const normalizedHostname = hostname.replace(/^\[|\]$/g, '') |
no test coverage detected