Files
portfolio/lib/utils.ts
denshooter 18f8fb7407 style: final polish for design overhaul
Fixed all compilation errors, improved responsive layout, added missing icons, and refined animations for a perfect user experience.
2026-02-16 00:54:41 +01:00

44 lines
1.1 KiB
TypeScript

import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
/**
* Utility functions for the application
*/
/**
* Combine tailwind classes safely
*/
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
/**
* Debounce helper to prevent duplicate function calls
* @param func - The function to debounce
* @param delay - The delay in milliseconds
* @returns A debounced version of the function with a cleanup method
*/
export const debounce = <T extends (...args: unknown[]) => void>(
func: T,
delay: number
): (((...args: Parameters<T>) => void) & { cancel: () => void }) => {
let timeoutId: NodeJS.Timeout | undefined;
const debounced = (...args: Parameters<T>) => {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
timeoutId = setTimeout(() => func(...args), delay);
};
// Add cancel method to clear pending timeouts
debounced.cancel = () => {
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
timeoutId = undefined;
}
};
return debounced;
};