Registry / serialization / mime-names

mime-names

JSON →
library1.0.0jsnpmunverified

mime-names is a JavaScript package that provides a database of human-readable names and common file extensions, keyed by MIME types. It is designed to complement `mime-db`, offering a more descriptive layer on top of MIME type definitions. This package does not aim to be an exhaustive list of all MIME types, focusing instead on popular and commonly used formats. Developers should anticipate that some less common MIME types might not be present and implement graceful handling for such cases. The current stable version is 1.0.0, and releases are typically made as needed to add new types or update existing data. Its primary differentiator is its direct, lookup-table structure and its specific focus on human-readable names and extensions rather than broader MIME type resolution logic.

npm install mime-names
INSTALL
IMPORT
SIG · MIME-NAMES
M
mime-names
serializationjavascriptv1.0.0
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.

db
import db from 'mime-names';
import { db } from 'mime-names';
The package exports the entire database object as its default export. There are no named exports. Node.js's ESM interop for CommonJS allows this default import pattern.
db (CommonJS)
const db = require('mime-names');
This package is primarily a CommonJS module, and this is the direct and intended way to access the database object in CommonJS environments.

Demonstrates how to import the MIME database and look up information for a specific MIME type, including handling cases where a type might not be found. It illustrates accessing the name and extensions properties.

import db from 'mime-names'; const mimeType = 'application/json'; const data = db[mimeType]; if (data) { console.log(`MIME Type: ${mimeType}`); console.log(` Name: ${data.name}`); console.log(` Extensions: ${data.extensions ? data.extensions.join(', ') : 'None'}`); } else { console.log(`No data found for MIME type: ${mimeType}`); } const unknownMimeType = 'application/x-custom-type'; const unknownData = db[unknownMimeType]; if (!unknownData) { console.log(`\nAs expected, no data for ${unknownMimeType} (not all-encompassing).`); }
Debug
Known issues
gotchaThe `mime-names` database is not comprehensive and explicitly states it 'does not try to be all encompassing'. It focuses on popular file formats. Your application code must gracefully handle cases where a MIME type might not exist in this database.
fix
Always check if the lookup result is `undefined` before trying to access its properties. E.g., `const data = db[mimeType]; if (data) { /* use data */ }`
affects: >=1.0.0
gotchaThe `db` object returned by `mime-names` should be treated as read-only. While JavaScript allows mutation of objects, modifying this imported database can lead to unexpected behavior or inconsistencies, especially if parts of your application rely on its original state.
fix
Avoid directly adding, deleting, or modifying properties on the `db` object. If custom MIME type data is needed, merge it into a separate, application-specific object.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'name')
Attempting to access properties like `.name` or `.extensions` on a MIME type that does not exist in the `mime-names` database without first checking if the entry exists.
fix
Ensure that the MIME type entry is not `undefined` before accessing its properties. `const data = db[mimeType]; if (data) { console.log(data.name); }`
SyntaxError: The requested module 'mime-names' does not provide an export named 'SomeExport'
Incorrectly attempting to use named imports (e.g., `import { SomeExport } from 'mime-names'`) when the package only provides a default export (the entire database object).
fix
Use a default import to get the entire database object: `import db from 'mime-names';`. The package does not offer individual named exports for specific MIME types or utility functions.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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