Registry / serialization / mime-lite

mime-lite

JSON →
library1.0.3jsnpmunverified

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.

npm install mime-lite
INSTALL
IMPORT
SIG · MIME-LITE
M
mime-lite
serializationjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getType
import { getType } from 'mime-lite';
const getType = require('mime-lite').getType;
For retrieving the MIME type from a file extension or path segment. Prefer ESM `import`.
getExtension
import { getExtension } from 'mime-lite';
const getExtension = require('mime-lite').getExtension;
For retrieving the common file extension associated with a given MIME type. Prefer ESM `import`.
MimeLite
import * as MimeLite from 'mime-lite';
import MimeLite from 'mime-lite';
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.

Demonstrates basic usage of `getType` and `getExtension` to determine MIME types from extensions and vice versa, including a simple validation example.

import { getType, getExtension } from 'mime-lite'; // Get MIME type from file extensions const mimePdf = getType('document.pdf'); console.log(`PDF MIME type: ${mimePdf}`); // Expected: application/pdf const mimeJpeg = getType('image.jpeg'); console.log(`JPEG MIME type: ${mimeJpeg}`); // Expected: image/jpeg const mimeUnknown = getType('archive.xyz'); console.log(`Unknown extension MIME type: ${mimeUnknown}`); // Expected: undefined or null // Get file extension from MIME types const extHtml = getExtension('text/html'); console.log(`HTML extension: ${extHtml}`); // Expected: html const extJson = getExtension('application/json'); console.log(`JSON extension: ${extJson}`); // Expected: json const extUnsupported = getExtension('application/x-custom'); console.log(`Unsupported MIME extension: ${extUnsupported}`); // Expected: undefined or null // Example: Basic file type validation function isCommonTextFile(fileName: string): boolean { const mime = getType(fileName); return ['text/plain', 'text/html', 'application/json', 'text/css', 'text/javascript'].includes(mime ?? ''); } console.log(`'report.txt' is a common text file: ${isCommonTextFile('report.txt')}`); console.log(`'image.png' is a common text file: ${isCommonTextFile('image.png')}`);
Debug
Known issues
gotchaThis 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.
fix
Consult `mime-lite` source or test specific types for support. For broader coverage, consider the full `mime` package or a more comprehensive registry.
affects: >=1.0.0
gotcha`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.
fix
Implement nullish coalescing (`??`) or conditional checks (`if (mimeType)`) when consuming the results of `getType` or `getExtension`.
affects: >=1.0.0
gotchaWhile 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.
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0, _mime_lite.getType) is not a function
Incorrect CommonJS `require` syntax being used for a package primarily designed for named ESM exports, or incorrect destructuring in a mixed environment.
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.
Cannot find module 'mime-lite' or its corresponding type declarations.
The `mime-lite` package is not installed, or TypeScript cannot locate its declaration files.
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.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mime-lite — npm install mime-lite · libregistry