# mimesniff

> Sniff MIME types in browser

Latest version **1.1.1** (published 2019-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install mimesniff
pnpm add mimesniff
yarn add mimesniff
bun add mimesniff
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-03-19 |
| First published | 2019-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Blake Friedman |
| Maintainers | blakef |
| Keywords | MIME, sniff |

## Links

- npm: https://www.npmjs.com/package/mimesniff
- Homepage: https://gitlab.com/blakef/mimesniff#readme
- Issues: https://gitlab.com/blakef/mimesniff/issues
- npm.io page: https://npm.io/package/mimesniff

## Recent versions

- 1.1.1 (latest) — 2019-03-19
- 1.1.0 — 2019-03-19
- 1.0.1 — 2019-03-14
- 1.0.0 — 2019-03-14

## README

# MIME Sniffing for the Browser

Do you not trust your the mime type determined by your browser, you shouldn't.  Most browsers will take a 
file's extension to determine MIME type.  Using `getMIMEType(file)` will try sniff the file type:

```html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>MIME test</title>
    <script src="index.js"></script>
  </head>
  <body>
    <input id="file" type="file" />
    <ol></ol>
    <script type="text/javascript">
      document.getElementById('file').addEventListener('change', (e) => {
        for (let file of e.srcElement.files) {
          const li = document.createElement('li');
          getMIMEType(file)
            .then(
              text => li.innerText = text,
              text => li.innerText = `${error} -> I'll use the browser supplied one: ${file.type}`
            ) 
            .then(() => document.querySelector('ol').appendChild(li));
        }
      });
    </script>
  </body>
</html>
```

# Can sniff:

| Category | Type |
|----------|------|
| audio | aiff |
| audio | mpeg |
| application | ogg |
| audio | midi |
| video | avi |
| audio | wave |
| image | bmp |
| image | gif |
| image | gif |
| image | webp |
| image | png |
| image | jpeg |
| application | x-gzip |
| application | zip |
| application | x-rar-compressed |
| application | postscript |
| application | pdf |

# Develop

Want to add support for more types?  Take a look at the [MIME Sniffing living standard](https://mimesniff.spec.whatwg.org/).

---
_Source: https://npm.io/package/mimesniff · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
