(href: string)
| 51 | // Visa versa https://duck.com/ext.css should return fasle on https://duck.com/search/ |
| 52 | // We're checking if any relative value within ext.css could potentially not be on the same path. |
| 53 | export function isRelativeHrefOnAbsolutePath(href: string): boolean { |
| 54 | if (href.startsWith('data:')) { |
| 55 | return true; |
| 56 | } |
| 57 | const url = parseURL(href); |
| 58 | |
| 59 | if (url.protocol !== location.protocol) { |
| 60 | return false; |
| 61 | } |
| 62 | if (url.hostname !== location.hostname) { |
| 63 | return false; |
| 64 | } |
| 65 | if (url.port !== location.port) { |
| 66 | return false; |
| 67 | } |
| 68 | // Now check if the path is on the same path as the base |
| 69 | // We do this by getting the pathname up until the last slash. |
| 70 | return url.pathname === location.pathname; |
| 71 | } |
| 72 | |
| 73 | export function getURLHostOrProtocol($url: string): string { |
| 74 | const url = new URL($url); |
no test coverage detected