git-command-helper
Version:
github command helper for nodejs
32 lines (30 loc) • 777 B
JavaScript
// git-command-helper 2.1.0 by Dimas Lanjaka <dimaslanjaka@gmail.com> (https://www.webmanajemen.com)
class helper {
/**
* Suppress Catch of async function or catch of errors
* @param cb
* @returns null = failed (catch caught)
*/
static async suppress(cb) {
try {
//return await Bluebird.resolve(cb).then((res) => res);
if (this.isPromise(cb)) {
return await cb();
} else {
return cb();
}
} catch (e) {
return e;
}
}
/**
* is variable promise function?
* @param p
* @returns
*/
static isPromise(p) {
//console.log(Object.prototype.toString.call(p));
return p && /\[object (Promise|AsyncFunction)\]/i.test(Object.prototype.toString.call(p));
}
}
export { helper as default };