mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 16:56:22 +02:00
23 lines
541 B
TypeScript
23 lines
541 B
TypeScript
import { sanitizeHref } from "./sanitize-href";
|
|
|
|
export function resolveSafeNavigationHref(
|
|
...candidates: Array<string | null | undefined>
|
|
): string | undefined {
|
|
for (const candidate of candidates) {
|
|
const safeHref = sanitizeHref(candidate ?? undefined);
|
|
if (safeHref) {
|
|
return safeHref;
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
export function openSafeNavigationHref(href: string | undefined): boolean {
|
|
if (!href || typeof window === "undefined") {
|
|
return false;
|
|
}
|
|
|
|
window.open(href, "_blank", "noopener,noreferrer");
|
|
return true;
|
|
}
|