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

@happy-ts/fetch-t

v1.9.1

Published

Type-safe Fetch API wrapper with abortable requests, timeout support, progress tracking, automatic retry, and Rust-like Result error handling.

Downloads

3,150

Readme

fetchT

License Build Status codecov NPM version NPM downloads JSR Version JSR Score

Type-safe Fetch API wrapper with abortable requests, timeout support, progress tracking, automatic retry, and Rust-like Result error handling.


中文 | API Documentation


Features

  • Abortable Requests - Cancel requests anytime via FetchTask.abort()
  • Type-safe Responses - Specify return type with responseType parameter (text, json, arraybuffer, bytes, blob, stream)
  • Timeout Support - Auto-abort requests after specified milliseconds
  • Progress Tracking - Monitor download progress with onProgress callback
  • Chunk Streaming - Access raw data chunks via onChunk callback
  • Automatic Retry - Configurable retry strategies with retry option
  • Result Error Handling - Rust-like Result type for explicit error handling
  • Cross-platform - Works with Deno, Node.js, Bun, and browsers

Installation

# npm
npm install @happy-ts/fetch-t

# yarn
yarn add @happy-ts/fetch-t

# pnpm
pnpm add @happy-ts/fetch-t

# JSR (Deno)
deno add @happy-ts/fetch-t

# JSR (Bun)
bunx jsr add @happy-ts/fetch-t

Quick Start

Basic Usage

import { fetchT } from '@happy-ts/fetch-t';

// GET JSON data
const result = await fetchT<{ id: number; title: string }>('https://api.example.com/data', {
    responseType: 'json',
});

result.inspect(data => {
    console.log(data.title);
}).inspectErr(err => {
    console.error('Request failed:', err.message);
});

Abortable Request

const task = fetchT('https://api.example.com/large-file', {
    abortable: true,
    responseType: 'arraybuffer',
});

// Abort after 5 seconds
setTimeout(() => {
    task.abort('User cancelled');
}, 5000);

const result = await task.result;

Automatic Retry

const result = await fetchT('https://api.example.com/data', {
    retry: {
        retries: 3,
        delay: (attempt) => Math.min(1000 * Math.pow(2, attempt - 1), 10000),
        when: [500, 502, 503, 504],
        onRetry: (error, attempt) => console.log(`Retry ${attempt}: ${error.message}`),
    },
    responseType: 'json',
});

Examples

Error Handling Design

fetchT distinguishes between two types of errors:

Programming Errors (Synchronous)

Invalid parameters throw immediately for fail-fast behavior:

// These throw synchronously - no try/catch around await needed
fetchT('https://example.com', { timeout: -1 });     // Error: timeout must be > 0
fetchT('https://example.com', { timeout: 'bad' });  // TypeError: timeout must be a number
fetchT('not-a-url');                                // TypeError: Invalid URL

This differs from native fetch, which returns rejected Promises for parameter errors. Synchronous throws provide clearer stack traces and catch bugs during development.

Runtime Errors (Result Type)

Network failures and HTTP errors are wrapped in Result type:

const result = await fetchT('https://api.example.com/data', { responseType: 'json' });

if (result.isErr()) {
    const error = result.unwrapErr();
    // FetchError with status code, or network Error
}

License

MIT