0.1.0 • Published 6 months ago

try-function v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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!

0.1.0

6 months ago