MCPcopy Create free account
hub / github.com/broofa/mime

github.com/broofa/mime

Chat with this repo
repository ↗ · DeepWiki ↗ · release v4.1.2 ↗ · + Follow · compare 2 versions
14 symbols 51 edges 12 files 4 documented · 29% ● updated 3mo agov4.1.0 · 2025-09-12★ 2,356

Browse by type

⨍ Functions 12◇ Types & classes 2
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Mime

NPM downloads Mime CI

An API for MIME type information.

  • All mime-db types
  • Compact and dependency-free mime's badge
  • Full TS support

[!Note] mime@4 is now latest. If you're upgrading from mime@3, note the following: * mime@4 is API-compatible with mime@3, with ~~one~~ two exceptions: * Direct imports of mime properties no longer supported * mime.define() cannot be called on the default mime object * ESM module support is required. ESM Module FAQ. * Requires an ES2020 or newer runtime * Built-in Typescript types (@types/mime no longer needed)

Installation

npm install mime

Quick Start

For the full version (800+ MIME types, 1,000+ extensions):

import mime from 'mime';

mime.getType('txt');                    // ⇨ 'text/plain'
mime.getExtension('text/plain');        // ⇨ 'txt'

Lite Version mime/lite's badge

mime/lite is a drop-in mime replacement, stripped of unofficial ("prs.*", "x-*", "vnd.*") types:

import mime from 'mime/lite';

API

mime.getType(pathOrExtension)

Get mime type for the given file path or extension. E.g.

mime.getType('js');             // ⇨ 'text/javascript'
mime.getType('json');           // ⇨ 'application/json'

mime.getType('txt');            // ⇨ 'text/plain'
mime.getType('dir/text.txt');   // ⇨ 'text/plain'
mime.getType('dir\\text.txt');  // ⇨ 'text/plain'
mime.getType('.text.txt');      // ⇨ 'text/plain'
mime.getType('.txt');           // ⇨ 'text/plain'

null is returned in cases where an extension is not detected or recognized

mime.getType('foo/txt');        // ⇨ null
mime.getType('bogus_type');     // ⇨ null

mime.getExtension(type)

Get file extension for the given mime type. Charset options (often included in Content-Type headers) are ignored.

mime.getExtension('text/plain');               // ⇨ 'txt'
mime.getExtension('application/json');         // ⇨ 'json'
mime.getExtension('text/html; charset=utf8');  // ⇨ 'html'

mime.getAllExtensions(type)

[!Note] New in mime@4

Get all file extensions for the given mime type.

```javascript --run default mime.getAllExtensions('image/jpeg'); // ⇨ Set(3) { 'jpeg', 'jpg', 'jpe' }


## Custom `Mime` instances

The default `mime` objects are immutable.  Custom, mutable versions can be created as follows...
### new Mime(type map [, type map, ...])

Create a new, custom mime instance.  For example, to create a mutable version of the default `mime` instance:

```javascript
import { Mime } from 'mime/lite';

import standardTypes from 'mime/types/standard.js';
import otherTypes from 'mime/types/other.js';

const mime = new Mime(standardTypes, otherTypes);

Each argument is passed to the define() method, below. For example new Mime(standardTypes, otherTypes) is synonomous with new Mime().define(standardTypes).define(otherTypes)

mime.define(type map [, force = false])

[!Note] Only available on custom Mime instances

Define MIME type -> extensions.

Attempting to map a type to an already-defined extension will throw unless the force argument is set to true.

mime.define({'text/x-abc': ['abc', 'abcd']});

mime.getType('abcd');            // ⇨ 'text/x-abc'
mime.getExtension('text/x-abc')  // ⇨ 'abc'

Command Line

Extension -> type

$ mime scripts/jquery.js
text/javascript

Type -> extension

$ mime -r image/jpeg
jpeg

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 7
Function 5
Class 2

Languages

TypeScript100%

Modules by API surface

src/Mime.ts9 symbols
scripts/build.ts3 symbols
test/test_util.js2 symbols

Dependencies from manifests, versioned

@types/mime-db1.43.6 · 1×
@types/mime-types3.0.1 · 1×
@types/node26.6.5 · 1×
@typescript-eslint/eslint-plugin8.71.1 · 1×
@typescript-eslint/parser8.71.1 · 1×
chalk6.0.1 · 1×
mime-score2.0.4 · 1×
mime-types3.0.2 · 1×
prettier3.9.10 · 1×
release-please17.11.2 · 1×
runmd2.1.1 · 1×
typescript6.0.3 · 1×

For agents

$ claude mcp add mime \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page