MIME Type Lookup Utility

0.0.2 · abandoned · verified Sun Apr 19

The `mime-lookup` library provides a focused utility for resolving MIME types based on file extensions. Unlike some alternatives, this package does not bundle its own MIME type database. Instead, it requires the user to supply a database, typically by integrating with the `mime-db` package. As of its only released version, 0.0.2, it offers core functionalities such as `lookup` for determining a MIME type from a given path, `extension` for retrieving a default file extension from a MIME type, and `define` for adding custom MIME type to extension mappings. It also includes `charsets.lookup` for charset mappings. Key differentiators include its lightweight nature due to the decoupled database, allowing for flexible custom database integration. First published in 2015 and last updated in 2016, the project appears to be unmaintained, making its release cadence non-existent.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate `MimeLookup` using `mime-db`, perform basic MIME type lookups, retrieve extensions, and define custom MIME type mappings.

const MimeLookup = require('mime-lookup');
const mimeDb = require('mime-db'); // This is the recommended database

// Initialize MimeLookup with the mime-db database
const mime = new MimeLookup(mimeDb);

console.log('--- MIME Type Lookups ---');
console.log('file.txt:', mime.lookup('file.txt'));
console.log('image.jpeg:', mime.lookup('image.jpeg'));
console.log('.html:', mime.lookup('.html'));
console.log('unknown.xyz (default):', mime.lookup('unknown.xyz'));

console.log('\n--- Extension Lookups ---');
console.log('text/html:', mime.extension('text/html'));
console.log('application/json:', mime.extension('application/json'));

console.log('\n--- Custom Mappings ---');
mime.define({
    'application/x-custom-format': ['xcf', 'customfmt'],
    'text/markdown': ['md', 'markdown']
});
console.log('document.xcf:', mime.lookup('document.xcf'));
console.log('report.md:', mime.lookup('report.md'));
console.log('application/x-custom-format (extension):', mime.extension('application/x-custom-format'));

view raw JSON →