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

@simongrayman/edge-upload

v0.1.0

Published

Modern, type-safe, and edge-compatible file upload parser for Web Standards.

Readme

edge-upload 🚀

A modern, type-safe, and edge-compatible file upload parser for Web Standards.

Say goodbye to legacy multipart parsers like multer. edge-upload is built from the ground up to work seamlessly in Node.js, Next.js (App Router), Cloudflare Workers, Deno, Bun, and any environment that supports the standard Web Request and Response APIs.

✨ Features

  • 🌍 Universal: Works everywhere (Node.js, Edge, Serverless).
  • 🛡️ Type-Safe: First-class TypeScript support with optional Zod integration.
  • 🔒 Secure by Default: Automatically generates secure filenames (UUID) to prevent Directory Traversal attacks.
  • Lightweight: Zero heavy dependencies, built on native Web FormData API.
  • 🎯 Developer Experience: Clean, Promise-based API with structured error handling.

📦 Installation

npm install edge-upload

(Optional but highly recommended for type-safe validation)

npm install zod

🚀 Quick Start

Basic Usage (No Validation)

import { parseUpload, UploadError } from 'edge-upload';

export async function POST(request: Request) {
  try {
    const result = await parseUpload(request, {
      maxFileSize: '5MB',
      maxFiles: 1,
      allowedMimeTypes: ['image/jpeg', 'image/png']
    });

    const file = result.files['avatar']?.[0];
    const username = result.fields['username'];

    return new Response(`Hello ${username}, received ${file.name}`, { status: 200 });
  } catch (error) {
    if (error instanceof UploadError) {
      return new Response(error.message, { status: error.statusCode });
    }
    return new Response('Internal Server Error', { status: 500 });
  }
}

Advanced Usage (with Zod Validation) 🌟

import { parseUpload, UploadError } from 'edge-upload';
import { z } from 'zod';

const uploadSchema = z.object({
  avatar: z.custom<File>().refine(
    (file) => file.size <= 5 * 1024 * 1024, 
    { message: "Max file size is 5MB" }
  ).refine(
    (file) => ["image/jpeg", "image/png"].includes(file.type),
    { message: "Only JPG and PNG are allowed" }
  ),
  username: z.string().min(3).max(20),
});

export async function POST(request: Request) {
  try {
    // Result is fully type-safe based on your Zod schema!
    const result = await parseUpload(request, { schema: uploadSchema });
    
    // result.data.avatar is guaranteed to be a valid File
    // result.data.username is guaranteed to be a string (3-20 chars)
    
    return Response.json({ success: true, data: result.data });
  } catch (error) {
    if (error instanceof UploadError && error.code === 'VALIDATION_ERROR') {
      return Response.json({ errors: error.details }, { status: 400 });
    }
    return Response.json({ error: 'Upload failed' }, { status: 500 });
  }
}

⚙️ API Reference

parseUpload(request: Request, options?: ParseOptions)

Options:

  • maxFileSize (string | number): Maximum allowed file size (e.g., '5MB', '100KB', or 5242880 in bytes).
  • maxFiles (number): Maximum number of files allowed in a single request (default: Infinity).
  • allowedMimeTypes (string[]): Array of allowed MIME types (e.g., ['image/png', 'application/pdf']).
  • preserveFileName (boolean): If true, keeps the original filename. If false (default), generates a secure UUID filename.
  • schema (Zod Schema): Optional Zod schema for type-safe validation of both files and text fields.

Returns:

A ParseResult object containing:

  • files: Record<string, File[]> - Parsed files grouped by their form field name.
  • fields: Record<string, string> - Parsed text fields.
  • data: T - The fully validated data object (if a Zod schema was provided).

📄 License

MIT