mime v4.0.6
Mime
An API for MIME type information.
!Note
mime@4is nowlatest. If you're upgrading frommime@3, note the following:
mime@4is API-compatible withmime@3, withonetwo exceptions:
- Direct imports of
mimeproperties no longer supportedmime.define()cannot be called on the defaultmimeobject- ESM module support is required. ESM Module FAQ.
- Requires an ES2020 or newer runtime
- Built-in Typescript types (
@types/mimeno longer needed)
Installation
npm install mimeQuick 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 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'); // ⇨ nullmime.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.
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:
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
Mimeinstances
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/javascriptType -> extension
$ mime -r image/jpeg
jpeg12 months ago
12 months ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
14 years ago
14 years ago
14 years ago
15 years ago
15 years ago
15 years ago
15 years ago