Last active
December 12, 2018 15:11
-
-
Save Paratron/658c80499d67625ed9c3cb80a5d3bcbd to your computer and use it in GitHub Desktop.
This node module will consume another module and promisify all of its functions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {promisify} = require('util'); | |
const promisifyModuleFunctions = (inModule) => Object | |
.entries(inModule) | |
.reduce((outModule, [key, property]) => { | |
outModule[key] = (typeof property === 'function') | |
? promisify(property) | |
: property; | |
return outModule; | |
}, {}); | |
module.exports = { | |
promisifyModuleFunctions, | |
requireWithPromises: (moduleName) => promisifyModuleFunctions(require(moduleName)) | |
}; |
manuelbieh
commented
Dec 12, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment