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

@baybreezy/file-extension-icon

v0.0.7

Published

Modern, lightweight package for folder and file extension specific Material icons and VSCode icons

Readme

@baybreezy/file-extension-icon

Demo Cover Image

Modern, TypeScript-first package for file and folder extension-specific Material and VSCode icons

A complete rewrite of file-extension-icon-js using modern TypeScript, ESM-first approach, and the UnJS ecosystem for optimal performance and developer experience.

npm version npm bundle size License: MIT

✨ Features

  • 🎨 Two icon themes: Material Icon Theme & VSCode Icons
  • 🔷 TypeScript: Full type safety with comprehensive type definitions
  • 📦 Zero dependencies: No runtime dependencies
  • 🌳 Tree-shakeable: Per-theme entry points, so you only load the icons you use
  • 🔄 Dual format: ESM and CommonJS support
  • 🧾 Output formats: base64 data URI, URL-encoded data URI or raw SVG
  • 🛣️ Paths welcome: src/app/package.json resolves like package.json
  • 🧩 Customizable: add your own file/folder associations and SVG icons
  • ⚛️ React & Vue components: <FileIcon name="index.ts" />
  • 🚀 Modern build: Built with tsdown
  • ✅ Well-tested: Comprehensive test coverage
  • 📝 Well-documented: Full JSDoc comments and examples
  • 🖥️ CLI included: Interactive and scriptable terminal tool for browsing and exporting icons

📦 Installation

# @antfu/ni
npx ni @baybreezy/file-extension-icon

🚀 Usage

Basic Usage

import {
  getMaterialFileIcon,
  getMaterialFolderIcon,
  getVSIFileIcon,
  getVSIFolderIcon,
} from "@baybreezy/file-extension-icon";

// Get Material Design file icon
const jsIcon = getMaterialFileIcon("index.js");
// Returns: "data:image/svg+xml;base64,..."

// Get Material Design folder icon (closed)
const folderIcon = getMaterialFolderIcon("components");

// Get Material Design folder icon (open)
const openFolderIcon = getMaterialFolderIcon("components", true);

// Get VSCode file icon
const tsIcon = getVSIFileIcon("app.ts");

// Get VSCode folder icon
const vsiFolderIcon = getVSIFolderIcon("src", true);

File and folder names can also be paths (/ or \); the last segment is used. Matching is case-insensitive.

getMaterialFileIcon("src/app/package.json"); // same as "package.json"
getMaterialFolderIcon("project/src/", true); // same as "src"

Load Only One Theme

If you only use one icon theme, import it from its own entry point. This loads just that theme's icon data, which keeps your bundle (and server start-up) much smaller:

// Material Icon Theme only (~0.9 MB of icon data instead of ~4.2 MB)
import {
  getMaterialFileIcon,
  getMaterialFolderIcon,
} from "@baybreezy/file-extension-icon/material";
// VSCode Icons only
import { getVSIFileIcon, getVSIFolderIcon } from "@baybreezy/file-extension-icon/vsi";

The root import (@baybreezy/file-extension-icon) still exports everything, as before.

Output Formats

Every icon function takes an optional format:

| Format | Returns | Use it for | | ------------------ | ------------------------------- | ------------------------------------- | | "base64" default | data:image/svg+xml;base64,... | <img src>, CSS url(), anywhere | | "utf8" | data:image/svg+xml,%3Csvg ... | Same places, ~23% smaller than base64 | | "svg" | <svg ...>...</svg> | Inline SVG, writing .svg files |

getMaterialFileIcon("index.ts", { format: "svg" });
getMaterialFolderIcon("src", { open: true, format: "utf8" });

Encoded results are cached per icon, so repeated lookups are cheap.

One API for Both Themes

import { getFileIcon, getFolderIcon } from "@baybreezy/file-extension-icon";

getFileIcon("index.ts"); // Material (default)
getFileIcon("index.ts", { theme: "vsi", format: "svg" }); // VSCode Icons
getFolderIcon("src", { theme: "vsi", open: true });

Icon Details

Find out which icon was picked and why:

import { getFileIconInfo } from "@baybreezy/file-extension-icon";

getFileIconInfo("Dockerfile.dev");
// {
//   iconName: "docker",
//   matchedBy: "fileName",     // "fileName" | "extension" | "folderName" | "default"
//   matchedKey: "dockerfile.dev",
//   svg: "<svg ...>",
//   dataUri: "data:image/svg+xml;base64,..."
// }

