Skip to content

notkearash/safe

Repository files navigation

safe() banner

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

Installation

npm
npm i @kearash/safe
pnpm
pnpm add @kearash/safe
bun
bun i @kearash/safe
yarn
yarn add @kearash/safe

Usage

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 file for details.

About

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

Topics

Resources

License

Stars

Watchers

Forks