Skip to content
Library design

Filename-to-MIME Lookup Is Useful—Until You Mistake It for Validation

A small, zero-dependency TypeScript library of MIME constants and helpers for HTTP APIs, uploads, and file extensions.

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

Why it was needed

Upload, download, and HTTP code needs dependable mappings between filenames or extensions and media types. Carrying a broad MIME database into every bundle for that job adds weight most applications do not need.

One extension can have aliases or ambiguous mappings. Lookup must normalize case, dots, and paths without implying that file content was inspected. ESM and CommonJS consumers need stable typed exports with no runtime dependencies.

How it is built

A curated media-type registry backs pure lookup and validation functions, which are built with tsup into a dual-format package with typed exports. A TanStack Start docs and playground app in the same workspace runs against the local package.

Keep the scope narrow and dependency-free. A curated registry and a small set of helpers cover common upload and HTTP needs without a broad database dependency, at the cost of not covering every registered type.

Treat extension lookup as metadata, not security. A filename only suggests a media type. The library never inspects file bytes, so callers should not mistake a lookup for content validation.

Test the local package from the docs app. The documentation app runs the exact package that will be released, so examples and behavior are checked against the real build before publishing.

The key decision: Keep the scope narrow and dependency-free.

What changed

Implemented extension-to-type and type-to-extension lookups. Added normalization and validation helpers. Configured typed ESM and CommonJS publishing. Built interactive docs, examples, tests, CI, and Netlify deployment.

Consumers can infer common media types from filenames. Consumers can recover the preferred extension for a media type. Media-type inputs can be validated and normalized before use. The same API works in browser and Node.js module systems.

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.