Fix actions/tour
This commit is contained in:
21
node_modules/catering/LICENSE
generated
vendored
Normal file
21
node_modules/catering/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright © 2018 Vincent Weevers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
10
node_modules/catering/index.d.ts
generated
vendored
Normal file
10
node_modules/catering/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export function fromCallback<T, S extends symbol>(callback: Callback<T> | undefined, symbol: S)
|
||||
: Callback<T> & { [K in S]?: Promise<T> };
|
||||
|
||||
export function fromCallback<T>(callback: Callback<T> | undefined)
|
||||
: Callback<T> & { promise?: Promise<T> };
|
||||
|
||||
export function fromPromise<T>(promise: Promise<T>, callback: Callback<T> | undefined)
|
||||
: Promise<T> | undefined;
|
||||
|
||||
type Callback<T> = (err: Error | null, result: T) => void;
|
||||
28
node_modules/catering/index.js
generated
vendored
Normal file
28
node_modules/catering/index.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
|
||||
var nextTick = require('./next-tick')
|
||||
|
||||
exports.fromCallback = function (callback, symbol) {
|
||||
if (callback === undefined) {
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
callback = function (err, res) {
|
||||
if (err) reject(err)
|
||||
else resolve(res)
|
||||
}
|
||||
})
|
||||
|
||||
callback[symbol !== undefined ? symbol : 'promise'] = promise
|
||||
} else if (typeof callback !== 'function') {
|
||||
throw new TypeError('Callback must be a function')
|
||||
}
|
||||
|
||||
return callback
|
||||
}
|
||||
|
||||
exports.fromPromise = function (promise, callback) {
|
||||
if (callback === undefined) return promise
|
||||
|
||||
promise
|
||||
.then(function (res) { nextTick(() => callback(null, res)) })
|
||||
.catch(function (err) { nextTick(() => callback(err)) })
|
||||
}
|
||||
1
node_modules/catering/next-tick-browser.js
generated
vendored
Normal file
1
node_modules/catering/next-tick-browser.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = typeof queueMicrotask === 'function' ? queueMicrotask : (fn) => Promise.resolve().then(fn)
|
||||
1
node_modules/catering/next-tick.js
generated
vendored
Normal file
1
node_modules/catering/next-tick.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = process.nextTick.bind(process)
|
||||
38
node_modules/catering/package.json
generated
vendored
Normal file
38
node_modules/catering/package.json
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "catering",
|
||||
"version": "2.1.1",
|
||||
"description": "Simple utility to allow your module to be consumed with a callback or promise",
|
||||
"license": "MIT",
|
||||
"author": "Vincent Weevers",
|
||||
"scripts": {
|
||||
"test": "standard && node test.js",
|
||||
"test-browsers-local": "airtap test.js"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"next-tick.js",
|
||||
"next-tick-browser.js"
|
||||
],
|
||||
"browser": {
|
||||
"./next-tick.js": "./next-tick-browser.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"airtap": "^4.0.4",
|
||||
"airtap-playwright": "^1.0.1",
|
||||
"standard": "^16.0.4",
|
||||
"tape": "^5.4.0"
|
||||
},
|
||||
"keywords": [
|
||||
"callback",
|
||||
"promise",
|
||||
"promisify"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"repository": "vweevers/catering",
|
||||
"bugs": "https://github.com/vweevers/catering/issues",
|
||||
"homepage": "https://github.com/vweevers/catering"
|
||||
}
|
||||
55
node_modules/catering/readme.md
generated
vendored
Normal file
55
node_modules/catering/readme.md
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
# catering
|
||||
|
||||
**Cater to callback and promise crowds.**
|
||||
Simple utility to allow your module to be consumed with a callback or promise. For Node.js and browsers.
|
||||
|
||||
[](https://www.npmjs.com/package/catering)
|
||||
[](https://www.npmjs.com/package/catering)
|
||||
[](https://github.com/vweevers/catering/actions/workflows/test.yml)
|
||||
[](https://standardjs.com)
|
||||
|
||||
## Menu
|
||||
|
||||
If your module internally uses callbacks:
|
||||
|
||||
```js
|
||||
const { fromCallback } = require('catering')
|
||||
const kPromise = Symbol('promise')
|
||||
|
||||
module.exports = function (callback) {
|
||||
callback = fromCallback(callback, kPromise)
|
||||
queueMicrotask(() => callback(null, 'example'))
|
||||
return callback[kPromise]
|
||||
}
|
||||
```
|
||||
|
||||
If your module internally uses promises:
|
||||
|
||||
```js
|
||||
const { fromPromise } = require('catering')
|
||||
|
||||
module.exports = function (callback) {
|
||||
return fromPromise(Promise.resolve('example'), callback)
|
||||
}
|
||||
```
|
||||
|
||||
Either way your module can now be consumed in two ways:
|
||||
|
||||
```js
|
||||
example((err, result) => {})
|
||||
const result = await example()
|
||||
```
|
||||
|
||||
When converting from a promise to a callback, `fromPromise` calls the callback in a next tick to escape the promise chain and not let it steal your beautiful errors.
|
||||
|
||||
## Install
|
||||
|
||||
With [npm](https://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install catering
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE) © 2018-present Vincent Weevers. Originally extracted from [`levelup`](https://github.com/Level/levelup/blob/37e0270c8c29d5086904e29e247e918dddcce6e2/lib/promisify.js).
|
||||
Reference in New Issue
Block a user