38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
export const toCamel = (obj: any): any => {
|
|
if (Array.isArray(obj)) return obj.map(toCamel);
|
|
if (obj && typeof obj === "object") {
|
|
return Object.fromEntries(
|
|
Object.entries(obj).map(([k, v]) => [
|
|
k.replace(/_([a-z])/g, (_, c) => c.toUpperCase()),
|
|
toCamel(v),
|
|
])
|
|
);
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
export const formatDate = (dateString?: string | null) => {
|
|
if (!dateString) {
|
|
return "--";
|
|
}
|
|
const date = dateString ? new Date(dateString) : new Date();
|
|
|
|
const optionsDate = {
|
|
day: "numeric",
|
|
month: "long",
|
|
year: "numeric",
|
|
} as const;
|
|
const optionsTime = {
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
hour12: true,
|
|
} as const;
|
|
const optionsWeekday = { weekday: "long" } as const;
|
|
|
|
const formattedDate = date.toLocaleDateString("en-IN", optionsDate);
|
|
const formattedTime = date.toLocaleTimeString("en-IN", optionsTime);
|
|
const formattedWeekday = date.toLocaleDateString("en-IN", optionsWeekday);
|
|
|
|
return `${formattedDate}, ${formattedTime}, ${formattedWeekday}`;
|
|
};
|