Skip to content

content-types-lite

A small, type-safe TypeScript library of HTTP media type constants and helpers for parsing, formatting, matching, and validating Content-Type values.

Role
Library design and package engineering
Scope
Typed APIs, compatibility, and package distribution
Status
Published npm package

Problem

Applications keep reimplementing Content-Type parsing and negotiation, and each version handles edge cases slightly differently. The usual alternative is importing a larger dependency tree for what is a focused HTTP-header task.

Constraints

  1. C1

    Quoted parameters and malformed header values must parse predictably.

  2. C2

    The package output must work for both ESM and CommonJS consumers.

  3. C3

    The public API must stay small and type-safe with no runtime dependencies.

Architecture

The core is a pure TypeScript library with its own tests, built into dual ESM and CommonJS outputs with typed exports. A React documentation and playground app in the same workspace consumes the local package, so the docs always run the current code.

01

Core library

Pure TypeScript functions parse, format, match, and validate media types, backed by tests.

02

Package builds

The tsup build produces dual ESM and CommonJS outputs with typed package exports.

03

Documentation app

A workspace-linked React documentation and playground app consumes the local package rather than a published release.

Decisions

D1

Keep runtime dependencies at zero

A dependency-free package stays small and easy to audit. The cost is leaving out broad convenience helpers in favor of a focused surface.

D2

Ship dual module formats with typed exports

ESM and CommonJS consumers get the same API and type declarations without configuring interop themselves.

D3

Colocate the docs playground and package

The docs app depends on workspace:*, so every app build exercises the current implementation instead of an older published version.

Contribution

  • Implemented media-type parsing, formatting, and parameter handling.
  • Added content negotiation and validation helpers with type declarations.
  • Configured tsup, package exports, and release gates.
  • Built searchable interactive docs and examples against the workspace:* package.

Outcomes

  • Consumers can parse and serialize Content-Type values.
  • Consumers can validate and compare media types.
  • The package works from both ESM and CommonJS.
  • Developers can test behavior interactively in the documentation app.

Product screenshot

content-types-lite documentation home page with the headline 'HTTP content types, handled correctly' and a parsing example
The documentation site exercises the published package directly, from install command to live parsing examples.

Verified stack

  • TypeScript
  • ESM
  • CommonJS
  • tsup
  • TanStack Start
  • React
  • Tailwind CSS
  • Vite
  • Vitest
  • Netlify
  • GitHub Actions
  • CI/CD

Working through something similar?

Share your challenge, scope, and timeline to start a focused conversation.