Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/notkearash/safe

Handle your await/async promises safely without try/catch blocks.
https://github.com/notkearash/safe

javascript library npm typescript

Last synced: 23 days ago
JSON representation

Handle your await/async promises safely without try/catch blocks.

Awesome Lists containing this project

README

        

![safe() banner](./safe.png)

Handle your await/async promises safely without try/catch blocks.

## Installation

npm

```bash
npm i @kearash/safe
```

pnpm

```bash
pnpm add @kearash/safe
```

bun

```bash
bun i @kearash/safe
```

yarn

```bash
yarn add @kearash/safe
```

## Usage

```ts
import { safe } from '@kearash/safe';

const fetchData = async () => {
const [error, data] = await safe(fetch('https://jsonplaceholder.typicode.com/'));
if (error) {
console.error('Error fetching data:', error);
return;
}
console.log('Fetched data:', data);
};

fetchData();
```

## License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.