refactor
This commit is contained in:
		| @ -1,17 +1,3 @@ | ||||
| function formatCSV(data) { | ||||
|     return data.reduce( | ||||
|         (csv, lineCells) => { | ||||
|             let line = lineCells.reduce( | ||||
|                 (lineText, cell, idx) => { | ||||
|                     cell = '"' + cell.trim().replace(/"/g, '""') + '"'; | ||||
|                     return lineText + cell + (idx == lineCells.length - 1 ? "" : ",") | ||||
|                 }, ""); | ||||
|             return csv + line + "\n"; | ||||
|         }, | ||||
|         "" | ||||
|     ); | ||||
| } | ||||
|  | ||||
| function saveFile(data, mimeType, fileName) { | ||||
|     fileName = fileName || document.title || "result"; | ||||
|     var blob; | ||||
| @ -42,12 +28,4 @@ function saveFile(data, mimeType, fileName) { | ||||
|     } else { | ||||
|         location.href = url | ||||
|     } | ||||
| } | ||||
|  | ||||
| function saveFileAsk(data) { | ||||
|     let csv = formatCSV(data.slice(1, 50)).trim() || "- Empty -"; | ||||
|     if (confirm(`Click confirm to download if the sample data looks good (${data.length-1} items):\n\n${csv}`)) { | ||||
|         csv = formatCSV(data); | ||||
|         saveFile(csv, "text/csv"); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user