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

save-as-file

v0.4.0

Published

A simple fn to save a file to disk

Readme

save-as-file

A simple fn to save a file to disk.

npm CI Coveralls Github Branch

Table of Contents

Installation


You can install this package from NPM:

npm add save-as-file

Or with Yarn:

yarn add save-as-file

CDN

For CDN, you can use unpkg:

https://unpkg.com/save-as-file/dist/index.min.js

The global namespace for save-as-file is saveAsFile:

<script src="https://unpkg.com/save-as-file/dist/index.min.js"></script>

<script>
    const json = JSON.stringify({ping: true});
    const file = new File([json], 'test.json', {type: 'application/json'});
    saveAsFile(file, 'test.json');
</script>

Usage


ES6

Save a File to disk:

import saveFile from 'save-as-file';
const json = JSON.stringify({ping: true});
const file = new File([json], 'test.json', {type: 'application/json'});
saveFile(file, 'test.json');

Since a File already carries a name, filename is optional for File input and defaults to the File's own name:

saveFile(file); // saved as file.name

NOTE: For File/Blob objects we create a temporary object URL which we revoke after 1 minute. If you need to download a large file which may take longer than 1 minute to download, use the 3rd argument to increase this timeout:

import saveFile from 'save-as-file';
const json = JSON.stringify({ping: true});
const file = new File([json], 'test.json', {type: 'application/json'});
saveFile(file, 'test.json', 1000 * 60 * 10 /* 10 mins */);

CommonJS

Save a File to disk:

const saveFile = require('save-as-file');
const json = JSON.stringify({ping: true});
const file = new File([json], 'test.json', {type: 'application/json'});
saveFile(file, 'test.json');

API


saveFile(data, filename?, gcTimeout?): void

| Param | Type | Default | Description | | ----------- | ------------------------ | ----------- | ----------------------------------------------------------------------------------------- | | data | File \| Blob \| string | - | The File/Blob to save, or an existing object URL string. | | filename | string | data.name | Name to save the file as. Optional for File input; defaults to the File's own name. | | gcTimeout | number | 60000 | Milliseconds to wait before revoking a created object URL. Only used for File/Blob input. |

Browser Support


You can expect this lib to run wherever the download attribute of an <a> element is supported. See the browserslist field in package.json for the full support matrix.

Contribute


See AGENTS.md for the full workflow and conventions. In short:

npm ci                # install dependencies
npm run lint          # oxlint
npm run format        # prettier
npm run typecheck     # tsc (TypeScript 7)
npm run build         # tsdown
npm test              # vitest