Skip to content

Commit

Permalink
Merge pull request #20 from mad-lab-fau/18-parsing-csv-file-with-only…
Browse files Browse the repository at this point in the history
…-one-column-fails

18 parsing csv file with only one column fails
  • Loading branch information
roschro-fau authored Jan 26, 2024
2 parents 3dfb158 + e0aa804 commit 5bae415
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/lib/components/preparation/StudyForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,40 @@
// parse file content and set subject list to empty list in case of an error
let el = document.getElementById('file');
if (el instanceof HTMLInputElement) {
if(el.files && el.files.length > 0){
if(el.files && el.files.length > 0) {
let file: File = el.files[0];
parseFile(file).then((subjectList) => {
parsingError = "";
studyProps.update((props) => {
return {
file.text().then((text) => {
let delimiter = text.includes(";") || text.includes(",") ? "" : " ";
parseFile(file, delimiter).then((subjectList) => {
parsingError = "";
studyProps.update((props) => {
return {
...props,
subjectList: subjectList,
};
});
}).catch((err) => {
parsingError = err;
studyProps.update((props) => {
return {
};
});
}).catch((err) => {
parsingError = err;
studyProps.update((props) => {
return {
...props,
subjectList: [],
};
};
});
});
});
}
}
}
function parseFile(file: File): Promise<string[]>{
function parseFile(file: File, delimiter: String): Promise<string[]>{
let subjectList: string [] = [];
let err: string = "";
return new Promise<string[]>((resolve, reject) => {
Papa.parse(file, {
header: true,
skipEmptyLines: true,
delimiter: delimiter,
complete: function(parsed: any) {
let col = $studyProps.subjectColumn;
if (col){
Expand Down

0 comments on commit 5bae415

Please sign in to comment.