Files
prowler/lib/utils.ts
T
2024-07-28 16:35:45 +02:00

82 lines
2.4 KiB
TypeScript

import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export function capitalize(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}
export const parseStringify = (value: any) => JSON.parse(JSON.stringify(value));
export const convertFileToUrl = (file: File) => URL.createObjectURL(file);
// FORMAT DATE TIME
export const formatDateTime = (dateString: Date | string) => {
const dateTimeOptions: Intl.DateTimeFormatOptions = {
// weekday: "short", // abbreviated weekday name (e.g., 'Mon')
month: "short", // abbreviated month name (e.g., 'Oct')
day: "numeric", // numeric day of the month (e.g., '25')
year: "numeric", // numeric year (e.g., '2023')
hour: "numeric", // numeric hour (e.g., '8')
minute: "numeric", // numeric minute (e.g., '30')
hour12: true, // use 12-hour clock (true) or 24-hour clock (false)
};
const dateDayOptions: Intl.DateTimeFormatOptions = {
weekday: "short", // abbreviated weekday name (e.g., 'Mon')
year: "numeric", // numeric year (e.g., '2023')
month: "2-digit", // abbreviated month name (e.g., 'Oct')
day: "2-digit", // numeric day of the month (e.g., '25')
};
const dateOptions: Intl.DateTimeFormatOptions = {
month: "short", // abbreviated month name (e.g., 'Oct')
year: "numeric", // numeric year (e.g., '2023')
day: "numeric", // numeric day of the month (e.g., '25')
};
const timeOptions: Intl.DateTimeFormatOptions = {
hour: "numeric", // numeric hour (e.g., '8')
minute: "numeric", // numeric minute (e.g., '30')
hour12: true, // use 12-hour clock (true) or 24-hour clock (false)
};
const formattedDateTime: string = new Date(dateString).toLocaleString(
"en-US",
dateTimeOptions,
);
const formattedDateDay: string = new Date(dateString).toLocaleString(
"en-US",
dateDayOptions,
);
const formattedDate: string = new Date(dateString).toLocaleString(
"en-US",
dateOptions,
);
const formattedTime: string = new Date(dateString).toLocaleString(
"en-US",
timeOptions,
);
return {
dateTime: formattedDateTime,
dateDay: formattedDateDay,
dateOnly: formattedDate,
timeOnly: formattedTime,
};
};
export function encryptKey(passkey: string) {
return btoa(passkey);
}
export function decryptKey(passkey: string) {
return atob(passkey);
}