Skip to content
content-types-lite
Type-safe HTTP utilities

HTTP content types, handled correctly.

Tiny, type-safe media type constants and focused utilities for parsing, formatting, matching, and validating Content-Type headers.

npm install content-types-lite
response.headersVALID

RAW HEADER

application/problem+json;charset="utf-8"

MEDIA TYPE

application/problem+json

PARAMETERS

charset: utf-8
JSON-likeTextualparsed safely
0runtime dependencies
ESM + CJSmodern and established runtimes
Literal typesautocomplete included
Subpath exportstree-shakeable modules

Small surface.
Serious header work.

Keep common cases effortless and edge cases explicit. Each strict, side-effect-free utility is also available through a focused subpath export.

/parse

Parse without surprises

Normalize casing, read parameters, and return null for malformed or duplicate values.

parseContentType(header)

/format

Format safely

Quote parameter values correctly and reject control characters before they reach a header.

formatContentType(type, params)

/match

Match useful ranges

Handle exact values, image/* wildcards, and structured suffix patterns such as *+json.

matchesMediaType(value, pattern)

/guards

Narrow with confidence

Detect JSON-like, XML-like, textual, image, audio, and video content types.

isJsonLike(contentType)

Quick start

One import.
Correct headers.

Named constants preserve their literal TypeScript types. The frozen default export keeps existing 1.x code working.

Read the documentation
response.ts
import { JSON, withCharset } from 'content-types-lite'

const headers = {
  'Content-Type': withCharset(JSON),
}

// 'application/json; charset=utf-8'

Make the header boring again.

Use the tiny utility that handles the sharp edges for you.

Try the playground