Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parseFile = (content: string, fileExtension: string): void => {
let payload: CSL.Data[];
try {
switch (fileExtension) {
case '.ris':
payload = parseRis(content);
break;
case '.bib':
case '.bibtex':
payload = parseBibtex(content);
break;
default:
throw new Error('Invalid FileType');
}
} catch (e) {
this.setErrorMessage(ImportDialog.errors.filetype_error);
this.setFile();
this.setPayload([]);
return;
}
if (payload.length === 0) {
export async function readReferencesFile(file: File): Promise {
const extension = file.name
.substring(file.name.lastIndexOf('.'))
.toLowerCase();
const content = await readFile(file);
switch (extension) {
case '.ris':
return parseRis(content);
case '.bib':
case '.bibtex':
return parseBibtex(content);
default:
throw new Error(`Invalid file extension: ${extension}`);
}
}