RyanZim / Universalify
Licence: mit
Make a callback- or promise-based function support both promises and callbacks.
Stars: ✭ 82
Programming Languages
javascript
184084 projects - #8 most used programming language
js
455 projects
Projects that are alternatives of or similar to Universalify
Declarativ
A declarative HTML rendering library that is definitely not JSX.
Stars: ✭ 16 (-80.49%)
Mutual labels: promises
Dynogels Promisified
Promisifies methods exposed by dynogels (Dynamo DB mapper)
Stars: ✭ 36 (-56.1%)
Mutual labels: promises
Electron Promise Ipc
Promise-flavored IPC calls in Electron. 100% test coverage.
Stars: ✭ 55 (-32.93%)
Mutual labels: promises
Backboard
A Promise-based wrapper around IndexedDB with sane error and transaction handling
Stars: ✭ 11 (-86.59%)
Mutual labels: promises
Native Promise Only
A polyfill for native ES6 Promises as close as possible (no extensions) to the strict spec definitions.
Stars: ✭ 708 (+763.41%)
Mutual labels: promises
Pinfuture
An Objective-C future implementation that aims to provide maximal type safety
Stars: ✭ 74 (-9.76%)
Mutual labels: promises
Bluebird Api
Bluebird compatible API on top of native promises.
Stars: ✭ 36 (-56.1%)
Mutual labels: promises
Modern Async
A modern JavaScript tooling library for asynchronous operations using async/await and promises
Stars: ✭ 31 (-62.2%)
Mutual labels: promises
Future
🚀 R package: future: Unified Parallel and Distributed Processing in R for Everyone
Stars: ✭ 735 (+796.34%)
Mutual labels: promises
Radon
Object oriented state management solution for front-end development.
Stars: ✭ 80 (-2.44%)
Mutual labels: promises
Ygor
Task toolkit. For when `npm run` isn't enough and everything else is too much.
Stars: ✭ 69 (-15.85%)
Mutual labels: promises
Node.pas
Asynchronous Event-driven server programming for EMB Delphi, powered by libuv.
Stars: ✭ 45 (-45.12%)
Mutual labels: promises
universalify
Make a callback- or promise-based function support both promises and callbacks.
Uses the native promise implementation.
Installation
npm install universalify
API
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!
})
License
MIT
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].