pollo/app/_utils/helpers.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-09-03 16:04:35 -06:00
import { json2csv } from "csv42";
2023-10-03 19:56:57 -06:00
export const jsonToCsv = (jsonObject: Array<object>, fileName: string) => {
2023-09-03 16:04:35 -06:00
const csv = json2csv(jsonObject);
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", fileName);
link.style.visibility = "hidden";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
2023-10-03 19:56:57 -06:00
};
2023-09-03 16:04:35 -06:00
export function isAdmin(meta: UserPublicMetadata | undefined) {
return (meta?.isAdmin as boolean | undefined) || false;
}
export function isVIP(meta: UserPublicMetadata | undefined) {
return (meta?.isVIP as boolean | undefined) || false;
}
2023-10-03 19:56:57 -06:00
export const writeToLogs = (
level: "warn" | "info" | "error" | "success",
message: string
) => {
switch (level) {
case "info":
console.log(`[ INFO]: ${message}`);
break;
case "warn":
console.log(`[⚠️ WARN]: ${message}`);
break;
case "error":
console.log(`[❌ ERROR]: ${message}`);
break;
case "success":
console.log(`[✅ SUCCESS]: ${message}`);
break;
default:
console.log(`[ INFO]: ${message}`);
break;
}
};