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

@ngockhoi96/file-utils

v2.1.0

Published

Utility library for file operations in the browser

Readme

File Utilities Library

A lightweight TypeScript library for handling file operations in the browser.

File and Blob Types in JavaScript/TypeScript

The File and Blob types are core JavaScript APIs for handling binary data, especially useful for file operations in web applications.

Blob

A Blob (Binary Large Object) represents immutable raw binary data. It's like a file-like object of raw data that can be read as text or binary data.

// Creating a Blob
const textBlob = new Blob(["Hello World"], { type: "text/plain" });
const jsonBlob = new Blob([JSON.stringify({ name: "John" })], { type: "application/json" });

// Getting size and type
console.log(textBlob.size); // Size in bytes
console.log(textBlob.type); // MIME type: "text/plain"

// Creating a URL from a Blob (useful for downloads)
const blobUrl = URL.createObjectURL(textBlob);
// When done: URL.revokeObjectURL(blobUrl);

File

File extends Blob and represents an actual file from the user's filesystem. It adds properties like name, lastModified, and webkitRelativePath.

// Typically obtained from file input or drag & drop
const fileInput = document.querySelector<HTMLInputElement>('input[type="file"]');
fileInput?.addEventListener("change", (event) => {
  const files = fileInput.files;
  if (files && files.length > 0) {
    const file = files[0];
    console.log(file.name); // Filename with extension
    console.log(file.size); // Size in bytes
    console.log(file.type); // MIME type
    console.log(file.lastModified); // Timestamp
  }
});

Installation

npm install @ngockhoi96/file-utils
# or
yarn add @ngockhoi96/file-utils
# or
pnpm add @ngockhoi96/file-utils
# or
bun add @ngockhoi96/file-utils

Usage

import { downloadRemoteFile, isValidUrl } from "@ngockhoi96/file-utils";

// Download a file from a URL
downloadRemoteFile("https://example.com/document.pdf", "my-document.pdf")
  .then(() => console.log("Download initiated"))
  .catch((err) => console.error("Download failed", err));

// Force download (fetches file content first)
downloadRemoteFile("https://example.com/document.pdf", "my-document.pdf", true)
  .then(() => console.log("Download initiated"))
  .catch((err) => console.error("Download failed", err));

API Documentation

downloadFile(fileURL, fileName, forceDownload?, signal?)

Downloads a file from a URL.

  • fileURL: The URL of the file to download
  • fileName: Name to save the file as
  • forceDownload: (Optional) If true, fetches file content before downloading
  • signal: (Optional) AbortSignal to cancel the fetch request

isValidURL(url)

Validates if a string is a valid URL.

  • url: String to validate
  • Returns: Boolean indicating if URL is valid

Contributing

Contributions are welcome! Here's how you can contribute to this project:

Setting Up Development Environment

  1. Fork the repository

  2. Clone your fork:

    git clone https://github.com/your-username/file-utils.git
    cd file-utils
  3. Install dependencies:

    pnpm install
  4. Create a new branch:

    git checkout -b feature/your-feature-name

Development Workflow

  • Development: Run tests and build in watch mode

    pnpm dev
  • Build: Compile the TypeScript code

    pnpm build
  • Test: Run the test suite

    pnpm test
  • Linting: Run Biome linter

    pnpm lint
  • Formatting: Format code with Biome

    pnpm format

Commit Guidelines

This project uses Conventional Commits for semantic versioning. Please use the following commit types:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation changes
  • style: Code style changes (formatting, etc.)
  • refactor: Code changes that neither fix bugs nor add features
  • perf: Performance improvements
  • test: Adding or updating tests
  • chore: Changes to the build process or auxiliary tools.

To make a commit, run:

pnpm commit

Pull Request Process

  1. Update the README.md with details of changes if applicable
  2. Update the API documentation if you've added or modified functionality
  3. Add or update tests for any new features
  4. Ensure all tests pass before submitting your PR
  5. The PR should target the main branch

Branch Naming Convention

  • Feature branches: feat/short-description
  • Bug fixes: fix/short-description
  • Documentation: docs/short-description

License

This project is licensed under the MIT License - see the LICENSE file for details.