Icons by Name

import { getAssociations, getIconByName, getIconNames } from "@baybreezy/file-extension-icon";

getIconByName("typescript"); // Material file icon by icon name
getIconByName("folder-src", { type: "folder", open: true, format: "svg" });
getIconByName("nope"); // undefined

getIconNames(); // { file: [...], folder: [...] } every icon in the theme
getAssociations("vsi"); // { fileNames, extensions, folderNames } every name with a specific icon

Custom Associations and Icons

Layer your own names and SVGs on top of a theme. The built-in functions are not affected.

import { createIconResolver } from "@baybreezy/file-extension-icon";

const icons = createIconResolver({
  theme: "material",
  extensions: { tpl: "html" }, // map to an existing icon
  fileNames: { "acme.config": "acme" }, // map to a custom icon
  fileIcons: { acme: "<svg ...>...</svg>" },
  folderNames: { infra: "folder-server" },
  folderIcons: { "my-folder": { closed: "<svg ...>", open: "<svg ...>" } },
});

icons.getFileIcon("page.tpl");
icons.getFolderIcon("infra", { open: true });

Per-theme versions are available too: createMaterialIconResolver() and createVSIIconResolver().

React and Vue Components

react (17+) and vue (3.3+) are optional peer dependencies; install whichever you use.

import { FileIcon, FolderIcon } from "@baybreezy/file-extension-icon/react";

<FileIcon name="index.ts" />
<FileIcon name="package.json" theme="vsi" size={24} alt="package.json" className="icon" />
<FolderIcon name="src" open={isExpanded} />
<script setup lang="ts">
import { FileIcon, FolderIcon } from "@baybreezy/file-extension-icon/vue";
</script>

<template>
  <FileIcon name="index.ts" />
  <FolderIcon name="src" :open="isExpanded" theme="vsi" :size="24" />
</template>

Both render an <img> (with alt="" by default, since the icon is usually decorative). Other attributes pass through to it.

Other Frameworks / HTML

<script type="module">
  import { getMaterialFileIcon } from "@baybreezy/file-extension-icon";

  const icon = getMaterialFileIcon("index.html");
  document.getElementById("icon").src = icon;
</script>

<img id="icon" alt="html" width="24" height="24" />

Advanced Usage

import { getMaterialFileIcon } from "@baybreezy/file-extension-icon";

// The package intelligently matches file names, most specific first
getMaterialFileIcon("app.component.ts"); // Matches Angular component
getMaterialFileIcon("test.spec.ts"); // Matches test file
getMaterialFileIcon("package.json"); // Matches package.json
getMaterialFileIcon("Dockerfile"); // Matches Docker

// Works with any file extension
getMaterialFileIcon("script.py");
getMaterialFileIcon("style.scss");
getMaterialFileIcon("README.md");

📚 API Reference

All icon functions return a base64 data URI unless you pass a format.

Theme-agnostic (root import only)

theme is "material" (default) or "vsi".

| Function | Returns | | ------------------------------------------------------------ | ---------------------------------------- | | getFileIcon(fileName, { theme?, format? }) | string | | getFolderIcon(folderName, { theme?, open?, format? }) | string | | getFileIconInfo(fileName, { theme? }) | IconInfo | | getFolderIconInfo(folderName, { theme?, open? }) | IconInfo | | getIconByName(iconName, { theme?, type?, open?, format? }) | string \| undefined | | getIconNames(theme?) | { file: string[]; folder: string[] } | | getAssociations(theme?) | { fileNames; extensions; folderNames } | | createIconResolver({ theme?, ...customizations }) | IconResolver |

Material Icons (/material or root)

| Function | Returns | | ------------------------------------------------------------- | --------------------- | | getMaterialFileIcon(fileName, { format? }?) | string | | getMaterialFolderIcon(folderName, open?) | string | | getMaterialFolderIcon(folderName, { open?, format? }) | string | | getMaterialFileIconInfo(fileName) | IconInfo | | getMaterialFolderIconInfo(folderName, open?) | IconInfo | | getMaterialIconByName(iconName, { type?, open?, format? }?) | string \| undefined | | getMaterialIconNames() | IconNames | | getMaterialAssociations() | IconAssociations | | createMaterialIconResolver(customizations?) | IconResolver |

