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

nextjs-fetch-utility

v1.0.0

Published

A simple, reusable utility function for fetching data in a Next.js environment.

Readme

open_cloud_upload

A simple, reusable utility for chunked file uploads with progress reporting and retries.

Installation

npm install open_cloud_upload

API Reference

The library exports a ChunkedUploader class with a single static method, uploadFile.

ChunkedUploader.uploadFile(file, metadata, options)

This static method handles the logic for slicing a file into chunks and uploading them sequentially to a server. It includes features like progress tracking, error handling, and automatic retries with exponential backoff.

Signature

import { ChunkedUploader, UploadMetadata, UploadOptions } from 'open_cloud_upload';

ChunkedUploader.uploadFile(
  file: File,
  metadata: UploadMetadata,
  options: UploadOptions
): Promise<void>;

Parameters

  1. file: File The File object that you want to upload. This is typically obtained from an <input type="file"> element.

  2. metadata: UploadMetadata An object containing metadata required by the upload endpoint.

    • token: string: An authentication token or session identifier.
    • type: string: A string identifying the type of object being uploaded (e.g., 'profile-picture', 'document').
    • _id?: string: (Optional) A unique ID for the file object. If not provided, a random one will be generated.
  3. options: UploadOptions An object to configure the upload behavior.

    • url: string: The URL of the API endpoint that will receive the file chunks.
    • chunkSize?: number: (Optional) The size of each chunk in bytes. Default: 5 * 1024 * 1024 (5 MB).
    • baseDelay?: number: (Optional) The base delay in milliseconds for the exponential backoff retry mechanism. Default: 100.
    • onUploadProgress?: (progress: number) => void: (Optional) A callback function that receives the upload progress as a number between 0 and 1.
    • onUploadSuccess?: (message: string) => void: (Optional) A callback function that is called with a success message when the file is fully uploaded.
    • onUploadError?: (error: any) => void: (Optional) A callback function that is called if the upload fails after all retry attempts.

Usage Example

Here is an example of how to use ChunkedUploader in a React/Next.js component.

import React, { useState } from "react";
import { ChunkedUploader } from "open_cloud_upload";

const FileUploader = () => {
  const [progress, setProgress] = useState(0);
  const [message, setMessage] = useState("");

  const handleFileChange = async (
    event: React.ChangeEvent<HTMLInputElement>
  ) => {
    const file = event.target.files?.[0];
    if (!file) return;

    setMessage("Starting upload...");
    setProgress(0);

    await ChunkedUploader.uploadFile(
      file,
      {
        token: "your-auth-token-here",
        type: "user-avatar",
        // _id is optional
      },
      {
        url: "/api/upload", // Your backend endpoint
        uploadProgress: (p) => setProgress(p * 100),
        onUploadSuccess: (msg) => setMessage(msg),
        onUploadError: (err) => setMessage(`Upload failed: ${err}`),
      }
    );
  };

  return (
    <div>
      <input type="file" onChange={handleFileChange} />
      {progress > 0 && <progress value={progress} max="100" />}
      <p>{message}</p>
    </div>
  );
};

export default FileUploader;