@sohanemon/utils 4.1.9 → 4.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -28,10 +28,11 @@ export declare function isNavActive(href: string, path: string): boolean;
|
|
|
28
28
|
* @param {string[]} [params.locales=['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl']] - Supported locale prefixes.
|
|
29
29
|
* @returns {boolean} - True if the link is active, false otherwise.
|
|
30
30
|
*/
|
|
31
|
-
export declare function isLinkActive({ path, currentPath, locales, }: {
|
|
31
|
+
export declare function isLinkActive({ path, currentPath, locales, exact, }: {
|
|
32
32
|
path: string;
|
|
33
33
|
currentPath: string;
|
|
34
34
|
locales?: string[];
|
|
35
|
+
exact?: boolean;
|
|
35
36
|
}): boolean;
|
|
36
37
|
/**
|
|
37
38
|
* Cleans a file path by removing the `/public/` prefix if present.
|
package/dist/functions/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export function isNavActive(href, path) {
|
|
|
36
36
|
* @param {string[]} [params.locales=['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl']] - Supported locale prefixes.
|
|
37
37
|
* @returns {boolean} - True if the link is active, false otherwise.
|
|
38
38
|
*/
|
|
39
|
-
export function isLinkActive({ path, currentPath, locales = ['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl'], }) {
|
|
39
|
+
export function isLinkActive({ path, currentPath, locales = ['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl'], exact = true, }) {
|
|
40
40
|
const localeRegex = new RegExp(`^/?(${locales.join('|')})/`);
|
|
41
41
|
const normalizePath = (p) => {
|
|
42
42
|
return p
|
|
@@ -45,7 +45,9 @@ export function isLinkActive({ path, currentPath, locales = ['en', 'es', 'de', '
|
|
|
45
45
|
};
|
|
46
46
|
const normalizedPath = normalizePath(path);
|
|
47
47
|
const normalizedCurrentPath = normalizePath(currentPath);
|
|
48
|
-
return
|
|
48
|
+
return exact
|
|
49
|
+
? normalizedPath === normalizedCurrentPath
|
|
50
|
+
: normalizedCurrentPath.startsWith(normalizedPath);
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Cleans a file path by removing the `/public/` prefix if present.
|