Modern, lightweight package for folder and file extension specific Material icons and VSCode icons
npm install @baybreezy/file-extension-icon> 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.



- π¨ 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
``bash`@antfu/ni
npx ni @baybreezy/file-extension-icon
`ts
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);
`
#### React / Vue / Svelte
`tsx
import { getMaterialFileIcon } from "@baybreezy/file-extension-icon";
function FileIcon({ fileName }: { fileName: string }) {
const icon = getMaterialFileIcon(fileName);
return ;
}
`
#### HTML
`html
`
`ts
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");
`
#### 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:
`typescript`
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 nameopen
- (boolean, optional): Whether to return the open folder icon. Default: false
Returns: Base64-encoded data URI string
Example:
`typescript`
const closedIcon = getMaterialFolderIcon("components");
const openIcon = getMaterialFolderIcon("components", true);
#### 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 nameopen
- (boolean, optional): Whether to return the open folder icon. Default: false
Returns: Base64-encoded data URI string
The package also exports utility functions for advanced use cases:
`typescript`
import {
convertToBase64,
createDataUri,
findIconInCollection,
getIconFromMap,
} from "@baybreezy/file-extension-icon";
This package includes an interactive CLI tool for browsing and exporting icons!
`bashRun interactively
npx file-icon
$3
- π¨ 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
π 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.
$3
1. Import only what you need:
`typescript
// β
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
`bash
Install dependencies
npm installBuild the package
npm run buildRun tests
npm testRun tests with coverage
npm run test:coverageRun tests in UI mode
npm run test:uiType check
npm run typecheckLint code
npm run lint
`π§ͺ Testing
This package includes comprehensive test coverage:
`bash
Run tests in watch mode
npm testGenerate coverage report
npm run test:coverageOpen test UI
npm run test:ui
`π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
π License
MIT Β© Behon Baker
π Credits & Acknowledgments
file-extension-icon-js` by MD. Minhazul Islam.- Original Author: MD. Minhazul Islam
- Original Package: file-extension-icon-js
- License: MIT
- Material Icon Theme by Philipp Kief
- VSCode Icons by VSCode Icons Team
- vscode-icons-js by Dominik DereΗ°anik
- file-icons-js by Web Semantics
- GitHub Repository
- npm Package
- Issue Tracker
- Author Website
---
Made with β€οΈ by Behon Baker