try-function
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

try-function

NPM version Build Test coverage Size

Installation

npm install try-function

Usage

Convert this:

let payload: string | undefined;
try {
  payload = decode("abc123");
} catch (error) {
  // ...
}

... to this:

const payload = tryFn(
  () => decode("abc123"),
  (error) => {
    // ...
  }
);
  • Functional with no re-assignement (no need for let)
  • Less error-prone
  • Automatic typing (no need to define result's type)
  • Supports async functions out-of-the-box
  • Supports finally blocks
  • No dependencies
  • Fully tested

Changelog

For a list of changes and releases, see the changelog.

Contributing

Found a bug, have a question or looking to improve try-function? Open an issue, start a discussion or submit a PR!

/try-function/

    Package Sidebar

    Install

    npm i try-function

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    5.47 kB

    Total Files

    6

    Last publish

    Collaborators

    • alexnault