-first commit
This commit is contained in:
22
node_modules/standard-as-callback/LICENSE
generated
vendored
Normal file
22
node_modules/standard-as-callback/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Zihua Li
|
||||
Copyright (c) 2013-2017 Petka Antonov
|
||||
|
||||
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.
|
||||
33
node_modules/standard-as-callback/README.md
generated
vendored
Normal file
33
node_modules/standard-as-callback/README.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Standard asCallback
|
||||
A performant and standard (Bluebird) library that registers a node-style callback on a promise.
|
||||
|
||||
[](https://travis-ci.org/luin/asCallback)
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install standard-as-callback
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
const asCallback = require('standard-as-callback')
|
||||
|
||||
const promise = new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
resolve('hello world!')
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
asCallback(promise, function callback (err, res) {
|
||||
console.log(err, res) // null, 'hello world!'
|
||||
})
|
||||
```
|
||||
|
||||
## Thanks
|
||||
|
||||
Most code of this library are ported from the awesome Bluebird library.
|
||||
|
||||
## License
|
||||
The MIT License.
|
||||
5
node_modules/standard-as-callback/built/index.d.ts
generated
vendored
Normal file
5
node_modules/standard-as-callback/built/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { CallbackFunction } from "./types";
|
||||
export interface IOptions {
|
||||
spread: boolean;
|
||||
}
|
||||
export default function asCallback<T>(promise: Promise<T>, nodeback: CallbackFunction<T>, options?: IOptions): Promise<T>;
|
||||
41
node_modules/standard-as-callback/built/index.js
generated
vendored
Normal file
41
node_modules/standard-as-callback/built/index.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const utils_1 = require("./utils");
|
||||
function throwLater(e) {
|
||||
setTimeout(function () {
|
||||
throw e;
|
||||
}, 0);
|
||||
}
|
||||
function asCallback(promise, nodeback, options) {
|
||||
if (typeof nodeback === "function") {
|
||||
promise.then((val) => {
|
||||
let ret;
|
||||
if (options !== undefined &&
|
||||
Object(options).spread &&
|
||||
Array.isArray(val)) {
|
||||
ret = utils_1.tryCatch(nodeback).apply(undefined, [null].concat(val));
|
||||
}
|
||||
else {
|
||||
ret =
|
||||
val === undefined
|
||||
? utils_1.tryCatch(nodeback)(null)
|
||||
: utils_1.tryCatch(nodeback)(null, val);
|
||||
}
|
||||
if (ret === utils_1.errorObj) {
|
||||
throwLater(ret.e);
|
||||
}
|
||||
}, (cause) => {
|
||||
if (!cause) {
|
||||
const newReason = new Error(cause + "");
|
||||
Object.assign(newReason, { cause });
|
||||
cause = newReason;
|
||||
}
|
||||
const ret = utils_1.tryCatch(nodeback)(cause);
|
||||
if (ret === utils_1.errorObj) {
|
||||
throwLater(ret.e);
|
||||
}
|
||||
});
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
exports.default = asCallback;
|
||||
1
node_modules/standard-as-callback/built/types.d.ts
generated
vendored
Normal file
1
node_modules/standard-as-callback/built/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare type CallbackFunction<T> = ((err: null, val: T) => void) | ((err: Error) => void);
|
||||
2
node_modules/standard-as-callback/built/types.js
generated
vendored
Normal file
2
node_modules/standard-as-callback/built/types.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
9
node_modules/standard-as-callback/built/utils.d.ts
generated
vendored
Normal file
9
node_modules/standard-as-callback/built/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { CallbackFunction } from "./types";
|
||||
export declare const errorObj: {
|
||||
e: {};
|
||||
};
|
||||
declare function tryCatcher<T>(err: Error, val?: T): void | {
|
||||
e: Error;
|
||||
};
|
||||
export declare function tryCatch<T>(fn: CallbackFunction<T>): typeof tryCatcher;
|
||||
export {};
|
||||
23
node_modules/standard-as-callback/built/utils.js
generated
vendored
Normal file
23
node_modules/standard-as-callback/built/utils.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.tryCatch = exports.errorObj = void 0;
|
||||
//Try catch is not supported in optimizing
|
||||
//compiler, so it is isolated
|
||||
exports.errorObj = { e: {} };
|
||||
let tryCatchTarget;
|
||||
function tryCatcher(err, val) {
|
||||
try {
|
||||
const target = tryCatchTarget;
|
||||
tryCatchTarget = null;
|
||||
return target.apply(this, arguments);
|
||||
}
|
||||
catch (e) {
|
||||
exports.errorObj.e = e;
|
||||
return exports.errorObj;
|
||||
}
|
||||
}
|
||||
function tryCatch(fn) {
|
||||
tryCatchTarget = fn;
|
||||
return tryCatcher;
|
||||
}
|
||||
exports.tryCatch = tryCatch;
|
||||
40
node_modules/standard-as-callback/package.json
generated
vendored
Normal file
40
node_modules/standard-as-callback/package.json
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "standard-as-callback",
|
||||
"version": "2.1.0",
|
||||
"description": "A performant and standard (Bluebird) library that registers a node-style callback on a promise",
|
||||
"main": "built/index.js",
|
||||
"types": "built/index.d.ts",
|
||||
"directories": {
|
||||
"lib": "built"
|
||||
},
|
||||
"files": [
|
||||
"built/"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rm -rf built && tsc",
|
||||
"test": "npm run build && mocha",
|
||||
"prepublishOnly": "npm test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/luin/asCallback.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ascallback",
|
||||
"nodeify",
|
||||
"promise",
|
||||
"bluebird"
|
||||
],
|
||||
"author": "luin <i@zihua.li>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/luin/asCallback/issues"
|
||||
},
|
||||
"homepage": "https://github.com/luin/asCallback#readme",
|
||||
"devDependencies": {
|
||||
"mocha": "^8.3.2",
|
||||
"promise-timeout": "^1.3.0",
|
||||
"sinon": "^9.2.4",
|
||||
"typescript": "^4.2.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user