# detect-content-type

> detect-content-type implements the algorithm described at http://mimesniff.spec.whatwg.org/ to determine the Content-Type of the given data. It considers at most the first 512 bytes of data. It always returns a valid MIME type: if it cannot determine a mo

Latest version **1.2.0** (published 2018-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-content-type
pnpm add detect-content-type
yarn add detect-content-type
bun add detect-content-type
```

## 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.2.0 |
| Published | 2018-02-02 |
| First published | 2018-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Deepak Jois |
| Maintainers | debugjois |
| Keywords | content-type, http |

## Links

- npm: https://www.npmjs.com/package/detect-content-type
- Repository: https://github.com/deepakjois/node-detect-content-type
- Homepage: https://github.com/deepakjois/node-detect-content-type#readme
- Issues: https://github.com/deepakjois/node-detect-content-type/issues
- npm.io page: https://npm.io/package/detect-content-type

## Recent versions

- 1.2.0 (latest) — 2018-02-02
- 1.0.0 (beta) — 2018-02-01
- 1.1.0 — 2018-02-02
- 1.0.1 — 2018-02-02

## README

# detect-content-type
Javascript module to determine the Content-Type of the given data, using the algorithm specified in the [MIME Sniffing Standard](https://mimesniff.spec.whatwg.org/).

This module is useful in cases where it is not possible to determine the Content-Type of the data using filename extension, either because file does not have an extension or the filename is not available.

## Installation

```
npm install detect-content-type
```

or

```
yarn add detect-content-type
```


## Import
ES6 and above:
```javascript
import detectContentType from 'detect-content-type'
```

Using CommonJS:
```javascript
var detectContentType = require('detect-content-type')
```

## Usage 
`detectContentType` takes a Buffer, and determines its Content-Type. It considers at most
512 bytes of data. `detectContentType` always returns a valid MIME type. If it cannot determine a
more specific one, it returns `application/octet-stream`.
 
```javascript
let ct = detectContentType(Buffer.from("<html><body></body></html>")) // returns 'text/html; charset=utf-8'
```

## Credits
The code in this module is ported nearly line-by-line from the [http.DetectContentType][DetectContentType] method in the Go standard library.

[DetectContentType]: https://golang.org/pkg/net/http/#DetectContentType

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