Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 16, 2024 via pnpm

type-is 1.6.18

Infer the content-type of a request.
Package summary
Share
0
issues
1
license
4
MIT
Package created
28 Dec 2013
Version published
26 Apr 2019
Maintainers
2
Total deps
4
Direct deps
2
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
4 Packages, Including:
media-typer@0.3.0
mime-db@1.52.0
mime-types@2.1.35
type-is@1.6.18
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

2
All Dependencies CSV
β“˜ This is a list of type-is 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
media-typer0.3.04.09 kBMIT
prod
mime-types2.1.355.46 kBMIT
prod

Visualizations

Frequently Asked Questions

What does type-is do?

Type-is is a useful Node.js module that can infer the content type of an HTTP request. This can help in processing different types of request payloads more efficiently in your server-side code. It checks if the request is from one of the specified types and returns accordingly. If the request has no body or if the Content-Type header is invalid, the function will return null or false respectively.

How do you use type-is?

Implementation of type-is in your projects is straightforward and efficient. Type-is can be installed using the npm install command in your terminal as follows:

$ npm install type-is

Using type-is in your project is as easy as requiring the module and using one of its functions in an HTTP server setup such as:

var http = require('http')
var typeis = require('type-is')

http.createServer(function (req, res) {
  var istext = typeis(req, ['text/*'])
  res.end('you ' + (istext ? 'sent' : 'did not send') + ' me text')
})

In addition to recognizing different content types, type-is also provides a handy method hasBody to check whether a particular request has a body. This can be used to ensure your server responds appropriately only to requests with a valid body.

Here is a code usage example of the hasBody method:

if (typeis.hasBody(req)) {
  req.on('data', function (chunk) {
    // ...
  })
}

Another useful function provided by type-is is is method which checks if a specific mediaType matches any of the specified types.

Here is a code usage example of the is method:

var mediaType = 'application/json'
typeis.is(mediaType, ['json']) // => 'json'

Where are the type-is docs?

The comprehensive documentation for type-is is available in the type-is GitHub repository. It offers multiple examples, complete API references, and explanations on how to use each API and function. This will help you understand not only how to use the module but also the logic behind it and the potential use cases. The GitHub URL for the package, along with its documentation is: type-is GitHub