0.0.0 • Published 5 years ago

@zhaoyao91/try-catch v0.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

Try Catch

Return result and error instead of throwing.

Installation

npm i @zhaoyao91/try-catch

Usage

handle sync function

const tryCatch = require("@zhaoyao91/try-catch");

function fn(...args) {
  // throw or return
}

const [error, result] = tryCatch(fn, ...args);

handle async function

const tryCatch = require("@zhaoyao91/try-catch");

async function fn(...args) {
  // throw or return
}

const [error, result] = await tryCatch(fn, ...args);

Customize promise judge logic

require("@zhaoyao91/try-catch").isPromise = function(x) {
  // customized logic to tell if x is a promise
};

License

MIT