($base: string, $relative: string)
| 32 | } |
| 33 | |
| 34 | export function getAbsoluteURL($base: string, $relative: string): string { |
| 35 | if ($relative.match(/^data\\?\:/)) { |
| 36 | return $relative; |
| 37 | } |
| 38 | // Check if relative starts with `//hostname...`. |
| 39 | // We have to add a protocol to make it absolute. |
| 40 | if (/^\/\//.test($relative)) { |
| 41 | return `${location.protocol}${$relative}`; |
| 42 | } |
| 43 | const b = parseURL($base); |
| 44 | const a = parseURL($relative, b.href); |
| 45 | return a.href; |
| 46 | } |
| 47 | |
| 48 | // Check if any relative URL is on the window.location; |
| 49 | // So that https://duck.com/ext.css would return true on https://duck.com/ |
no test coverage detected