stack/docs/src/lib/is-active.ts
Madison 4e467c4026
New docs (#698)
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
Co-authored-by: Madison Kennedy <madison@Madisons-MacBook-Pro.local>
Co-authored-by: BilalG1 <bg2002@gmail.com>
2025-06-20 13:30:01 -07:00

11 lines
280 B
TypeScript

export function isActive(
url: string,
pathname: string,
nested = true,
): boolean {
if (url.endsWith('/')) url = url.slice(0, -1);
if (pathname.endsWith('/')) pathname = pathname.slice(0, -1);
return url === pathname || (nested && pathname.startsWith(`${url}/`));
}