/parse
Parse without surprises
Normalize casing, read parameters, and return null for malformed or duplicate values.
parseContentType(header)Tiny, type-safe media type constants and focused utilities for parsing, formatting, matching, and validating Content-Type headers.
npm install content-types-liteRAW HEADER
MEDIA TYPE
application/problem+jsonPARAMETERS
charset: utf-8Keep common cases effortless and edge cases explicit. Each strict, side-effect-free utility is also available through a focused subpath export.
/parse
Normalize casing, read parameters, and return null for malformed or duplicate values.
parseContentType(header)/format
Quote parameter values correctly and reject control characters before they reach a header.
formatContentType(type, params)/match
Handle exact values, image/* wildcards, and structured suffix patterns such as *+json.
matchesMediaType(value, pattern)/guards
Detect JSON-like, XML-like, textual, image, audio, and video content types.
isJsonLike(contentType)Quick start
Named constants preserve their literal TypeScript types. The frozen default export keeps existing 1.x code working.
Read the documentationimport { JSON, withCharset } from 'content-types-lite'
const headers = {
'Content-Type': withCharset(JSON),
}
// 'application/json; charset=utf-8'Use the tiny utility that handles the sharp edges for you.
Try the playground