ldc-supportweb/resources/ts/lib/utils.tsx
2026-05-19 16:47:07 +02:00

55 lines
1.1 KiB
TypeScript

// * Packages
import { useFormatedDate } from "@/hooks/use-formated-value";
import useTrans, { UseTransOptions } from "@/hooks/use-translations";
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
/**
* Merge classes.
* @param inputs ClassValue[]
* @returns string
*/
export function cn(...inputs: ClassValue[]): string {
return twMerge(clsx(inputs));
}
/**
* Get the translation value.
*
* @param keyName string
* @param options UseTransOptions|null
* @return string
*/
export const GetTranslation = (keyName: string, options?: UseTransOptions) => {
return useTrans(keyName, options);
};
/**
* Get the formated date.
*
* @param string date
* @param string timezone
* @param boolean time
* @returns
*/
export const GetFormatedDate = (
date: string,
timezone?: string,
time?: boolean,
) => {
return useFormatedDate(date, timezone, time);
};
/**
* Check if it's a valid url or not.
* @param {string} url
* @return {boolean}
*/
export const isAValidUrl = (url: string | undefined): boolean => {
if (!url) return false;
try {
return !!new URL(url).href;
} catch {
return false;
}
};