pollo/app/services/helpers.ts

47 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { json2csv } from "csv42";
export const jsonToCsv = (jsonObject: Array<object>, fileName: string) => {
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);
};
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;
}
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;
}
};