Socket
Socket
Sign inDemoInstall

detect-content-type

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    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


Version published
Weekly downloads
73K
decreased by-11.72%
Maintainers
1
Install size
120 kB
Created
Weekly downloads
 

Readme

Source

detect-content-type

Javascript module to determine the Content-Type of the given data, using the algorithm specified in the MIME Sniffing Standard.

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:

import detectContentType from 'detect-content-type'

Using CommonJS:

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.

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 method in the Go standard library.

Keywords

FAQs

Last updated on 02 Feb 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc