mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-28 07:09:50 +00:00
15 lines
439 B
TypeScript
15 lines
439 B
TypeScript
export function normalize(urlOrPath: string) {
|
|
if (urlOrPath.length > 1 && urlOrPath.endsWith('/')) return urlOrPath.slice(0, -1);
|
|
return urlOrPath;
|
|
}
|
|
|
|
/**
|
|
* @returns if `href` is matching the given pathname
|
|
*/
|
|
export function isActive(href: string, pathname: string, nested = false): boolean {
|
|
href = normalize(href);
|
|
pathname = normalize(pathname);
|
|
|
|
return href === pathname || (nested && pathname.startsWith(`${href}/`));
|
|
}
|