UNPKG

mr-excel

Version:

A versatile JavaScript library for effortlessly generating .xlsx files from input objects. Seamlessly create Excel spreadsheets with data, formatting, formulas, and more.

41 lines (40 loc) 819 B
export const toDataURL2 = ( url: string, name: string, isBackend: boolean = false, fetchFunc?: Function ) => { let apiCaller: Function; let convertCall = false; if (typeof fetchFunc == "function") { apiCaller = fetchFunc; convertCall = true; } else { apiCaller = fetch; } return apiCaller(url) .then((response: any) => { if (convertCall) { return response; } if (isBackend) { return response.arrayBuffer(); } else { return response.blob(); } }) .then((res: any) => { if (convertCall) { return res; } if (isBackend) { // return Buffer.from(res) return res; } else { return new File([res], name); } }) .catch((err: any) => { throw err; }); };