Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codingbeautydev/try-catch-fn
Intuitive functional JavaScript try-catch
https://github.com/codingbeautydev/try-catch-fn
functional-programming javascript npm try-catch typescript
Last synced: about 1 month ago
JSON representation
Intuitive functional JavaScript try-catch
- Host: GitHub
- URL: https://github.com/codingbeautydev/try-catch-fn
- Owner: codingbeautydev
- Created: 2023-11-11T14:13:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-12T03:39:22.000Z (about 1 year ago)
- Last Synced: 2024-11-08T20:11:48.244Z (about 2 months ago)
- Topics: functional-programming, javascript, npm, try-catch, typescript
- Language: TypeScript
- Homepage: https://www.codingbeautydev.com/blog/javascript-functional-try-catch
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# try-catch-fn
Functional try-catch implementation.
More info here: [This is how functional try-catch transforms your JavaScript code](https://www.codingbeautydev.com/blog/javascript-functional-try-catch).
## Usage
```js
import { tryCatch } from 'try-catch-fn';const status = tryCatch({
tryFn: () => {
throw new Error('network error');
},
catchFn: (err) => 'error',
});console.log(status); // error
```Pass single function argument to simply "silence" any exception it throws.
```js
import { tryCatch } from 'try-catch-fn';const status = tryCatch(() => {
throw new Error('error');
});console.log(status); // null
```