📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

type-is

Package Overview
Dependencies
Maintainers
5
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-is

Infer the content-type of a request.

2.0.1
latest
Source
npm
Version published
Weekly downloads
30M
-4.74%
Maintainers
5
Weekly downloads
 
Created

What is type-is?

The type-is npm package is used to determine the MIME type of the content represented by a request or response object. It can check if the content type matches any of the given MIME types, which can be useful for handling requests in web applications, especially when dealing with REST APIs or any other HTTP-based interfaces.

What are type-is's main functionalities?

Check content type

This feature allows you to check if a given content type matches one of the specified MIME types. In the code sample, it checks if 'image/png' is an image MIME type.

const typeis = require('type-is');
const contentType = 'image/png';
const result = typeis.is(contentType, ['image/*']); // returns 'image/png'

Determine if request has body

This feature checks if the request object has a body by inspecting the 'Content-Type' header.

const typeis = require('type-is');
const req = { headers: { 'content-type': 'text/html' } };
const hasBody = typeis.hasBody(req); // returns true

Determine the type of request

This feature determines the type of the request by checking if the 'Content-Type' header matches any of the provided MIME types.

const typeis = require('type-is');
const req = { headers: { 'content-type': 'application/json' } };
const result = typeis(req, ['json', 'urlencoded', 'multipart']); // returns 'json'

Other packages similar to type-is

Keywords

content

FAQs

Package last updated on 27 Mar 2025

Did you know?

Socket

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