|                                                                                                                                                                                           |  | <!--
  -- This file is auto-generated from src/README_js.md. Changes should be made there.  --># Mime
A comprehensive, compact MIME type module.
[](https://travis-ci.org/broofa/mime)
## Version 2 Notes
Version 2 is a breaking change from 1.x as the semver implies.  Specifically:
* `lookup()` renamed to `getType()`* `extension()` renamed to `getExtension()`* `charset()` and `load()` methods have been removed
If you prefer the legacy version of this module please `npm install mime@^1`.  Version 1 docs may be found [here](https://github.com/broofa/mime/tree/v1.4.0).
## Install
### NPM
```npm install mime```
### Browser
It is recommended that you use a bundler such as[webpack](https://webpack.github.io/) or [browserify](http://browserify.org/) topackage your code.  However, browser-ready versions are available via wzrd.in.E.g. For the full version:
    <script src="https://wzrd.in/standalone/mime@latest"></script>    <script>    mime.getType(...); // etc.    </script>
Or, for the `mime/lite` version:
    <script src="https://wzrd.in/standalone/mime%2flite@latest"></script>    <script>    mimelite.getType(...); // (Note `mimelite` here)    </script>
## Quick Start
For the full version (800+ MIME types, 1,000+ extensions):
```javascriptconst mime = require('mime');
mime.getType('txt');                    // ⇨ 'text/plain'mime.getExtension('text/plain');        // ⇨ 'txt'```
See [Mime API](#mime-api) below for API details.
## Lite Version
There is also a "lite" version of this module that omits vendor-specific(`*/vnd.*`) and experimental (`*/x-*`) types.  It weighs in at ~2.5KB, comparedto 8KB for the full version.  To load the lite version:
```javascriptconst mime = require('mime/lite');```
## Mime .vs. mime-types .vs. mime-db modules
For those of you wondering about the difference between these [popular] NPM modules,here's a brief rundown ...
[`mime-db`](https://github.com/jshttp/mime-db) is "the source oftruth" for MIME type information.  It is not an API.  Rather, it is a canonicaldataset of mime type definitions pulled from IANA, Apache, NGINX, and custom mappingssubmitted by the Node.js community.
[`mime-types`](https://github.com/jshttp/mime-types) is a thinwrapper around mime-db that provides an API drop-in compatible(ish) with `mime @ < v1.3.6` API.
`mime` is, as of v2, a self-contained module bundled with a pre-optimized versionof the `mime-db` dataset.  It provides a simplified API with the following characteristics:
* Intelligently resolved type conflicts (See [mime-score](https://github.com/broofa/mime-score) for details)* Method naming consistent with industry best-practices* Compact footprint.  E.g. The minified+compressed sizes of the various modules:
Module | Size--- | ---`mime-db`  | 18 KB`mime-types` | same as mime-db`mime` | 8 KB`mime/lite` | 2 KB
## Mime API
Both `require('mime')` and `require('mime/lite')` return instances of the MIMEclass, documented below.
Note: Inputs to this API are case-insensitive.  Outputs (returned values) willbe lowercase.
### new Mime(typeMap, ... more maps)
Most users of this module will not need to create Mime instances directly.However if you would like to create custom mappings, you may do so as follows...
```javascript// Require Mime classconst Mime = require('mime/Mime');
// Define mime type -> extensions mapconst typeMap = {  'text/abc': ['abc', 'alpha', 'bet'],  'text/def': ['leppard']};
// Create and use Mime instanceconst myMime = new Mime(typeMap);myMime.getType('abc');            // ⇨ 'text/abc'myMime.getExtension('text/def');  // ⇨ 'leppard'```
If more than one map argument is provided, each map is `define()`ed (see below), in order.
### mime.getType(pathOrExtension)
Get mime type for the given path or extension.  E.g.
```javascriptmime.getType('js');             // ⇨ 'application/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
```javascriptmime.getType('foo/txt');        // ⇨ nullmime.getType('bogus_type');     // ⇨ null```
### mime.getExtension(type)
Get extension for the given mime type.  Charset options (often included inContent-Type headers) are ignored.
```javascriptmime.getExtension('text/plain');               // ⇨ 'txt'mime.getExtension('application/json');         // ⇨ 'json'mime.getExtension('text/html; charset=utf8');  // ⇨ 'html'```
### mime.define(typeMap[, force = false])
Define [more] type mappings.
`typeMap` is a map of type -> extensions, as documented in `new Mime`, above.
By default this method will throw an error if you try to map a type to anextension that is already assigned to another type.  Passing `true` for the`force` argument will suppress this behavior (overriding any previous mapping).
```javascriptmime.define({'text/x-abc': ['abc', 'abcd']});
mime.getType('abcd');            // ⇨ 'text/x-abc'mime.getExtension('text/x-abc')  // ⇨ 'abc'```
## Command Line
    mime [path_or_extension]
E.g.
    > mime scripts/jquery.js
    application/javascript
----Markdown generated from [src/README_js.md](src/README_js.md) by [](https://github.com/broofa/runmd)
 |