{"id":11783,"library":"react-native-mime-types","title":"MIME Types Utility for React Native","description":"react-native-mime-types is a focused utility for identifying and managing MIME (Multipurpose Internet Mail Extensions) types within React Native applications. It provides core functions like `lookup` to determine content types from file extensions or paths, `contentType` to construct full Content-Type headers, and `extension` to find the default file extension for a given MIME type. Unlike the general-purpose `node-mime` library, this package explicitly returns `false` for unknown types instead of providing naive fallbacks, requiring developers to implement their own fallback logic. It operates purely functionally, eschewing `new Mime()` constructors or a `.define()` API for adding custom types; all type definitions are sourced from the comprehensive `mime-db` project. The current stable version is 2.5.0, and it receives updates as needed, often reflecting changes in `mime-db`. Its primary differentiator is its simplicity and explicit behavior regarding unknown types, making it predictable for React Native environments.","status":"active","version":"2.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/Liroo/react-native-mime-types","tags":["javascript","mime","types","typescript"],"install":[{"cmd":"npm install react-native-mime-types","lang":"bash","label":"npm"},{"cmd":"yarn add react-native-mime-types","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-native-mime-types","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a namespace object, not a default export. Access functions via `mime.lookup`, `mime.contentType`, etc.","wrong":"import mime from 'react-native-mime-types';","symbol":"mime","correct":"import * as mime from 'react-native-mime-types';"},{"note":"For CommonJS environments, the entire API is exposed as properties of the `mime` object.","wrong":"const { lookup, contentType } = require('react-native-mime-types');","symbol":"mime","correct":"const mime = require('react-native-mime-types');"},{"note":"Functions like `lookup` and `contentType` are properties of the main `mime` object and are not directly named exports.","wrong":"import { lookup } from 'react-native-mime-types';\nlookup('file.json');","symbol":"mime.lookup","correct":"import * as mime from 'react-native-mime-types';\nmime.lookup('file.json');"}],"quickstart":{"code":"import * as mime from 'react-native-mime-types';\n\nconsole.log('--- MIME Type Lookups ---');\nconsole.log('JSON file type:', mime.lookup('json')); // 'application/json'\nconsole.log('Markdown file type:', mime.lookup('.md')); // 'text/x-markdown'\nconsole.log('HTML file type:', mime.lookup('file.html')); // 'text/html'\nconsole.log('JavaScript file type:', mime.lookup('folder/file.js')); // 'application/javascript'\nconsole.log('Unrecognized file type (should be false):', mime.lookup('cats')); // false\n\nconsole.log('\\n--- Content-Type Header Creation ---');\nconsole.log('Markdown content type header:', mime.contentType('markdown')); // 'text/x-markdown; charset=utf-8'\nconsole.log('JSON content type header:', mime.contentType('file.json')); // 'application/json; charset=utf-8'\n\nconsole.log('\\n--- Extension Lookup ---');\nconsole.log('Extension for octet-stream:', mime.extension('application/octet-stream')); // 'bin'\n\nconsole.log('\\n--- Direct Maps ---');\nconsole.log('Type for .txt:', mime.types['txt']); // 'text/plain'\nconsole.log('Extensions for text/html:', mime.extensions['text/html']); // ['html', 'htm']","lang":"typescript","description":"Demonstrates common MIME type lookups by extension or path, content-type header generation, extension retrieval, and direct map access, including handling unrecognized types."},"warnings":[{"fix":"Implement custom fallback logic: `const type = mime.lookup(path) || 'application/octet-stream';`","message":"Unlike some MIME libraries (e.g., node-mime), `react-native-mime-types` returns `false` for unrecognized or invalid input, rather than providing a default fallback like 'application/octet-stream'. You must explicitly handle `false` returns.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"All functions are accessed directly from the imported `mime` object (e.g., `mime.lookup()`).","message":"The library does not expose a constructor; do not attempt to use `new mime()` or `new Mime()` patterns. It's a purely functional API.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"To add new or custom MIME types, contribute them to the `mime-db` project, or manage a separate, custom mapping within your application code.","message":"`react-native-mime-types` does not provide a `.define()` method to add custom MIME types at runtime. All type definitions are based on `mime-db`.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'2.5.0':129 'ad':109 'api':107 'applic':29 'behavior':151 'chang':138 'comprehens':119 'construct':47 'constructor':103 'content':38,50 'content-typ':49 'contenttyp':45 'core':32 'current':125 'custom':110 'db':122,142 'default':58 'defin':106 'definit':114 'determin':37 'develop':89 'differenti':145 'environ':161 'eschew':100 'explicit':77,150 'extens':24,42,54,60 'fallback':87,94 'fals':79 'file':41,59 'find':56 'focus':14 'full':48 'function':33,99 'general':69 'general-purpos':68 'given':63 'header':52 'identifi':17 'implement':91 'instead':83 'internet':22 'javascript':162 'librari':74 'like':34 'logic':95 'lookup':35 'mail':23 'make':155 'manag':19 'mime':1,10,20,64,73,102,121,141,163 'mime-db':120,140 'multipurpos':21 'naiv':86 'nativ':6,9,28,160 'need':135 'new':101 'node':72 'node-mim':71 'often':136 'oper':97 'packag':76 'path':44 'predict':157 'primari':144 'project':123 'provid':31,85 'pure':98 'purpos':70 'react':5,8,27,159 'react-native-mime-typ':7 'receiv':132 'reflect':137 'regard':152 'requir':88 'return':78 'simplic':148 'sourc':116 'stabl':126 'type':2,11,25,39,51,65,82,111,113,154,164 'typescript':165 'unknown':81,153 'unlik':66 'updat':133 'util':3,15 'version':127 'within':26","created_at":"2026-04-19T13:39:46.844866+00:00","updated_at":"2026-04-19T13:39:46.844866+00:00","problems":[{"fix":"This library does not allow runtime definition of MIME types. Rely on `mime-db` for definitions or manage custom types manually.","cause":"Attempting to use a `.define()` method to add custom MIME types, which this library does not support.","error":"TypeError: mime.define is not a function"},{"fix":"Ensure the library is imported as a namespace object (ESM: `import * as mime from 'react-native-mime-types';`) or the full module object (CommonJS: `const mime = require('react-native-mime-types');`). All functions are properties of the `mime` object.","cause":"The `mime` object was not imported correctly, or an attempt was made to destructure named exports that do not exist.","error":"TypeError: Cannot read properties of undefined (reading 'lookup')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Liroo/react-native-mime-types","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/react-native-mime-types","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}