SurfSense/surfsense_web/components/tool-ui/shared/media/safe-navigation.ts

24 lines
541 B
TypeScript
Raw Normal View History

import { sanitizeHref } from "./sanitize-href";
export function resolveSafeNavigationHref(
2026-03-30 01:50:41 +05:30
...candidates: Array<string | null | undefined>
): string | undefined {
2026-03-30 01:50:41 +05:30
for (const candidate of candidates) {
const safeHref = sanitizeHref(candidate ?? undefined);
if (safeHref) {
return safeHref;
}
}
2026-03-30 01:50:41 +05:30
return undefined;
}
export function openSafeNavigationHref(href: string | undefined): boolean {
2026-03-30 01:50:41 +05:30
if (!href || typeof window === "undefined") {
return false;
}
2026-03-30 01:50:41 +05:30
window.open(href, "_blank", "noopener,noreferrer");
return true;
}