mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 20:37:44 +00:00
Co-authored-by: KinfeMichael Tariku <65047246+Kinfe123@users.noreply.github.com> Co-authored-by: Kinfe123 <kinfishtech@gmail.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { clsx, type ClassValue } from "clsx";
|
|
import { twMerge } from "tailwind-merge";
|
|
import type * as React from "react";
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function absoluteUrl(path: string) {
|
|
return `${process.env.NEXT_PUBLIC_APP_URL}${path}`;
|
|
}
|
|
export function kFormatter(num: number) {
|
|
const absNum = Math.abs(num);
|
|
const sign = Math.sign(num);
|
|
|
|
if (absNum >= 1000000000) {
|
|
return sign * parseFloat((absNum / 1000000000).toFixed(1)) + "B+";
|
|
} else if (absNum >= 1000000) {
|
|
return sign * parseFloat((absNum / 1000000).toFixed(1)) + "M+";
|
|
} else if (absNum >= 1000) {
|
|
return sign * parseFloat((absNum / 1000).toFixed(1)) + "K+";
|
|
}
|
|
return sign * absNum;
|
|
}
|
|
|
|
export const baseUrl =
|
|
process.env.NODE_ENV === "development" || !process.env.VERCEL_URL
|
|
? new URL("http://localhost:3000")
|
|
: new URL(`https://${process.env.VERCEL_URL}`);
|
|
export function formatDate(date: Date) {
|
|
let d = new Date(date);
|
|
return d
|
|
.toLocaleDateString("en-US", { month: "short", day: "numeric" })
|
|
.replace(",", "");
|
|
}
|
|
|
|
export function mergeRefs<T>(
|
|
...refs: (React.Ref<T> | undefined)[]
|
|
): React.RefCallback<T> {
|
|
return (value) => {
|
|
refs.forEach((ref) => {
|
|
if (typeof ref === "function") {
|
|
ref(value);
|
|
} else if (ref) {
|
|
ref.current = value;
|
|
}
|
|
});
|
|
};
|
|
}
|