@sohanemon/utils 4.0.19 → 4.0.22

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.
@@ -4,3 +4,4 @@ export declare function cn(...inputs: ClassValue[]): string;
4
4
  export declare function isNavActive(href: string, path: string): boolean;
5
5
  export declare function cleanSrc(src: string): string;
6
6
  export declare const scrollTo: (containerSelector: string | React.RefObject<HTMLDivElement>, to: "top" | "bottom") => void;
7
+ export declare const getClientSideCookie: (name: string) => string | undefined;
@@ -1,6 +1,8 @@
1
1
  import { clsx } from 'clsx';
2
- import { twMerge } from 'tailwind-merge';
2
+ import { extendTailwindMerge } from 'tailwind-merge';
3
+ import { withFluid } from '@fluid-tailwind/tailwind-merge';
3
4
  export function cn(...inputs) {
5
+ const twMerge = extendTailwindMerge(withFluid);
4
6
  return twMerge(clsx(inputs));
5
7
  }
6
8
  export function isNavActive(href, path) {
@@ -30,3 +32,10 @@ export const scrollTo = (containerSelector, to) => {
30
32
  });
31
33
  }
32
34
  };
35
+ export const getClientSideCookie = (name) => {
36
+ const cookieValue = document.cookie
37
+ .split('; ')
38
+ .find((row) => row.startsWith(`${name}=`))
39
+ ?.split('=')[1];
40
+ return cookieValue;
41
+ };
@@ -27,4 +27,6 @@ export declare const useAsync: <T extends (...args: any) => any>(fn: T, opts?: U
27
27
  error: Error;
28
28
  };
29
29
  export declare const useQuerySelector: <T extends Element>(selector: string) => T | null;
30
- export default useQuerySelector;
30
+ export declare function useIsClient(): boolean;
31
+ export declare function useLockScroll(): void;
32
+ export {};
@@ -44,6 +44,7 @@ export function useMediaQuery(tailwindBreakpoint) {
44
44
  function handleChange() {
45
45
  setMatches(getMatches(parsedQuery));
46
46
  }
47
+ // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
47
48
  useEffect(() => {
48
49
  const matchMedia = window.matchMedia(parsedQuery);
49
50
  handleChange();
@@ -59,6 +60,7 @@ export function useEffectOnce(effect) {
59
60
  }
60
61
  export function useUpdateEffect(effect, deps) {
61
62
  const isInitialMount = useRef(true);
63
+ // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
62
64
  useEffect(() => {
63
65
  if (isInitialMount.current) {
64
66
  isInitialMount.current = false;
@@ -66,7 +68,6 @@ export function useUpdateEffect(effect, deps) {
66
68
  else {
67
69
  return effect();
68
70
  }
69
- // eslint-disable-next-line react-hooks/exhaustive-deps
70
71
  }, deps);
71
72
  }
72
73
  export function useDebounce(state, delay = 500) {
@@ -94,6 +95,7 @@ export function useTimeout(callback, delay = 1000) {
94
95
  }, [delay]);
95
96
  }
96
97
  export function useWindowEvent(type, listener, options) {
98
+ // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
97
99
  useEffect(() => {
98
100
  window.addEventListener(type, listener, options);
99
101
  return () => window.removeEventListener(type, listener, options);
@@ -111,6 +113,7 @@ export const useLocalStorage = (key, defaultValue) => {
111
113
  }, [key]);
112
114
  // Function to update the stored value in local storage and state
113
115
  const updateStoredValue = (valueOrFn) => {
116
+ // biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
114
117
  let newValue;
115
118
  if (typeof valueOrFn === 'function') {
116
119
  const updateFunction = valueOrFn;
@@ -211,4 +214,19 @@ export const useQuerySelector = (selector) => {
211
214
  }, [selector]);
212
215
  return element;
213
216
  };
214
- export default useQuerySelector;
217
+ export function useIsClient() {
218
+ const [isClient, setIsClient] = useState(false);
219
+ useEffect(() => {
220
+ setIsClient(true);
221
+ }, []);
222
+ return isClient;
223
+ }
224
+ export function useLockScroll() {
225
+ useLayoutEffect(() => {
226
+ const originalStyle = window.getComputedStyle(document.body).overflow;
227
+ document.body.style.overflow = 'hidden';
228
+ return () => {
229
+ document.body.style.overflow = originalStyle;
230
+ };
231
+ }, []);
232
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "4.0.19",
3
+ "version": "4.0.22",
4
4
  "author": "Sohan Emon <sohanemon@outlook.com>",
5
5
  "description": "",
6
6
  "type": "module",
@@ -15,26 +15,39 @@
15
15
  },
16
16
  "typesVersions": {
17
17
  "*": {
18
- "core": ["dist/index.d.ts"],
19
- "hooks": ["dist/hooks/index.d.ts"],
20
- "components": ["dist/components/index.d.ts"]
18
+ "core": [
19
+ "dist/index.d.ts"
20
+ ],
21
+ "hooks": [
22
+ "dist/hooks/index.d.ts"
23
+ ],
24
+ "components": [
25
+ "dist/components/index.d.ts"
26
+ ]
21
27
  }
22
28
  },
23
- "files": ["dist", "README.md"],
29
+ "files": [
30
+ "dist",
31
+ "README.md"
32
+ ],
24
33
  "scripts": {
25
34
  "build": "tsc",
26
35
  "build:watch": "tsc --watch",
27
36
  "export": "tsc && npm publish"
28
37
  },
29
- "keywords": ["utils", "cn"],
38
+ "keywords": [
39
+ "utils",
40
+ "cn"
41
+ ],
30
42
  "license": "ISC",
31
43
  "devDependencies": {
44
+ "@types/node": "^22.4.0",
45
+ "@types/react": "^18.3.3",
32
46
  "typescript": "^5.5.4"
33
47
  },
34
48
  "dependencies": {
49
+ "@fluid-tailwind/tailwind-merge": "^0.0.2",
35
50
  "@iconify/react": "^4.1.1",
36
- "@types/node": "^22.4.0",
37
- "@types/react": "^18.3.3",
38
51
  "clsx": "^2.1.1",
39
52
  "react": "^18.3.1",
40
53
  "tailwind-merge": "^1.14.0"