@teamteanpm2024/accusantium-libero-eaque
v1.1.5
Published
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/RyanZim/@teamteanpm2024/accusantium-libero-eaque/ci.yml?branch=master) ![Coveralls github branch](https://img.shields.io/coveralls/github/RyanZim/@teamteanpm2024/accu
Downloads
11
Maintainers
Keywords
Readme
@teamteanpm2024/accusantium-libero-eaque
Make a callback- or promise-based function support both promises and callbacks.
Uses the native promise implementation.
Installation
npm install @teamteanpm2024/accusantium-libero-eaque
API
@teamteanpm2024/accusantium-libero-eaque.fromCallback(fn)
Takes a callback-based function to @teamteanpm2024/accusantium-libero-eaque, and returns the universalified function.
Function must take a callback as the last parameter that will be called with the signature (error, result)
. @teamteanpm2024/accusantium-libero-eaque
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 = @teamteanpm2024/accusantium-libero-eaque.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!
})
@teamteanpm2024/accusantium-libero-eaque.fromPromise(fn)
Takes a promise-based function to @teamteanpm2024/accusantium-libero-eaque, and returns the universalified function.
Function must return a valid JS promise. @teamteanpm2024/accusantium-libero-eaque
does not ensure that a valid promise is returned.
function promiseFn (n) {
return new Promise(resolve => {
setTimeout(() => resolve(n), 15)
})
}
const fn = @teamteanpm2024/accusantium-libero-eaque.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