Skip to content

Commit

Permalink
Readme wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnault committed Nov 7, 2023
1 parent bc50f37 commit 3c24120
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
# try-function

![NPM version](https://img.shields.io/npm/v/try-function?style=flat-square)
![Build](https://img.shields.io/github/actions/workflow/status/alexnault/try-function/ci-and-publish.yml?branch=main&style=flat-square)
![Test coverage](https://img.shields.io/codecov/c/github/alexnault/try-function?style=flat-square)
![Size](https://img.shields.io/badge/dynamic/json?color=blue&label=size&query=$.size.uncompressedSize&url=https://deno.bundlejs.com?q=try-function&style=flat-square)

## Installation

```bash
npm install try-function
```

## Usage

Convert this:

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

... to this:

```ts
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](https://github.com/alexnault/try-function/releases).
Expand Down

0 comments on commit 3c24120

Please sign in to comment.