Skip to content
Library design

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

Tiny, zero-dependency, type-safe MIME constants and helpers for HTTP APIs, uploads, and file extensions.

Written by Montasim
2 min read

mime-types-lite interface preview

The visible feature was only the surface

Upload, download, and HTTP code needs dependable mappings between filenames/extensions and media types without carrying a broad database dependency into every bundle.

The system also had to respect concrete constraints. One extension can have aliases or ambiguous mappings. Lookup must normalize case/dots/paths without pretending file content was inspected. ESM/CommonJS consumers require stable typed exports with no runtime dependencies.

My role covered library design and package engineering, with responsibility for typed apis, compatibility, and package distribution.

I turned the constraints into boundaries

Curated media-type registry and pure lookup/validation functions; tsup dual-format package/exports; workspace-linked TanStack Start docs and playground.

Scope the registry/helpers narrowly and keep zero dependencies.

Treat extension lookup as metadata inference, not content security validation.

Exercise the exact local package from the documentation app before release.

The key decision: Scope the registry/helpers narrowly and keep zero dependencies.

The implementation had to prove the model

I delivered the work across the full path: Implemented extension-to-type and type-to-extension lookups. Added normalization and validation helpers. Configured typed ESM/CommonJS publishing. Built interactive docs, examples, tests, CI, and Netlify deployment.

The result is concrete: Consumers can infer common media types from filenames. Recover preferred extensions. Validate/normalize media-type inputs. Use the same API in browser/Node module systems.

The senior engineering lesson was that solving the visible workflow is only half the job. The architecture must also make constraints, failure modes, evidence, and ownership explicit enough for the next change to remain safe.

Working through a similar challenge?

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

Discussion

Join the conversation about this article

0 comments

Loading discussion

Fetching the latest comments.

Leave a reply

Respond to the article or continue the discussion.

Ctrl + Enter to post

Your email stays private. Comments are stored securely.