@beenotung/tslib
Version:
utils library in Typescript
36 lines • 898 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.thenF = exports.then = exports.isPromise = void 0;
const PromiseString = Promise.resolve().toString();
function isPromise(x) {
return (x &&
typeof x === 'object' &&
typeof x.toString === 'function' &&
x.toString() === PromiseString);
}
exports.isPromise = isPromise;
function then(x, f, onError) {
if (isPromise(x)) {
const res = x.then(f);
if (onError) {
res.catch(onError);
}
return res;
}
return f(x);
}
exports.then = then;
function thenF(f, q, onError) {
try {
const x = f();
return then(x, q, onError);
}
catch (e) {
if (typeof onError === 'function') {
onError(e);
}
return Promise.reject(e);
}
}
exports.thenF = thenF;
//# sourceMappingURL=result.js.map