@kimmel/toolbelt
v0.1.1
Published
Utility functions for Kimmel projects
Downloads
3
Readme
Toolbelt
Useful utility functions for Kimmel projects
Installation
In your terminal:
$ yarn add @kimmel/toolbelt
Functions
attempt
Wraps a promise in a try/catch block and returns a tuple with the first item being any caught error, and the second item being the resolved promise.
import { attempt } from '@kimmel/toolbelt';
async function fetchData() {
return fetch('https://example.com');
}
async function tryToFetch() {
const [error, result] = await attempt(fetchData);
if (error) {
// do something
}
return result;
}
attempt
automatically infers the resolves type of your promise.