mirror of
https://github.com/github/codeql-action.git
synced 2026-01-01 20:20:07 +08:00
* Bump tough-cookie and @azure/ms-rest-js Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) and [@azure/ms-rest-js](https://github.com/Azure/ms-rest-js). These dependencies needed to be updated together. Updates `tough-cookie` from 4.0.0 to 4.1.3 - [Release notes](https://github.com/salesforce/tough-cookie/releases) - [Changelog](https://github.com/salesforce/tough-cookie/blob/master/CHANGELOG.md) - [Commits](https://github.com/salesforce/tough-cookie/compare/v4.0.0...v4.1.3) Updates `@azure/ms-rest-js` from 2.6.2 to 2.7.0 - [Changelog](https://github.com/Azure/ms-rest-js/blob/master/Changelog.md) - [Commits](https://github.com/Azure/ms-rest-js/commits) --- updated-dependencies: - dependency-name: tough-cookie dependency-type: indirect - dependency-name: "@azure/ms-rest-js" dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Update checked-in dependencies --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
77 lines
2.0 KiB
Markdown
77 lines
2.0 KiB
Markdown
# universalify
|
|
|
|
[](https://travis-ci.org/RyanZim/universalify)
|
|

|
|

|
|

|
|
|
|
Make a callback- or promise-based function support both promises and callbacks.
|
|
|
|
Uses the native promise implementation.
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
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.
|
|
|
|
```js
|
|
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.
|
|
|
|
```js
|
|
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
|