Nicely Pointed Mandibles

    @kimmel/toolbelt
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.1 • Public • Published

    Toolbelt

    Useful utility functions for Kimmel projects

    codecov

    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.

    Install

    npm i @kimmel/toolbelt

    DownloadsWeekly Downloads

    1

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    5.55 kB

    Total Files

    12

    Last publish

    Collaborators

    • jacobhaug
    • zackify
    • ryanar