Skip to content

A lightweight TypeScript/JavaScript library for handling common web MIME types. The MIME type definitions are sourced from MDN Web Docs - Common MIME Types.

License

Notifications You must be signed in to change notification settings

lbb00/common-mime-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Common MIME Types

Npm Bundlephobia Coverage Typescript License Npm download

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, getType, getSubType } 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'

// Get the type part of a MIME type
const type = getType('image/png') // Returns 'image'

// Get the subtype part of a MIME type
const subType = getSubType('image/png') // Returns 'png'

// Search in mimeTypes array
mimeTypes.find((m) => m.mime === 'image/png')?.ext
mimeTypes.find((m) => m.ext === '.png')?.mime

About

A lightweight TypeScript/JavaScript library for handling common web MIME types. The MIME type definitions are sourced from MDN Web Docs - Common MIME Types.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published