The `mime-format` library provides a utility for disambiguating the base format of HTTP response bodies based on their `Content-Type` header. It aims to resolve ambiguities, especially between `text/*` and `application/*` types, by maintaining an internal database of textual content types served under `application/*` (e.g., `application/json` is classified as `text`). The current stable version is 2.0.2, with releases appearing to be on an as-needed basis, indicated by the significant gap between v0.2.0 and v2.0.0. Key differentiators include its explicit handling of `application/*` types that are textual in nature, and its ability to guess or mark content types as unknown if they are not in its database, providing granular control over content interpretation.
npm install mime-formatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `mime-format` to identify the base type, specific format, and charset from various `Content-Type` headers, including known types and those requiring guessing.
Consult the GitHub repository's commit history or `package.json` for details on API changes if migrating from pre-v1.0 or v1.x versions.
Always check the `guessed` and `unknown` flags in the returned object, and implement fallback logic for unlisted or custom content types.
Prioritize the `type` property for broad content categorization. Use `format` only when a specific textual syntax (like 'json', 'xml') is relevant and expected.
Ensure that the `contentType` argument passed to `mimeFormat.lookup()` is always a valid string representing an HTTP `Content-Type` header.
For CommonJS: `const mimeFormat = require('mime-format');`. For ESM: `import mimeFormat from 'mime-format';`. Then access the method as `mimeFormat.lookup(...)`.Either configure your Node.js project for ES modules by setting `"type": "module"` in `package.json` (and use `.mjs` or `.js` files), or switch to `require()` syntax: `const mimeFormat = require('mime-format');`.Double-check the exact `Content-Type` string being passed. If it's valid but not recognized, `mime-format` will resort to guessing or marking as unknown, which is its intended behavior for unlisted types. Consider contributing to the library's database for widely used missing types.
No dependency data recorded yet.