Skip to content
Library design

I Built a Smaller Content-Type Library by Refusing Feature Creep

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

Get content-types-lite on npm
2 min read0 comments
Website

Why it was needed

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.

Quoted parameters and malformed header values must parse predictably. The package output must work for both ESM and CommonJS consumers. The public API must stay small and type-safe with no runtime dependencies.

How it is built

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.

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.

Ship dual module formats with typed exports. ESM and CommonJS consumers get the same API and type declarations without configuring interop themselves.

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.

The key decision: Keep runtime dependencies at zero.

What changed

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.

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.

My role: Library design and package engineering. Scope: Typed APIs, compatibility, and package distribution.

Working through a similar challenge?

Share your context, constraints, and timeline to start a focused conversation.