I Have the below code that gets urls of PDF files, send them to a convert function and returns them as images, is there a way to make this code more readable?
Is there a way to avoid functions chaining?
import PDFtoImages from '../PDFtoImages'
export async function convertPDF(file, category) {
const images= await PDFtoImages(file.data)
return {
category: category ? [category] : [],
images
}
}
export function fetchBlob(url, opts = {}) {
return fetch(url, opts).then(res => {
if (!res.ok) return Promise.reject(new Error(res.statusText))
return res.blob()
})
}
export async function fetchFilesAsImages(filesUrls) {
const pdfAsImages= []
await Promise.all(
filesUrls.map(async file=> {
pdfAsImages.push(
await convertPDF(
{data: await fetchBlob(file.url)},
file.category
)
)
})
)
return pdfAsImages
}
import...
,export....
,}
so they would be pre-formatted? For more information about code blocks see the editing help page \$\endgroup\$