@sohanemon/utils 4.0.29 → 4.0.31
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.
- package/dist/functions/index.d.ts +47 -0
- package/dist/functions/index.js +55 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility to merge class names with Tailwind CSS and additional custom merging logic.
|
|
3
|
+
*
|
|
4
|
+
* @param {...ClassValue[]} inputs - Class names to merge.
|
|
5
|
+
* @returns {string} - A string of merged class names.
|
|
6
|
+
*/
|
|
1
7
|
import { type ClassValue } from 'clsx';
|
|
2
8
|
import type * as React from 'react';
|
|
3
9
|
export * from './cookie';
|
|
4
10
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use isLinkActive instead.
|
|
13
|
+
*
|
|
14
|
+
* Determines if a navigation link is active based on the current path.
|
|
15
|
+
*
|
|
16
|
+
* @param href - The target URL.
|
|
17
|
+
* @param path - The current browser path.
|
|
18
|
+
* @returns - True if the navigation is active, false otherwise.
|
|
19
|
+
*/
|
|
5
20
|
export declare function isNavActive(href: string, path: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a link is active, considering optional localization prefixes.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} params - Parameters object.
|
|
25
|
+
* @param {string} params.path - The target path of the link.
|
|
26
|
+
* @param {string} params.currentPath - The current browser path.
|
|
27
|
+
* @param {string[]} [params.locales=['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl']] - Supported locale prefixes.
|
|
28
|
+
* @returns {boolean} - True if the link is active, false otherwise.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isLinkActive({ path, currentPath, locales, }: {
|
|
31
|
+
path: string;
|
|
32
|
+
currentPath: string;
|
|
33
|
+
locales?: string[];
|
|
34
|
+
}): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Cleans a file path by removing the `/public/` prefix if present.
|
|
37
|
+
*
|
|
38
|
+
* @param src - The source path to clean.
|
|
39
|
+
* @returns - The cleaned path.
|
|
40
|
+
*/
|
|
6
41
|
export declare function cleanSrc(src: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Smoothly scrolls to the top or bottom of a specified container.
|
|
44
|
+
*
|
|
45
|
+
* @param containerSelector - The CSS selector or React ref for the container.
|
|
46
|
+
* @param to - Specifies whether to scroll to the top or bottom.
|
|
47
|
+
*/
|
|
7
48
|
export declare const scrollTo: (containerSelector: string | React.RefObject<HTMLDivElement>, to: "top" | "bottom") => void;
|
|
49
|
+
/**
|
|
50
|
+
* Copies a given string to the clipboard.
|
|
51
|
+
*
|
|
52
|
+
* @param value - The value to copy to the clipboard.
|
|
53
|
+
* @param [onSuccess=() => {}] - Optional callback executed after successful copy.
|
|
54
|
+
*/
|
|
8
55
|
export declare const copyToClipboard: (value: string, onSuccess?: () => void) => void;
|
package/dist/functions/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility to merge class names with Tailwind CSS and additional custom merging logic.
|
|
3
|
+
*
|
|
4
|
+
* @param {...ClassValue[]} inputs - Class names to merge.
|
|
5
|
+
* @returns {string} - A string of merged class names.
|
|
6
|
+
*/
|
|
1
7
|
import { clsx } from 'clsx';
|
|
2
8
|
import { extendTailwindMerge } from 'tailwind-merge';
|
|
3
9
|
import { withFluid } from '@fluid-tailwind/tailwind-merge';
|
|
@@ -6,15 +12,57 @@ export function cn(...inputs) {
|
|
|
6
12
|
const twMerge = extendTailwindMerge(withFluid);
|
|
7
13
|
return twMerge(clsx(inputs));
|
|
8
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use isLinkActive instead.
|
|
17
|
+
*
|
|
18
|
+
* Determines if a navigation link is active based on the current path.
|
|
19
|
+
*
|
|
20
|
+
* @param href - The target URL.
|
|
21
|
+
* @param path - The current browser path.
|
|
22
|
+
* @returns - True if the navigation is active, false otherwise.
|
|
23
|
+
*/
|
|
9
24
|
export function isNavActive(href, path) {
|
|
10
|
-
|
|
25
|
+
console.warn('isNavActive is deprecated. Use isLinkActive instead.');
|
|
26
|
+
const regex = new RegExp(`^/?${href}(/|$)`);
|
|
11
27
|
return regex.test(path);
|
|
12
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a link is active, considering optional localization prefixes.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} params - Parameters object.
|
|
33
|
+
* @param {string} params.path - The target path of the link.
|
|
34
|
+
* @param {string} params.currentPath - The current browser path.
|
|
35
|
+
* @param {string[]} [params.locales=['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl']] - Supported locale prefixes.
|
|
36
|
+
* @returns {boolean} - True if the link is active, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
export function isLinkActive({ path, currentPath, locales = ['en', 'es', 'de', 'zh', 'bn', 'fr', 'it', 'nl'], }) {
|
|
39
|
+
const localeRegex = new RegExp(`^/?(${locales.join('|')})/`);
|
|
40
|
+
const normalizePath = (p) => {
|
|
41
|
+
return p
|
|
42
|
+
.replace(localeRegex, '') // Remove localization prefix (e.g., en/, fr/, etc.)
|
|
43
|
+
.replace(/^\/+|\/+$/g, ''); // Trim leading and trailing slashes
|
|
44
|
+
};
|
|
45
|
+
const normalizedPath = normalizePath(path);
|
|
46
|
+
const normalizedCurrentPath = normalizePath(currentPath);
|
|
47
|
+
return normalizedPath === normalizedCurrentPath;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Cleans a file path by removing the `/public/` prefix if present.
|
|
51
|
+
*
|
|
52
|
+
* @param src - The source path to clean.
|
|
53
|
+
* @returns - The cleaned path.
|
|
54
|
+
*/
|
|
13
55
|
export function cleanSrc(src) {
|
|
14
56
|
if (src.includes('/public/'))
|
|
15
57
|
return src.replace('/public/', '/');
|
|
16
58
|
return src;
|
|
17
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Smoothly scrolls to the top or bottom of a specified container.
|
|
62
|
+
*
|
|
63
|
+
* @param containerSelector - The CSS selector or React ref for the container.
|
|
64
|
+
* @param to - Specifies whether to scroll to the top or bottom.
|
|
65
|
+
*/
|
|
18
66
|
export const scrollTo = (containerSelector, to) => {
|
|
19
67
|
let container;
|
|
20
68
|
if (typeof containerSelector === 'string') {
|
|
@@ -33,6 +81,12 @@ export const scrollTo = (containerSelector, to) => {
|
|
|
33
81
|
});
|
|
34
82
|
}
|
|
35
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* Copies a given string to the clipboard.
|
|
86
|
+
*
|
|
87
|
+
* @param value - The value to copy to the clipboard.
|
|
88
|
+
* @param [onSuccess=() => {}] - Optional callback executed after successful copy.
|
|
89
|
+
*/
|
|
36
90
|
export const copyToClipboard = (value, onSuccess = () => { }) => {
|
|
37
91
|
if (typeof window === 'undefined' || !navigator.clipboard?.writeText) {
|
|
38
92
|
return;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED