Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
date = parseRowsMappedArray[0].year;
str = parseRowsMappedArray[0].make;
str = parseRowsMappedArray[0].model;
num = parseRowsMappedArray[0].length;
// csvFormat(...) ============================================================================
str = d3Dsv.csvFormat(parseRowsMappedArray);
str = d3Dsv.csvFormat(parseRowsMappedArray, columns);
// csvFormatRows(...) ========================================================================
str = d3Dsv.csvFormatRows(parseRowsMappedArray.map((d, i) => [
d.year.getFullYear().toString(),
d.make,
d.model,
d.length.toString()
]));
// ------------------------------------------------------------------------------------------
// Test TSV
// ------------------------------------------------------------------------------------------
// tsvParse(...) ============================================================================
// without row mapper -----------------------------------------------------------------------
parseArray = d3Dsv.tsvParse(tsvTestStringWithHeader);
// now we need to find which module to use for the conversion
var parsed = "",
parse_error = false,
parse_error_msg = "";
if (this.isColumnHeader) {
try {
parsed = csvFormat( this.getJSON() );
parse_error = false;
} catch (e) {
parse_error = true;
parse_error_msg = "CSV conversion Failed. Please check if JSON is array of objects.";
}
} else {
try {
parsed = csvFormatRows( this.getJSON() );
parse_error = false;
} catch (e) {
parse_error = true;
parse_error_msg = "CSV conversion Failed. Please check if JSON is array of arrays.";
}
}
if (parse_error) {
// show the error message
Materialize.toast( parse_error_msg, 4000 );
// do not proceed
return;
}
console.log("All success! proceed to download");
this.downloadFile( parsed, "csv" );
export function formatCsv(data, fields) {
const columns = fields.map(f => f.name);
const formattedData = [columns];
// parse geojson object as string
data.forEach(row => {
formattedData.push(row.map((d, i) => parseFieldValue(d, fields[i].type)));
});
return csvFormatRows(formattedData);
}
export function downloadFlow (array, fileName, ext) {
let file;
const header = array[0]
switch(ext) {
case 'csv':
default: {
const csvString = csvFormatRows(array)
file = new File(
[csvString],
`${fileName}.${ext}`,
{ type: 'text/csv;charset=utf-8' }
)
FileSaver.saveAs(file)
break
}
case 'xlsx': {
const sheet = XLSX.utils.aoa_to_sheet(array, {header});
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, sheet, 'SheetJS');
XLSX.writeFile(wb, `${fileName}.${ext}`);
break
}
}