{"library":"mime-format","title":"MIME Format Lookup","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install mime-format"],"cli":null},"imports":["import mimeFormat from 'mime-format';","const mimeFormat = require('mime-format');","import mimeFormat from 'mime-format'; mimeFormat.lookup('application/json');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const mimeFormat = require('mime-format');\n\n// Look up a common XML content type with charset\nconst xmlResult = mimeFormat.lookup('application/xml; charset=gBk');\nconsole.log('XML result:', xmlResult);\n/*\nOutput:\n{\n  \"type\": \"text\",\n  \"format\": \"xml\",\n  \"charset\": \"gBk\"\n}\n*/\n\n// Example for a JSON content type, which it classifies as 'text'\nconst jsonResult = mimeFormat.lookup('application/json');\nconsole.log('JSON result:', jsonResult);\n/*\nOutput:\n{\n  \"type\": \"text\",\n  \"format\": \"json\"\n}\n*/\n\n// Example for an unknown content type, demonstrating 'guessed' or 'unknown'\nconst unknownResult = mimeFormat.lookup('application/x-custom-format');\nconsole.log('Unknown result:', unknownResult);\n/*\nOutput (may vary slightly based on internal logic):\n{\n  \"type\": \"application\",\n  \"format\": \"raw\",\n  \"guessed\": true\n}\n*/","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}