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

await-to-done

v1.2.0

Published

Async await wrapper for easy error handling - zero dependencies

Readme

await-to-done

Async await wrapper for easy error handling

Zero dependencies • ES5 compatible • TypeScript ready

npm version npm downloads gzip License

Sonar

Why?

Stop writing try-catch blocks everywhere. await-to-done wraps your promises and returns a tuple [error, data] for elegant error handling.

// Before 😫
try {
  const data = await fetchData()
  // handle data
} catch (error) {
  // handle error
}

// After 😍
import to from 'await-to-done'

const [error, data] = await to(fetchData())
if (error) {
  // handle error
}
// handle data

Install

pnpm add await-to-done
# or
npm install await-to-done

Usage

Single Promise

import to from 'await-to-done'

const [error, user] = await to(fetchUser(id))

if (error) {
  console.error('Failed to fetch user:', error)
  return
}

console.log('User:', user)

Multiple Promises

import to from 'await-to-done'

// Pass multiple promises as arguments
const [error, [user, posts]] = await to(fetchUser(id), fetchPosts(id))

// Or pass an array
const [error, results] = await to([fetchUser(id), fetchPosts(id)])

Custom Error Type

import to from 'await-to-done'

interface ApiError {
  code: number
  message: string
}

const [error, data] = await to<string, ApiError>(fetchData())
if (error) {
  console.log(error.code, error.message)
}

Browser / CDN

<script src="https://unpkg.com/await-to-done/dist/index.umd.js"></script>
<script>
  const [error, data] = await awaitToDone(fetch('/api/data'))
</script>

API

to<T, E>(promise)

| Parameter | Type | Description | | ----------- | -------------------------------------- | ----------------------- | | promise | Promise<T> | A promise to wrap | | Returns | Promise<[E, undefined] \| [null, T]> | Tuple of error and data |

to<P>(promises)

| Parameter | Type | Description | | ----------- | ------------------------------------------ | --------------------------- | | promises | Promise[] | Array of promises | | Returns | Promise<[Error, undefined] \| [null, P]> | Tuple with array of results |

Types

// Result tuple type
type Result<T, E = Error> = [E, undefined] | [null, T]

// Async result type
type AsyncResult<T, E = Error> = Promise<Result<T, E>>

Bundle Size

| File | Size (min + gzip) | | --------------- | ----------------- | | index.min.mjs | ~300 B | | index.umd.js | ~400 B |

Comparison

| Feature | await-to-done | await-to-js | | ----------------- | ------------- | ----------- | | Dependencies | 0 | 0 | | TypeScript types | ✅ Built-in | ❌ Separate | | Multiple promises | ✅ | ❌ | | Array support | ✅ | ❌ | | ES5 compatible | ✅ | ✅ | | Size | ~300 B | ~200 B |

License

MIT