Revue appel asynchrone à Papa Parse.

This commit is contained in:
Fabrice PENHOËT 2021-10-07 18:09:15 +02:00
parent 19c7994388
commit 318353c862

View File

@ -94,30 +94,30 @@ export class ParserForCSV implements Parsers
} }
// async dans le cas d'une source distante // async dans le cas d'une source distante
// Et création d'une Promise car PapaParse utilise une fonction callback. // Et création d'une Promise car PapaParse utilise des fonctions callback.
public async parse(): Promise<any> public async parse(): Promise<any>
{ {
const parser=this, options=this.options; const parser=this, options=this.options;
let parseContent="";
if(parser._datasRemoteSource.url !== "")
{
parseContent=parser._datasRemoteSource.url;
this._privateOptions.download=true;
this._privateOptions.withCredentials=parser._datasRemoteSource.withCredentials;
if(parser._datasRemoteSource.headers !== undefined)
{
this._privateOptions.downloadRequestHeaders={};
for(let i=0; i< parser._datasRemoteSource.headers.length; i++)
this._privateOptions.downloadRequestHeaders[parser._datasRemoteSource.headers[i].key]=parser._datasRemoteSource.headers[i].value;
}
}
else if(parser._datas2Parse !== "")
parseContent=parser._datas2Parse;
else
throw new Error(errors.parserNeedSource);
return new Promise((resolve,reject) => return new Promise((resolve,reject) =>
{ {
let parseContent="";
if(parser._datasRemoteSource.url !== "")
{
parseContent=parser._datasRemoteSource.url;
this._privateOptions.download=true;
this._privateOptions.withCredentials=parser._datasRemoteSource.withCredentials;
if(parser._datasRemoteSource.headers !== undefined)
{
this._privateOptions.downloadRequestHeaders={};
for(let i=0; i< parser._datasRemoteSource.headers.length; i++)
this._privateOptions.downloadRequestHeaders[parser._datasRemoteSource.headers[i].key]=parser._datasRemoteSource.headers[i].value;
}
}
else if(parser._datas2Parse !== "")
parseContent=parser._datas2Parse;
else
reject(new Error(errors.parserNeedSource));
Papa.parse(parseContent, Papa.parse(parseContent,
{ {
delimiter: options.delimiter, delimiter: options.delimiter,