VSCode Icons (/vsi or root)

The same functions with a VSI prefix: getVSIFileIcon, getVSIFolderIcon, getVSIFileIconInfo, getVSIFolderIconInfo, getVSIIconByName, getVSIIconNames, getVSIAssociations, createVSIIconResolver.

IconResolver

Returned by the create*IconResolver functions. Same behaviour as above, bound to one theme plus your customizations: getFileIcon, getFolderIcon, getFileIconInfo, getFolderIconInfo, getIconByName, getIconNames, getAssociations.

Types

IconTheme, IconFormat, IconOptions, FolderIconOptions, IconByNameOptions, IconInfo, IconNames, IconAssociations, IconCustomizations, IconResolver, plus the key types MaterialFileExtensionKeys, MaterialFileNameKeys, MaterialFolderNameKeys, VSIFileExtensionKeys, VSIFileNameKeys, VSIFolderNameKeys.

Utility Functions

import {
  convertToBase64,
  createDataUri, // createDataUri(svg, "base64" | "utf8")
  findIconInCollection,
  getIconFromMap,
} from "@baybreezy/file-extension-icon";

🖥️ CLI Tool

This package includes a CLI for browsing and exporting icons, interactively or from scripts.

# Run interactively
npx file-icon

# Or with flags for quick export
npx file-icon -t material -y file -n "index.js" --copy

# Save a raw SVG
npx file-icon -n package.json -o package.svg

# Print to stdout for piping (no prompts)
npx file-icon -y folder -n src --open -p -f utf8

# JSON with match details
npx file-icon -n Dockerfile --json

CLI Features

  • 🎨 Browse Material and VSCode icon themes
  • 🔍 Enter any file/folder name or path, or autocomplete over every known name
  • 📋 Copy to clipboard, save to file (.svg or .txt), or display in terminal
  • 🧾 base64, URL-encoded or raw SVG output
  • 🤖 --print and --json for scripts
  • ⚡ Fast and beautiful UI powered by Clack

📖 Full CLI Documentation

📊 Bundle Size

This package contains comprehensive icon data for both Material and VSCode icon themes.

  • Package size (compressed): ~2.7 MB
  • Unpacked size: ~8.9 MB (ESM and CommonJS builds)
  • Includes: Thousands of file and folder icons

| Import | Icon data loaded | | ----------------------------------------- | ---------------- | | @baybreezy/file-extension-icon | ~4.2 MB (both) | | @baybreezy/file-extension-icon/material | ~0.9 MB | | @baybreezy/file-extension-icon/vsi | ~3.2 MB |

Optimization Tips

  1. Import only the theme you use from /material or /vsi (see Load Only One Theme).

  2. Import only what you need:

    // ✅ Good - Tree-shakeable
    import { getMaterialFileIcon } from "@baybreezy/file-extension-icon";
    // ❌ Avoid - Imports everything
    import * as Icons from "@baybreezy/file-extension-icon";
  3. Use modern bundlers with tree-shaking support (Vite, Rollup, esbuild, webpack 5+). The package is marked "sideEffects": false.

🛠️ Development

# Install dependencies
npm install

# Build the package
npm run build

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in UI mode
npm run test:ui

# Type check
npm run typecheck

# Lint code
npm run lint

# Regenerate the icon data from the latest upstream themes
npm run sync:icons

Updating the Icon Data

npm run sync:icons downloads the latest material-icon-theme package and vscode-icons release and regenerates src/data. By default it merges: existing names are never removed, so the exported key types never lose members. Options: --material <version>, --vsi <version>, --only material|vsi, --replace (upstream data only, may remove names), --dry-run, --summary <file.md>.

The Sync Icon Data GitHub workflow runs this monthly (or on demand) and opens a pull request with a summary for review.

🧪 Testing

This package includes comprehensive test coverage:

# Run tests in watch mode
npm test

# Generate coverage report
npm run test:coverage

# Open test UI
npm run test:ui

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT © Behon Baker

🙏 Credits & Acknowledgments

This package is a complete TypeScript rewrite of file-extension-icon-js by MD. Minhazul Islam.

Original Package

Icon Sources

Inspiration

  • vscode-icons-js by Dominik Dereǰanik (the language-to-extension table in scripts/language-extensions.json comes from its data, MIT)
  • file-icons-js by Web Semantics

🔗 Links