-first commit
This commit is contained in:
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;
|
||||
Reference in New Issue
Block a user