fumadocs-ui
Version:
The Radix UI version of Fumadocs UI
16 lines (15 loc) • 454 B
JavaScript
//#region src/utils/urls.ts
function normalize(urlOrPath) {
if (urlOrPath.length > 1 && urlOrPath.endsWith("/")) return urlOrPath.slice(0, -1);
return urlOrPath;
}
/**
* @returns if `href` is matching the given pathname
*/
function isActive(href, pathname, nested = false) {
href = normalize(href);
pathname = normalize(pathname);
return href === pathname || nested && pathname.startsWith(`${href}/`);
}
//#endregion
export { isActive, normalize };