
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
universalify
Advanced tools
Make a callback- or promise-based function support both promises and callbacks.
Make a callback- or promise-based function support both promises and callbacks.
Uses the native promise implementation.
npm install universalify
universalify.fromCallback(fn)Takes a callback-based function to universalify, and returns the universalified function.
Function must take a callback as the last parameter that will be called with the signature (error, result). universalify does not support calling the callback with three or more arguments, and does not ensure that the callback is only called once.
function callbackFn (n, cb) {
setTimeout(() => cb(null, n), 15)
}
const fn = universalify.fromCallback(callbackFn)
// Works with Promises:
fn('Hello World!')
.then(result => console.log(result)) // -> Hello World!
.catch(error => console.error(error))
// Works with Callbacks:
fn('Hi!', (error, result) => {
if (error) return console.error(error)
console.log(result)
// -> Hi!
})
universalify.fromPromise(fn)Takes a promise-based function to universalify, and returns the universalified function.
Function must return a valid JS promise. universalify does not ensure that a valid promise is returned.
function promiseFn (n) {
return new Promise(resolve => {
setTimeout(() => resolve(n), 15)
})
}
const fn = universalify.fromPromise(promiseFn)
// Works with Promises:
fn('Hello World!')
.then(result => console.log(result)) // -> Hello World!
.catch(error => console.error(error))
// Works with Callbacks:
fn('Hi!', (error, result) => {
if (error) return console.error(error)
console.log(result)
// -> Hi!
})
MIT
Pify is a package that promisifies functions. It converts functions that use node-style callbacks into functions that return promises. Unlike universalify, pify does not maintain callback support once promisified.
Bluebird is a comprehensive promise library that includes a promisify feature to convert callback-based functions into promise-returning functions. It is more feature-rich than universalify but also larger in size and does not support callbacks after promisification.
Util.promisify is a built-in Node.js utility function that converts a callback-based function into a promise-based one. It is similar to universalify but is limited to Node.js and does not support the original callback interface after conversion.
FAQs
Make a callback- or promise-based function support both promises and callbacks.
The npm package universalify receives a total of 93,759,339 weekly downloads. As such, universalify popularity was classified as popular.
We found that universalify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.