refactor(frontend): deduplicate isActive function

This commit is contained in:
sam 2024-12-26 14:10:03 -05:00
parent 5077bd6a0b
commit 49e9eabea0
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
4 changed files with 13 additions and 16 deletions

View file

@ -0,0 +1,10 @@
import { page } from "$app/state";
export const isActive = (path: string | string[], prefix: boolean = false) =>
typeof path === "string"
? prefix
? page.url.pathname.startsWith(path)
: page.url.pathname === path
: prefix
? path.some((p) => page.url.pathname.startsWith(p))
: path.some((p) => page.url.pathname === p);