@baybreezy/file-extension-icon

中文文档
0.0.5发布于 2026/05/04MITTypeScriptESM + CJS零依赖近 30 天下载 1867

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

原始使用文档
文档目录23 节
  1. ✨ Features
  2. 📦 Installation
  3. 🚀 Usage
  4. Basic Usage
  5. Framework Examples
  6. Advanced Usage
  7. 📚 API Reference
  8. Material Icons
  9. VSCode Icons
  10. Utility Functions
  11. 🖥️ CLI Tool
  12. CLI Features
  13. 📊 Bundle Size
  14. Optimization Tips
  15. 🛠️ Development
  16. 🧪 Testing
  17. 🤝 Contributing
  18. 📄 License
  19. 🙏 Credits & Acknowledgments
  20. Original Package
  21. Icon Sources
  22. Inspiration
  23. 🔗 Links

@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: Only bundle what you use
  • 🔄 Dual format: ESM and CommonJS support
  • 🚀 Modern build: Built with Unbuild for optimal output
  • ✅ Well-tested: Comprehensive test coverage
  • 📝 Well-documented: Full JSDoc comments and examples
  • 🖥️ CLI included: Interactive 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);

Framework Examples

React / Vue / Svelte

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

function FileIcon({ fileName }: { fileName: string }) {
  const icon = getMaterialFileIcon(fileName);

  return <img src={icon} alt={fileName} width={24} height={24} />;
}

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 {
  convertToBase64,
  createDataUri,
  findIconInCollection,
  getIconFromMap,
  getMaterialFileIcon,
} from "@baybreezy/file-extension-icon";

// The package intelligently matches file names
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

Material Icons

getMaterialFileIcon(fileName: string): string

Returns a base64-encoded SVG data URI for the given file name using the Material Icon theme.

Parameters:

  • fileName (string): The file name with or without path (e.g., "index.js", "src/app.ts")

Returns: Base64-encoded data URI string

Example:

const icon = getMaterialFileIcon("index.js");
// => "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0..."

getMaterialFolderIcon(folderName: string, open?: boolean): string

Returns a base64-encoded SVG data URI for the given folder name using the Material Icon theme.

Parameters:

  • folderName (string): The folder name
  • open (boolean, optional): Whether to return the open folder icon. Default: false

Returns: Base64-encoded data URI string

Example:

const closedIcon = getMaterialFolderIcon("components");
const openIcon = getMaterialFolderIcon("components", true);

VSCode Icons

getVSIFileIcon(fileName: string): string

Returns a base64-encoded SVG data URI for the given file name using the VSCode Icon theme.

Parameters:

  • fileName (string): The file name with or without path

Returns: Base64-encoded data URI string

getVSIFolderIcon(folderName: string, open?: boolean): string

Returns a base64-encoded SVG data URI for the given folder name using the VSCode Icon theme.

Parameters:

  • folderName (string): The folder name
  • open (boolean, optional): Whether to return the open folder icon. Default: false

Returns: Base64-encoded data URI string

Utility Functions

The package also exports utility functions for advanced use cases:

import {
  convertToBase64,
  createDataUri,
  findIconInCollection,
  getIconFromMap,
} from "@baybreezy/file-extension-icon";

🖥️ CLI Tool

This package includes an interactive CLI tool for browsing and exporting icons!

# Run interactively
npx file-icon

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

CLI Features

  • 🎨 Browse Material and VSCode icon themes
  • 🔍 Search by file/folder name or browse all icons
  • 📋 Copy to clipboard, save to file, or display in terminal
  • ⚡ 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.6 MB
  • Unpacked size: ~8.6 MB
  • Includes: Thousands of file and folder icons

Note: Modern bundlers with tree-shaking can significantly reduce the final bundle size by including only the icons you use. Ensure your bundler is configured for tree-shaking to optimize bundle size.

Optimization Tips

  1. 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";
    
  2. Use modern bundlers with tree-shaking support (Vite, Rollup, esbuild, webpack 5+)

  3. Consider code splitting if you support multiple icon themes

🛠️ 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

🧪 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


Made with ❤️ by Behon Baker

版本与发布记录

@baybreezy/file-extension-icon 共发布 4 个版本,首次发布于 2025/10/16;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.0.5latest2026/05/046 个月前
0.0.42025/11/2011 个月前
0.0.32025/11/1611 个月前
0.0.22025/10/161.1 年前

关于 @baybreezy/file-extension-icon 的常见问题

@baybreezy/file-extension-icon 是什么?

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

如何安装 @baybreezy/file-extension-icon?

在项目目录运行 npm install @baybreezy/file-extension-icon,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 file-icon,可以用 npx file-icon 直接运行。

@baybreezy/file-extension-icon 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@baybreezy/file-extension-icon 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@baybreezy/file-extension-icon 可以商用吗?

@baybreezy/file-extension-icon 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@baybreezy/file-extension-icon 的下载量有多少?

根据 npm 官方下载统计,@baybreezy/file-extension-icon 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,867 次,日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@baybreezy/file-extension-icon 还在维护吗?

最新版本 0.0.5 发布于 2026/05/04(6 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/10/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。