common-mime-types
v1.0.0
Published
A lightweight TypeScript/JavaScript library for bidirectional conversion between file extensions and common web MIME types.
Downloads
119
Maintainers
Readme
Common MIME Types
A lightweight TypeScript/JavaScript library for handling common web MIME types. The MIME type definitions are sourced from MDN Web Docs - Common MIME Types.
Features
- 🎯 Includes most commonly used MIME types on the web
- 🔄 Bidirectional conversion between file extensions and MIME types
- 📦 Lightweight with zero dependencies
- 💪 Written in TypeScript with full type support
Usage
import { mimeTypes, mime2ext, ext2mime } from 'common-mime-types'
// Convert MIME type to file extension
const ext = mime2ext('image/png') // Returns '.png'
// Convert file extension to MIME type
const mimeType = ext2mime('.png') // Returns 'image/png'
// Search in mimeTypes array
mimeTypes.find((m) => m.mime === 'image/png')?.ext
mimeTypes.find((m) => m.ext === '.png')?.mime