am working on this project at work and they need me to make an API to generate a PDF containing a ton of tables. I did just that using the PDFMake lib and it works fine for the most part, I took inspiration from React and made components (all functions taking some input) for each table I needed to generate. But the problem is the input I get from the frontend can have missing fields or fields with undefined as their value, there are so many if checks I can put ! is there some obvious and scalable solution that I am missing ?
Why not a loop to set empty string for missing values
So if anyone's interested ( @poeti8 ) I solved this problem by using lodash's reduce method. First I made a higher order function such that :- func(obj) { return (acc, key) => { acc[key] = obj[key] || ''; } } Then it was as simple as :- reduce([keys i want to select], func(fromObject), {}) Voila :)
Обсуждают сегодня