{"name":"type-is","description":"Infer the content-type of a request.","version":"2.1.0","contributors":[{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},{"name":"Jonathan Ong","email":"me@jongleberry.com","url":"http://jongleberry.com"}],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/jshttp/type-is.git"},"funding":{"type":"opencollective","url":"https://opencollective.com/express"},"dependencies":{"content-type":"^2.0.0","media-typer":"^1.1.0","mime-types":"^3.0.0"},"devDependencies":{"eslint":"7.32.0","eslint-config-standard":"14.1.1","eslint-plugin-import":"2.31.0","eslint-plugin-markdown":"2.2.1","eslint-plugin-node":"11.1.0","eslint-plugin-promise":"5.2.0","eslint-plugin-standard":"4.1.0","mocha":"9.2.2","nyc":"15.1.0"},"engines":{"node":">= 18"},"scripts":{"lint":"eslint .","test":"mocha --reporter spec --check-leaks --bail test/","test:debug":"mocha --reporter spec --check-leaks --inspect --inspect-brk test/","test-ci":"nyc --reporter=lcovonly --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test"},"keywords":["content","type","checking"],"_id":"type-is@2.1.0","gitHead":"62a423ff2144dcc0c047111be1c860a3027bf148","bugs":{"url":"https://github.com/jshttp/type-is/issues"},"homepage":"https://github.com/jshttp/type-is#readme","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==","shasum":"71d1a7053293582e16ac9f3ebaf1ab9aa49e5570","tarball":"http://registry-npm.ywwl.com/type-is/download/type-is-2.1.0.tgz","fileCount":5,"unpackedSize":21269,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC6pgzNAJ5/TNElixfYJuYKKPHyodviVTN+WiyKaXDfawIhAMe9QZB6Y5MagvXoygPMNkCvdymImMEVzq/R6yMdff5s"}],"size":6752,"noattachment":false,"key":"/type-is/-/type-is-2.1.0.tgz"},"_npmUser":{"name":"blakeembrey","email":"hello@blakeembrey.com"},"directories":{},"maintainers":[{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"blakeembrey","email":"hello@blakeembrey.com"},{"name":"wesleytodd","email":"wes@wesleytodd.com"},{"name":"dougwilson","email":"doug@somethingdoug.com"},{"name":"jongleberry","email":"jonathanrichardong@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/type-is_2.1.0_1778686224360_0.02271048895530603"},"_hasShrinkwrap":false,"readme":"# type-is\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][ci-image]][ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nInfer the content-type of a request.\n\n## Install\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```sh\n$ npm install type-is\n```\n\n## API\n\n```js\nvar http = require('http')\nvar typeis = require('type-is')\n\nhttp.createServer(function (req, res) {\n  var istext = typeis(req, ['text/*'])\n  res.end('you ' + (istext ? 'sent' : 'did not send') + ' me text')\n})\n```\n\n### typeis(request, types)\n\nChecks if the `request` is one of the `types`. If the request has no body,\neven if there is a `Content-Type` header, then `null` is returned. If the\n`Content-Type` header is invalid or does not matches any of the `types`, then\n`false` is returned. Otherwise, a string of the type that matched is returned.\n\nThe `request` argument is expected to be a Node.js HTTP request. The `types`\nargument is an array of type strings.\n\nEach type in the `types` array can be one of the following:\n\n- A file extension name such as `json`. This name will be returned if matched.\n- A mime type such as `application/json`.\n- A mime type with a wildcard such as `*/*` or `*/json` or `application/*`.\n  The full mime type will be returned if matched.\n- A suffix such as `+json`. This can be combined with a wildcard such as\n  `*/vnd+json` or `application/*+json`. The full mime type will be returned\n  if matched.\n\nSome examples to illustrate the inputs and returned value:\n\n```js\n// req.headers.content-type = 'application/json'\n\ntypeis(req, ['json']) // => 'json'\ntypeis(req, ['html', 'json']) // => 'json'\ntypeis(req, ['application/*']) // => 'application/json'\ntypeis(req, ['application/json']) // => 'application/json'\n\ntypeis(req, ['html']) // => false\n```\n\n### typeis.hasBody(request)\n\nReturns a Boolean if the given `request` has a body, regardless of the\n`Content-Type` header.\n\nHaving a body has no relation to how large the body is (it may be 0 bytes).\nThis is similar to how file existence works. If a body does exist, then this\nindicates that there is data to read from the Node.js request stream.\n\n```js\nif (typeis.hasBody(req)) {\n  // read the body, since there is one\n\n  req.on('data', function (chunk) {\n    // ...\n  })\n}\n```\n\n### typeis.is(mediaType, types)\n\nChecks if the `mediaType` is one of the `types`. If the `mediaType` is invalid\nor does not matches any of the `types`, then `false` is returned. Otherwise, a\nstring of the type that matched is returned.\n\nThe `mediaType` argument is expected to be a\n[media type](https://tools.ietf.org/html/rfc6838) string. The `types` argument\nis an array of type strings.\n\nEach type in the `types` array can be one of the following:\n\n- A file extension name such as `json`. This name will be returned if matched.\n- A mime type such as `application/json`.\n- A mime type with a wildcard such as `*/*` or `*/json` or `application/*`.\n  The full mime type will be returned if matched.\n- A suffix such as `+json`. This can be combined with a wildcard such as\n  `*/vnd+json` or `application/*+json`. The full mime type will be returned\n  if matched.\n\nSome examples to illustrate the inputs and returned value:\n\n```js\nvar mediaType = 'application/json'\n\ntypeis.is(mediaType, ['json']) // => 'json'\ntypeis.is(mediaType, ['html', 'json']) // => 'json'\ntypeis.is(mediaType, ['application/*']) // => 'application/json'\ntypeis.is(mediaType, ['application/json']) // => 'application/json'\n\ntypeis.is(mediaType, ['html']) // => false\n```\n\n### typeis.match(expected, actual)\n\nMatch the type string `expected` with `actual`, taking in to account wildcards.\nA wildcard can only be in the type of the subtype part of a media type and only\nin the `expected` value (as `actual` should be the real media type to match). A\nsuffix can still be included even with a wildcard subtype. If an input is\nmalformed, `false` will be returned.\n\n```js\ntypeis.match('text/html', 'text/html') // => true\ntypeis.match('*/html', 'text/html') // => true\ntypeis.match('text/*', 'text/html') // => true\ntypeis.match('*/*', 'text/html') // => true\ntypeis.match('*/*+json', 'application/x-custom+json') // => true\n```\n\n### typeis.normalize(type)\n\nNormalize a `type` string. This works by performing the following:\n\n- If the `type` is not a string, `false` is returned.\n- If the string starts with `+` (so it is a `+suffix` shorthand like `+json`),\n  then it is expanded to contain the complete wildcard notation of `*/*+suffix`.\n- If the string contains a `/`, then it is returned as the type.\n- Else the string is assumed to be a file extension and the mapped media type is\n  returned, or `false` is there is no mapping.\n\nThis includes two special mappings:\n\n- `'multipart'` -> `'multipart/*'`\n- `'urlencoded'` -> `'application/x-www-form-urlencoded'`\n\n## Examples\n\n### Example body parser\n\n```js\nvar express = require('express')\nvar typeis = require('type-is')\n\nvar app = express()\n\napp.use(function bodyParser (req, res, next) {\n  if (!typeis.hasBody(req)) {\n    return next()\n  }\n\n  switch (typeis(req, ['urlencoded', 'json', 'multipart'])) {\n    case 'urlencoded':\n      // parse urlencoded body\n      throw new Error('implement urlencoded body parsing')\n    case 'json':\n      // parse json body\n      throw new Error('implement json body parsing')\n    case 'multipart':\n      // parse multipart body\n      throw new Error('implement multipart body parsing')\n    default:\n      // 415 error code\n      res.statusCode = 415\n      res.end()\n      break\n  }\n})\n```\n\n## License\n\n[MIT](LICENSE)\n\n[ci-image]: https://badgen.net/github/checks/jshttp/type-is/master?label=ci\n[ci-url]: https://github.com/jshttp/type-is/actions/workflows/ci.yml\n[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/type-is/master\n[coveralls-url]: https://coveralls.io/r/jshttp/type-is?branch=master\n[node-version-image]: https://badgen.net/npm/node/type-is\n[node-version-url]: https://nodejs.org/en/download\n[npm-downloads-image]: https://badgen.net/npm/dm/type-is\n[npm-url]: https://npmjs.org/package/type-is\n[npm-version-image]: https://badgen.net/npm/v/type-is\n[travis-image]: https://badgen.net/travis/jshttp/type-is/master\n[travis-url]: https://travis-ci.org/jshttp/type-is\n","publish_time":1778686224508,"_cnpm_publish_time":1778686224508,"dist-tags":{"latest":"3.0.0","next":"2.0.0"}}