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

@giapspzoo/save-file

v2.0.0

Published

A TypeScript utility for saving files in the browser.

Downloads

32

Readme

@giapspzoo/save-file

A TypeScript utility for saving files in the browser.

Installation

This package is browser-only — it requires document and the DOM download APIs. It will not work in Node.js or SSR environments.

npm install @giapspzoo/save-file

Usage

import { saveFile, saveBlobFile } from "@giapspzoo/save-file";

// Save a file from URL with custom filename
saveFile({
  fileName: "my-document.pdf",
  url: "https://example.com/document.pdf",
});

// Save a file from URL without custom filename (uses original filename)
saveFile({
  url: "https://example.com/document.pdf",
});

// Save a file from Blob
const blob = new Blob(["Hello, World!"], { type: "text/plain" });

const blobUrl = saveBlobFile({
  fileName: "hello.txt",
  blob,
});

// Revoke when the browser no longer needs the URL (see note below)
URL.revokeObjectURL(blobUrl);

// Save an image from Base64
const imageBase64 =
  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==";

saveFile({
  fileName: "image.png",
  url: imageBase64,
});

API

saveFile(params: TSaveFileParams): void

Saves a file to the user's device.

Parameters

| Parameter | Type | Required | Description | | ---------- | -------- | -------- | ---------------------------------------------------------------------------------------------------------- | | url | string | Yes | The URL of the file to save | | fileName | string | No | The name of the file to be saved. If not provided, the browser will use the original filename from the URL |

saveBlobFile(params: TSaveBlobFileParams): string

Saves a Blob to the user's device. Creates a temporary object URL, triggers the download, and returns that URL so you can revoke it when appropriate.

Parameters

| Parameter | Type | Required | Description | | ---------- | -------- | -------- | -------------------------------- | | blob | Blob | Yes | The blob data to save | | fileName | string | No | The name of the file to be saved |

Blob URL cleanup

saveBlobFile does not revoke the object URL automatically. Call URL.revokeObjectURL(url) when the browser has finished reading it — otherwise the blob stays in memory.

There is no standard event for “download started,” so wait long enough for the download to begin before revoking. Revoking too early can cause silent download failures in some browsers.

How it works

This utility creates a temporary anchor element with the download attribute, triggers a click event, and then removes the element from the DOM. This approach works with:

  • Direct file URLs
  • Blob URLs
  • Data URLs
  • Files served with appropriate CORS headers

License

MIT