Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
reader.onload = (lEvent) => {
const format = file.name.split('.').pop().toLowerCase();
var values;
try {
console.log('TRY')
// if (format === 'txt' || (format !== "csv" && format !== "tsv")) {
// throw Error();
// }
values = vega.read(lEvent.target.result, {type: format});
// let csvFormat = d3.dsvFormat(","); should be csvFormat??
// values = csvFormat.parse(lEvent.target.result);
setData(values);
setComponentClasses(Object.keys(values[0]));
toggleLoading();
toggleDataLoaded();
} catch (err) {
console.log('CATCH', err)
const separator = prompt('Write a delimiter for your dataset (e.g: ;)');
let ssv = d3.dsvFormat(separator);
values = ssv.parse(lEvent.target.result);
delete values.columns;
setData(values);
setComponentClasses(Object.keys(values[0]));
toggleLoading();
toggleDataLoaded();
reader.onload = (lEvent: any) => {
console.log('onload')
const format = file.name.split('.').pop();
let values;
try {
console.log('try')
if(format === "txt") throw true
values = vega.read(lEvent.target.result, {type: format});
console.log('try2')
this.props.setData(values);
this.setState({loading:false})
} catch (err) {
console.log('err')
let ssv = d3.dsvFormat(";");
console.log('err2');
values = ssv.parse(lEvent.target.result);
console.log(values);
this.props.setData(values);
this.setState({loading:false});
}
};
private onDataTextSubmit() {
const values = vega.read(this.state.dataText, {type: 'csv'});
this.props.handleAction(datasetLoad(this.state.dataName, {values}));
}
reader.onload = (lEvent: any) => {
const name = file.name.replace(/\.\w+$/, '');
const format = file.name.split('.').pop();
let values;
try {
values = vega.read(lEvent.target.result, {type: format});
} catch (err) {
window.alert(err.message);
}
handleAction(datasetLoad(name, {values, format}));
};
private loadDataString(data: string) {
const name = this.state.dataName;
const fileType = this.state.fileType;
const values = vega.read(data, {type: fileType});
this.props.handleAction(datasetLoad(name, {values}));
}