Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

type-is

Package Overview
Dependencies
Maintainers
6
Versions
38
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.

  • 1.5.7
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
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

FAQs

Package last updated on 10 Feb 2015

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc