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

@sanely/try

v0.1.0

Published

A better try/catch for TypeScript

Readme

@sanely/try is a small execution layer for TypeScript. You write normal functions. The package runs them, applies your retry, timeout, and cancellation policy, and returns errors as typed values instead of thrown exceptions.

The return type tells you everything that can come back: your value, the failures that you map, and the policy failures that your chain can add.

import * as try$ from "@sanely/try"

class OrderLookupError extends Error {}

const result = await try$
  .retry(3) // Up to 3 attempts in total, including the first
  .timeout("5s") // One total deadline across all attempts, in milliseconds or a time expression
  .run({
    try: async ({ signal }) => {
      const response = await fetch("https://api.example.com/orders/ord_123", {
        signal, // Aborts when the deadline expires
      })

      if (!response.ok) {
        throw new Error(`unexpected status ${response.status}`)
      }

      const order = (await response.json()) as { status: "pending" | "shipped" }
      return order.status
    },
    catch: () => new OrderLookupError("could not load the order"),
  })

// result is "pending" | "shipped" | OrderLookupError | TimeoutError

Features

  • Errors as values. Thrown errors come back as part of the return type.
  • Execution policies. Add retries, one total deadline, and cancellation without a change to the work.
  • Sync and async parity. runSync(...) maps failures and builds result unions the same way as run(...). Policies that wait or interrupt are async only.
  • Named task orchestration. Run concurrent and ordered workflows as objects of named tasks.
  • Instrumentation hooks. Observe execution with wrap(...) for logs, traces, and metrics.
  • Resource cleanup. Register cleanup that runs when a scope or an orchestration ends, with disposer() and this.$disposer.
  • No external dependencies. The only runtime dependency is @sanely/duration, which reads time expressions such as "500ms".

Install

npm install @sanely/try

The package needs AbortSignal.any and Promise.withResolvers. Node.js 22 or later has both, and the package declares that floor in its engines field. Recent Bun, Deno, and current browsers also have both.

Get started

Run a function. A thrown error comes back as an UnhandledException value:

import * as try$ from "@sanely/try"

const result = await try$.run(async () => {
  const response = await fetch("https://api.example.com/health")
  return response.status
})

// result is number | UnhandledException

Use the object form to map thrown errors to your own error types:

class InvalidConfigError extends Error {}

const config = try$.runSync({
  try: () => JSON.parse(process.env.APP_CONFIG ?? "") as { port: number },
  catch: () => new InvalidConfigError("APP_CONFIG is not valid JSON"),
})

// config is { port: number } | InvalidConfigError

Documentation

How-to guides:

Reference:

Explanation:

Contributing

Read the contributor guide before changing the package.

Acknowledgments

  • better-result for typed result-oriented error handling in TypeScript.
  • effect for structured, composable models of execution, failure, and concurrency.
  • better-all for task orchestration patterns over object-shaped work graphs.
  • errore for modeling errors as unions instead of tuples.

Made with 🥐 pastry.

License

MIT. See LICENSE.