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

gm-dl

v0.1.2

Published

A lightweight userscript download helper with native GM_download support and a safe XHR fallback.

Readme

gm-dl

A lightweight download helper for userscript environments that uses GM_download when available and falls back to an XHR-based implementation when it is not.

Why use it?

In browser userscripts, downloading files can be inconsistent across managers and browsers. gm-dl gives you one simple API and handles the common cases for you:

  • uses the native userscript download API when supported
  • falls back to GM.xmlHttpRequest with blob downloading when needed
  • supports AbortSignal cancellation
  • supports lifecycle callbacks such as onload, onerror, ontimeout, and onabort
  • works with a plain URL, Blob, or File, or with a full request object

Installation

npm install gm-dl

Quick start

Download from a URL

import GM_dl from 'gm-dl';

const signal = AbortSignal.timeout(30000);

await GM_dl('https://example.com/file.zip', 'file.zip', signal);

Download from a Blob or File

import GM_dl from 'gm-dl';

const blob = new Blob(['hello world'], { type: 'text/plain' });
await GM_dl(blob, 'hello.txt');

Use a full options object

import GM_dl from 'gm-dl';

await GM_dl({
  url: 'https://example.com/file.pdf',
  name: 'document.pdf',
  headers: {
    Accept: 'application/pdf',
  },
  onload: () => console.log('Download complete'),
  onerror: (error) => console.error('Download failed', error),
  ontimeout: () => console.warn('Download timed out'),
  onabort: () => console.warn('Download aborted'),
});

API

GM_dl(url, name, signal?)

Download a file from a URL or from a Blob/File object.

GM_dl(options)

Download using a request-like object. This is the full request shape accepted by the library:

type ExtendedDownloadRequest = GmDownloadOptions & {
  onabort?: () => void;
  signal?: AbortSignal;
};

The supported fields are:

interface GmDownloadOptions {
  url: string | Blob | File;
  name: string;
  headers?: Record<string, string>;
  saveAs?: boolean;
  conflictAction?: 'uniquify' | 'overwrite' | 'prompt';
  timeout?: number;
  onerror?: (event: GmDownloadErrorEvent) => void;
  ontimeout?: () => void;
  onload?: () => void;
  onprogress?: (event: GmDownloadProgressEvent) => void;
}

And the library adds two convenience options:

interface ExtendedDownloadRequest extends GmDownloadOptions {
  signal?: AbortSignal;
  onabort?: () => void;
}

Option details

  • url: string | Blob | File — the resource to download. A string URL is used for remote downloads; a Blob/File is downloaded directly.
  • name: string — the file name to save locally.
  • headers?: Record<string, string> — optional HTTP headers for remote downloads.
  • saveAs?: boolean — whether to show the browser's Save As dialog.
  • conflictAction?: 'uniquify' | 'overwrite' | 'prompt' — how to handle a filename collision.
  • timeout?: number — timeout in milliseconds.
  • onerror?: (event: GmDownloadErrorEvent) => void — called when the download fails.
  • ontimeout?: () => void — called when the download exceeds timeout.
  • onload?: () => void — called when the download completes successfully.
  • onprogress?: (event: GmDownloadProgressEvent) => void — called as download progress updates.
  • signal?: AbortSignal — aborts the operation from the caller if the signal is triggered.
  • onabort?: () => void — called when the operation is interrupted via signal or the internal abort logic.

GmDownloadErrorEvent is shaped like this:

interface GmDownloadErrorEvent {
  error:
    | 'not_enabled'
    | 'not_whitelisted'
    | 'not_permitted'
    | 'not_supported'
    | 'not_succeeded';
  details?: string;
}

GmDownloadProgressEvent is the browser-style progress event for downloads, and includes the downloaded file's final URL in addition to the usual progress fields.

Development

npm install
npm run build
npm run test

Scripts

  • npm run dev — start the Vite dev server
  • npm run build — build the distributable files
  • npm run preview — preview the build locally
  • npm run test — run the Vitest suite

License

MIT