Files
JiboViteDocs/node_modules/@lando/vitepress-theme-default-plus/utils/is-active.js
Your Name 38652eb9b5 Initalize
2026-05-03 12:12:57 -04:00

20 lines
623 B
JavaScript

const EXT_RE = /(index)?\.(md|html)$/;
const HASH_RE = /#.*$/;
const inBrowser = typeof document !== 'undefined';
const normalize = path => decodeURI(path).replace(HASH_RE, '').replace(EXT_RE, '');
export default function isActive(currentPath, matchPath, asRegex) {
if (matchPath === undefined) return false;
currentPath = normalize(`/${currentPath}`);
if (asRegex) return new RegExp(matchPath).test(currentPath);
if (normalize(matchPath) !== currentPath) return false;
const hashMatch = matchPath.match(HASH_RE);
if (hashMatch) return (inBrowser ? location.hash : '') === hashMatch[0];
return true;
};