Documentation / v1.9.0
Small API.
Clear contracts.
Constants and helpers for the MIME work application code does every day. Typed, dependency-free, and deliberately curated.
Get started
Installation
Install with any current JavaScript package manager. Node.js 20 or newer is supported.
npm install mime-types-liteGet started
Quick start
Import only the surface you need, or use the immutable MIME object for dynamic access.
import { MIME, fromExtension, matchesMimeType } from 'mime-types-lite';
MIME.JSON; // 'application/json'
fromExtension('reports/annual.pdf'); // 'application/pdf'
matchesMimeType('image/png', 'image/*'); // trueConstants
Constants
Import tree-shakeable named constants, use the immutable MIME object, or keep the backward-compatible default export.
import mimeTypesLite, { JSON, MIME } from 'mime-types-lite';
JSON; // 'application/json'
MIME.PDF; // 'application/pdf'
mimeTypesLite.PNG; // 'image/png'Lookup
fromExtension
Find a curated media type from an extension, filename, Windows path, or URL. Query strings and fragments are ignored.
fromExtension('.json');
// 'application/json'
fromExtension('C:\files\photo.JPEG');
// 'image/jpeg'
fromExtension('https://example.com/app.js?v=2');
// 'text/javascript'Lookup uses the filename only. It does not inspect file bytes.
Lookup
extensionsFor
Return every known extension for a media type without leading dots. Content-Type parameters are normalized first.
extensionsFor('image/jpeg');
// ['jpg', 'jpeg', 'jpe']
extensionsFor('text/html; charset=utf-8');
// ['html', 'htm']Validation
normalizeMimeType
Remove parameters, trim whitespace, lowercase the value, and validate MIME syntax. Invalid input returns undefined.
normalizeMimeType(' Application/JSON; charset=utf-8 ');
// 'application/json'
normalizeMimeType('not a MIME type');
// undefinedValidation
Validation helpers
Validate syntax, check the curated set, or extract a recognized top-level media category.
isMimeType('application/problem+json'); // true
isKnownMimeType('application/json; charset=utf-8'); // true
mimeCategory('image/svg+xml'); // 'image'Validation
matchesMimeType
Match a Content-Type value against an exact media type, a category wildcard, or the universal wildcard.
matchesMimeType('image/avif', 'image/*'); // true
matchesMimeType('application/json; charset=utf-8', 'application/json'); // true
matchesMimeType('text/plain', 'image/*'); // falseThis helper does not parse weighted HTTP Accept headers.
Types
TypeScript types
Literal unions provide precise types for keys, known values, extensions, categories, and patterns.
import type {
KnownExtension,
MimeCategory,
MimeType,
MimeTypeKey,
MimeTypePattern,
MimeTypeString,
} from 'mime-types-lite';Guides
Standards & legacy values
Preferred constants follow current registrations and specifications. Historic values remain available through LEGACY_MIME.
text/javascriptapplication/javascriptapplication/yamlapplication/x-yamlimage/vnd.microsoft.iconimage/x-iconapplication/graphql-response+jsonapplication/graphqlGuides
Security boundary
A filename extension, browser File.type, or HTTP Content-Type header can be attacker-controlled.
For untrusted uploads, also inspect file signatures, enforce size limits, store files safely, and process them with hardened tooling.
Read the security policy