Promise version of `juiceResources`
niftylettuce opened this issue · comments
niftylettuce commented
Can we add a Promise based version built-in? Maybe juiceResourcesAsync
?
const juice = require('juice');
// promise version of `juice.juiceResources`
const juiceResources = (html, options) => {
return new Promise((resolve, reject) => {
juice.juiceResources(html, options, (err, html) => {
if (err) return reject(err);
resolve(html);
});
});
};
module.exports = juiceResources;
niftylettuce commented
If anyone needs it in the meanwhile: <https://github.com/niftylettuce/juice-resources-promise
Tom Medema commented
Good suggestion. You might also consider:
const pify = require('pify')
const inlineHtml = await pify(juice.juiceResources)(html)
Jarrett Widman commented
Are folks using this now? https://nodejs.org/api/util.html#util_util_promisify_original
I've always leaned against supporting dual interfacing for node callback pattern and promises given how many libraries support back and forth on those. Its possibly also easier to just document how one would use one of these promisy libs than document there are two interfaces available.