export function updateDataHandler( heradersArray: { accessorKey: string, header: string, }[], valuesArray: Record ) { const data = {}; heradersArray.map((header: { accessorKey: string, header: string, }, i) => { if ( valuesArray[header.accessorKey] === undefined || valuesArray[header.accessorKey] === null || typeof valuesArray[header.accessorKey] === "object" ) { return; } data[header.accessorKey] = valuesArray[header.accessorKey]; return; }); return data; } export const arrayToCsv = (headers: { accessorKey: string, header: string, }[], data, delimiter?: string) => { const csvRows = []; csvRows.push(headers.map(e => e.header).join(delimiter || ",")); for (const row of data) { const rowValues = headers.map((header) => { const value = row[header.accessorKey]; const escaped = ("" + (value !== undefined ? value : '')).replace(/"/g, '\\"'); return `"${escaped}"`; }); csvRows.push(rowValues.join(delimiter || ",")); } return csvRows.join("\n"); }; export const download = (data, fileName: string, type: string) => { const blob = new Blob([data], { type: type || "text/csv" }); const url = window.URL.createObjectURL(blob); const a = document.createElement("a"); a.setAttribute("hidden", ""); a.setAttribute("href", url); a.setAttribute("download", fileName); document.body.appendChild(a); a.click(); document.body.removeChild(a); };