npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lekoma/promise-as-u-go

v1.0.2

Published

Library that combines the concept of promises with the Go-inspired approach

Readme

Promise-as-U-Go

promise-as-u-go is a small utility library that provides two functions to handle promises with built-in error catching and easier management of results. It wraps your promises in a try/catch block and returns consistent outcomes—whether the promise resolves or rejects—allowing you to handle errors gracefully while maintaining clean and readable code.

Table of Contents

Installation

To install promise-as-u-go, use npm or yarn:

npm install promise-as-u-go

or

yarn add promise-as-u-go

Usage

The library exposes two functions: tryCatch and tryCatchOn.

tryCatch

tryCatch is a utility function that wraps a promise and handles errors. It returns a tuple with the result or an error.

Example: Catching Errors

import { tryCatch } from 'promise-as-u-go';

async function example() {
  const [error, result] = await tryCatch(Promise.reject(new Error('Something went wrong')));
  if (error) {
    console.error('Caught error:', error);
  } else {
    console.log('Promise resolved:', result);
  }
}

example(); // Caught error: Error: Something went wrong

If the promise resolves successfully, tryCatch returns [undefined, result]. If the promise is rejected, it returns [error].

tryCatchOn

tryCatchOn allows you to catch specific types of errors by providing a list of error classes (constructors). This is useful when you want to handle particular types of errors differently.

Example: Catching Specific Errors

import { tryCatchOn } from 'promise-as-u-go';

class SpecificError extends Error {}

async function example() {
  const [error, result] = await tryCatchOn(
    Promise.reject(new SpecificError('A specific error occurred')),
    [SpecificError] // Only catch SpecificError
  );
  
  if (error) {
    console.error('Caught specific error:', error);
  } else {
    console.log('Promise resolved:', result);
  }
}

example(); // Caught specific error: SpecificError: A specific error occurred

If the promise is rejected and the error matches one of the classes in the errorsToCatch array, tryCatchOn returns [error]. Otherwise, it rethrows the error.

Example: Catching Any Error

import { tryCatchOn } from 'promise-as-u-go';

async function example() {
  const [error, result] = await tryCatchOn(
    Promise.reject(new Error('A general error occurred'))
  );
  
  if (error) {
    console.error('Caught error:', error);
  } else {
    console.log('Promise resolved:', result);
  }
}

example(); // Caught error: Error: A general error occurred

API

tryCatch

declare async function tryCatch<T>(
  promise: Promise<T>
): Promise<readonly [undefined, T] | [Error]>;

tryCatchOn

declare async function tryCatchOn<T, E extends new (...args: any[]) => Error>(
  promise: Promise<T>,
  errorsToCatch?: E[]
): Promise<readonly [undefined, T] | [Error]>;

License

Apache-2.0 © Marco Leko