Registry / serialization / mrmime

mrmime

JSON →
library0.0.1jsnpmunverified

mrmime is a minimalist and high-performance utility designed to retrieve MIME types from file extensions or filenames. Currently at version 2.0.1, it offers a small footprint (2.8kB gzipped) and O(1) lookup times, making it significantly faster than alternatives like `mime` or `mime/lite` as demonstrated in its benchmarks. The library's comprehensive dictionary is generated from `mime-db`, which aggregates IANA, NGINX, and Apache datasets, ensuring accuracy for standard MIME types while intentionally omitting experimental and vendor-specific entries to maintain its lightweight nature. It supports both native ESM and CommonJS environments, including Deno, and allows for dictionary customization. The project maintains an active release cadence, primarily syncing with `mime-db` updates and addressing minor breaking changes between major versions.

npm install mrmime
INSTALL
IMPORT
SIG · MRMIME
M
mrmime
serializationjavascriptv0.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lookup
import { lookup } from 'mrmime';
const lookup = require('mrmime').lookup;
Primarily designed for ESM. While CommonJS works, named imports are preferred.
mimes
import { mimes } from 'mrmime';
const mimes = require('mrmime').mimes;
The `mimes` object allows for runtime additions or overrides of MIME types and is mutable.
mrmime (CommonJS destructuring)
const { lookup, mimes } = require('mrmime');
For CommonJS environments, destructuring the require call is the idiomatic way to access named exports.

Demonstrates how to lookup MIME types for various inputs, handle unknown extensions, and dynamically customize the internal MIME dictionary.

import { lookup, mimes } from 'mrmime'; // Get a MIME type from an extension or filename console.log(lookup('txt')); // => "text/plain" console.log(lookup('.txt')); // => "text/plain" console.log(lookup('a.txt')); // => "text/plain" console.log(lookup('index.html')); // => "text/html" // Handle unknown extensions (returns undefined since v2.0.0) console.log(lookup('.xyz')); // => undefined // Customize the MIME dictionary by adding a new type mimes['xyz'] = 'hello/world'; console.log(lookup('xyz')); // => "hello/world" // Example with a common file type check const filename = 'document.pdf'; const mimeType = lookup(filename); if (mimeType) { console.log(`The MIME type for '${filename}' is: ${mimeType}`); } else { console.log(`Could not determine MIME type for '${filename}'.`); }
Debug
Known issues
breakingThe `lookup` function's return signature changed from `string | void` to `string | undefined` in v2.0.0. This aligns with TypeScript's `undefined` type for missing values.
fix
Update type assertions or nullish coalescing logic to explicitly check for `undefined` instead of `void`.
affects: >=2.0.0
breakingUpgrading to `mrmime` v2.0.0 includes an updated `mime-db` version, which resulted in changes to some extension-to-MIME-type mappings. Specifically, the `es` extension was removed, and others like `asc` had their values changed. Review the full changelog for details.
fix
Verify that expected MIME types for specific extensions are still correct after upgrading. If a previously recognized type is now `undefined` or changed, update application logic or manually add/override the type in the `mimes` dictionary.
affects: >=2.0.0
gotchaIn `mrmime` versions up to `v1.0.0`, TypeScript 4.7+ environments might not correctly discover the type definitions. This was fixed in `v1.0.1` by adding the 'types' export condition.
fix
Upgrade to `mrmime` v1.0.1 or newer to ensure correct TypeScript type discovery.
affects: <=1.0.0
Errors
Common errors & fixes
TypeError: (0 , mrmime_1.lookup) is not a function
Attempting to use CommonJS `require` with named imports incorrectly in an environment expecting ES modules, or vice-versa.
fix
If using `require`, use `const { lookup } = require('mrmime');`. If in an ES module environment, ensure `import { lookup } from 'mrmime';` is used and the file is treated as an ES module (e.g., `.mjs` extension or `type: 'module'` in `package.json`).
MIME type not found for '.xyz'
Looking up an extension that is not present in `mrmime`'s internal dictionary, which will result in `lookup` returning `undefined`.
fix
Recognize that `lookup` returns `undefined` for unknown extensions. If the extension is valid for your application, add it to the `mimes` dictionary: `mimes['xyz'] = 'your/custom-type';`.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mrmime — npm install mrmime · libregistry