{"library":"mime-types","title":"MIME Type Utility","description":"mime-types is a JavaScript utility library for working with content-types, offering functions to look up MIME types, file extensions, and associated charsets. Currently at stable version `3.0.2`, the package primarily focuses on providing accurate MIME type data sourced from `mime-db`. It differentiates itself from older `mime` modules by explicitly returning `false` for unknown types (rather than a naive fallback), avoiding instance creation (`new Mime()`), and omitting `.define()` functionality. While its core API remains compatible with `mime@1.x`, it's maintained by the `jshttp` organization and generally receives updates driven by new MIME types or minor fixes rather than frequent new features. A key aspect is its `mime-db` dependency; programmatic API changes are considered semver, but updates to the underlying MIME type data itself are not, meaning users needing strict data versioning must manage `mime-db` via package manager overrides.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mime-types"],"cli":null},"imports":["import mime from 'mime-types';","const mime = require('mime-types');","import mime from 'mime-types';\nconst type = mime.lookup('index.html');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import mime from 'mime-types';\nimport path from 'path';\n\n// Look up a MIME type by file extension or path\nconst jsonType = mime.lookup('json');\nconsole.log(`JSON type: ${jsonType}`); // Expected: application/json\n\nconst markdownType = mime.lookup('.md');\nconsole.log(`Markdown type: ${markdownType}`); // Expected: text/markdown\n\nconst filePath = '/path/to/document.pdf';\nconst fileType = mime.lookup(filePath);\nconsole.log(`File type for '${filePath}': ${fileType}`); // Expected: application/pdf\n\n// Handle unknown types (returns false)\nconst unknownType = mime.lookup('unrecognized');\nconst fallbackType = unknownType || 'application/octet-stream';\nconsole.log(`Unknown type lookup: ${fallbackType}`); // Expected: application/octet-stream\n\n// Create a full Content-Type header\nconst htmlContentType = mime.contentType('text/html');\nconsole.log(`HTML Content-Type: ${htmlContentType}`); // Expected: text/html; charset=utf-8\n\nconst jsContentType = mime.contentType(path.extname('app.js'));\nconsole.log(`JS Content-Type: ${jsContentType}`); // Expected: application/javascript; charset=utf-8\n\n// Get default extension for a MIME type\nconst binExtension = mime.extension('application/octet-stream');\nconsole.log(`Extension for octet-stream: ${binExtension}`); // Expected: bin\n\n// Lookup implied default charset\nconst textCharset = mime.charset('text/plain');\nconsole.log(`Charset for text/plain: ${textCharset}`); // Expected: UTF-8\n","lang":"typescript","description":"Demonstrates core `mime-types` functionalities: `lookup` for MIME types, `contentType` for full headers, `extension` for default extensions, and `charset` for implied charsets, including handling unknown types.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}