Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_parse (cslData) {
try {
this._cslData = JSON.parse(cslData)
} catch (e) {
try {
// Didn't work, so let's try to parse it as BibTex data.
this._cslData = BibTexParser.parse(cslData)
} catch (e) {
console.error(e)
// Nopey.
global.ipc.notify(trans('gui.citeproc.error_db'))
this._status = ERROR
return
}
}
// First we need to reorder the read data so that it can be passed to the
// sys object
for (let i = 0, ilen = this._cslData.length; i < ilen; i++) {
let item = this._cslData[i]
// if (!item.issued) continue
let id = item.id
this._items[id] = item
this._ids[id] = true // Create a fast accessible object (instead of slow array)
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}`);
}
}
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) {
this.setErrorMessage(ImportDialog.errors.filetype_error);
this.setFile();
}