{"id":11325,"library":"mime-lite","title":"MIME Type Utilities (Lite)","description":"mime-lite provides a lightweight, standard set of MIME type mappings for JavaScript applications, suitable for both Node.js and browser environments. The current stable version is 1.0.3, with a release cadence that appears to be low but active, incorporating updates for new MIME types as needed (e.g., adding 'xls' in v1.0.3). Its key differentiator is being a 'lite' version, implying a smaller bundle size and a focused set of standard MIME type definitions compared to larger, more comprehensive libraries like the original `mime` package, from which it acknowledges copying its data. This makes it an efficient choice for projects where minimizing footprint is critical. It ships with TypeScript types, enhancing developer experience and type safety.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/pactumjs/mime-lite","tags":["javascript","mime","lite","typescript"],"install":[{"cmd":"npm install mime-lite","lang":"bash","label":"npm"},{"cmd":"yarn add mime-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add mime-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For retrieving the MIME type from a file extension or path segment. Prefer ESM `import`.","wrong":"const getType = require('mime-lite').getType;","symbol":"getType","correct":"import { getType } from 'mime-lite';"},{"note":"For retrieving the common file extension associated with a given MIME type. Prefer ESM `import`.","wrong":"const getExtension = require('mime-lite').getExtension;","symbol":"getExtension","correct":"import { getExtension } from 'mime-lite';"},{"note":"While `mime-lite` primarily exports named utilities, you can import all exports as a namespace object. Avoid default imports as it's not the primary export pattern.","wrong":"import MimeLite from 'mime-lite';","symbol":"MimeLite","correct":"import * as MimeLite from 'mime-lite';"}],"quickstart":{"code":"import { getType, getExtension } from 'mime-lite';\n\n// Get MIME type from file extensions\nconst mimePdf = getType('document.pdf');\nconsole.log(`PDF MIME type: ${mimePdf}`); // Expected: application/pdf\n\nconst mimeJpeg = getType('image.jpeg');\nconsole.log(`JPEG MIME type: ${mimeJpeg}`); // Expected: image/jpeg\n\nconst mimeUnknown = getType('archive.xyz');\nconsole.log(`Unknown extension MIME type: ${mimeUnknown}`); // Expected: undefined or null\n\n// Get file extension from MIME types\nconst extHtml = getExtension('text/html');\nconsole.log(`HTML extension: ${extHtml}`); // Expected: html\n\nconst extJson = getExtension('application/json');\nconsole.log(`JSON extension: ${extJson}`); // Expected: json\n\nconst extUnsupported = getExtension('application/x-custom');\nconsole.log(`Unsupported MIME extension: ${extUnsupported}`); // Expected: undefined or null\n\n// Example: Basic file type validation\nfunction isCommonTextFile(fileName: string): boolean {\n  const mime = getType(fileName);\n  return ['text/plain', 'text/html', 'application/json', 'text/css', 'text/javascript'].includes(mime ?? '');\n}\n\nconsole.log(`'report.txt' is a common text file: ${isCommonTextFile('report.txt')}`);\nconsole.log(`'image.png' is a common text file: ${isCommonTextFile('image.png')}`);","lang":"typescript","description":"Demonstrates basic usage of `getType` and `getExtension` to determine MIME types from extensions and vice versa, including a simple validation example."},"warnings":[{"fix":"Consult `mime-lite` source or test specific types for support. For broader coverage, consider the full `mime` package or a more comprehensive registry.","message":"This library is explicitly a 'lite' version, which means it may not contain as comprehensive a list of MIME types as the original `mime` library (from which it was copied). Developers should verify if all necessary obscure or uncommon MIME types are supported.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Implement nullish coalescing (`??`) or conditional checks (`if (mimeType)`) when consuming the results of `getType` or `getExtension`.","message":"`mime-lite` typically returns `undefined` or `null` for unsupported file extensions or MIME types. Applications should always handle these cases explicitly to prevent runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use ESM `import { namedExport } from 'mime-lite';` for best compatibility and type support in modern projects. Ensure your `tsconfig.json` and build setup are configured for ESM.","message":"While the package ships with TypeScript types, incorrect import syntax (e.g., using CommonJS `require` directly with modern bundlers or incorrectly destructuring) can lead to 'is not a function' errors or type inference issues.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use `import { getType } from 'mime-lite';` for ESM projects. If using CommonJS, try `const { getType } = require('mime-lite');` or ensure your transpiler correctly handles interop.","cause":"Incorrect CommonJS `require` syntax being used for a package primarily designed for named ESM exports, or incorrect destructuring in a mixed environment.","error":"TypeError: (0, _mime_lite.getType) is not a function"},{"fix":"Ensure the package is installed: `npm install mime-lite` or `yarn add mime-lite`. If types are missing, explicitly install `@types/mime-lite` if available, though `mime-lite` ships its own types.","cause":"The `mime-lite` package is not installed, or TypeScript cannot locate its declaration files.","error":"Cannot find module 'mime-lite' or its corresponding type declarations."}],"ecosystem":"npm"}