(data)
| 910 | } |
| 911 | |
| 912 | function convertToCSV(data) { |
| 913 | if (!data.length) return "" |
| 914 | |
| 915 | const headers = Object.keys(data[0]) |
| 916 | const csvContent = [ |
| 917 | headers.join(","), |
| 918 | ...data.map((row) => headers.map((header) => `"${row[header]}"`).join(",")), |
| 919 | ].join("\n") |
| 920 | |
| 921 | return csvContent |
| 922 | } |
| 923 | |
| 924 | function downloadCSV(csv, filename) { |
| 925 | const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" }) |