12 lines
395 B
JavaScript
12 lines
395 B
JavaScript
export function isInternal(base, candidate) {
|
|
try {
|
|
const baseUrl = new URL(base);
|
|
const testUrl = new URL(candidate, base);
|
|
const protocolOk = testUrl.protocol === "http:" || testUrl.protocol === "https:";
|
|
const stripWWW = (h) => h.replace(/^www\./i, "");
|
|
return protocolOk && stripWWW(baseUrl.hostname) === stripWWW(testUrl.hostname);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|