37 lines
966 B
TypeScript
37 lines
966 B
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export const formatDate = (date: Date) =>
|
|
date.toLocaleString("en-EN", {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
});
|
|
|
|
export const getBaseUrl = () => {
|
|
if (typeof window !== "undefined") return window.location.origin;
|
|
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
|
|
return `http://localhost:${process.env.PORT ?? 3000}`;
|
|
};
|
|
|
|
export const debounce = <T extends (...args: any[]) => any>(
|
|
callback: T,
|
|
waitFor: number,
|
|
) => {
|
|
let timeout: ReturnType<typeof setTimeout>;
|
|
return (...args: Parameters<T>): ReturnType<T> => {
|
|
let result: any;
|
|
timeout && clearTimeout(timeout);
|
|
timeout = setTimeout(() => {
|
|
result = callback(...args);
|
|
}, waitFor);
|
|
return result;
|
|
};
|
|
};
|