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

tryflow

v0.1.6

Published

Tryflow is a lightweight, production-ready utility for handling try-catch-finally blocks in JavaScript/TypeScript. It helps reduce boilerplate, improve error handling, and provide advanced features such as automatic retries, logging, customizable fallback

Readme

tryflow

tryflow is a lightweight, production-ready utility for handling try-catch-finally blocks in JavaScript/TypeScript. It helps reduce boilerplate, improve error handling, and provide advanced features such as automatic retries, logging, customizable fallback mechanisms and more...

NPM Version
License


✨ Features

Minimal Boilerplate – Simplifies error handling with a clean, reusable API.
Retries – Automatically retries failed operations based on configurable rules.
Custom Logging – Integrates logging for better debugging and monitoring.
Fallback Mechanism – Define graceful fallbacks when errors occur.
Finally Support – Execute cleanup logic after execution.
Production-Ready – Designed for real-world applications with TypeScript support.


📦 Installation

Install via npm, yarn, pnpm or bun:

npm install tryflow
# or
yarn add tryflow
# or
pnpm add tryflow
# or
bun add tryflow

🚀 Usage

Basic Example

import { safeExecute } from 'tryflow';

const fetchData = async () => {
  return await fetch('https://api.example.com/data').then((res) => res.json());
};

const result = await safeExecute(fetchData, {
  retries: 3,
  fallback: () => ({ error: 'Failed to fetch data' }),
  onError: (error) => console.error('Error occurred:', error),
});

console.log(result);

Using the Finally Block

const result = await safeExecute(
  async () => {
    return await fetch('https://api.example.com/data').then((res) =>
      res.json(),
    );
  },
  {
    retries: 2,
    fallback: () => ({ error: 'Default fallback data' }),
    finally: () => console.log('Execution completed.'),
  },
);

🛠 API Reference

safeExecute<T>(fn: () => Promise<T>, options?: SafeExecuteOptions<T>): Promise<T | ReturnType<FallbackFunction<T>>>

Parameters:

| Parameter | Type | Description | | --------- | ----------------------- | ------------------------------------- | | fn | () => Promise<T> | The asynchronous function to execute. | | options | SafeExecuteOptions<T> | Optional configuration. |

Options (SafeExecuteOptions<T>)

| Option | Type | Default | Description | | ---------- | ---------------------- | ----------- | --------------------------------------------------------------------- | | retries | number | 0 | Number of times to retry execution on failure. | | fallback | () => T | undefined | Function that returns fallback data in case of failure. | | onError | (error: any) => void | undefined | Custom error logging function. | | finally | () => void | undefined | Function that runs after execution, regardless of success or failure. |


🧪 Testing

The package is tested using Jest. To run tests:

npm test

📜 Contribution Guidelines

We welcome contributions! 🚀

How to Contribute

  1. Fork the Repository
  2. Clone Your Fork
    git clone https://github.com/<YOUR_GITHUB_USERNAME>/tryflow
    cd tryflow
  3. Install Dependencies
    pnpm install
  4. Create a New Branch
    git checkout -b feature-name
  5. Make Your Changes
  6. Run Tests
    pnpm run test
  7. Commit and Push
    git commit -m "feat: added new feature"
    git push origin feature-name
  8. Create a Pull Request

📜 License

This package is licensed under the MIT License.


📮 Contact & Support

For issues, feel free to open a GitHub Issue.