{"name":"type-is","version":"2.0.1","keywords":["content","type","checking"],"license":"MIT","_id":"type-is@2.0.1","maintainers":[{"name":"blakeembrey","email":"hello@blakeembrey.com"},{"name":"wesleytodd","email":"wes@wesleytodd.com"},{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"dougwilson","email":"doug@somethingdoug.com"},{"name":"jongleberry","email":"jonathanrichardong@gmail.com"}],"contributors":[{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},{"url":"http://jongleberry.com","name":"Jonathan Ong","email":"me@jongleberry.com"}],"homepage":"https://github.com/jshttp/type-is#readme","bugs":{"url":"https://github.com/jshttp/type-is/issues"},"dist":{"shasum":"64f6cf03f92fce4015c2b224793f6bdd4b068c97","tarball":"http://registry-npm.ywwl.com/type-is/download/type-is-2.0.1.tgz","fileCount":5,"integrity":"sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw==","signatures":[{"sig":"MEQCIE5L+/qTUCwB+EiPWBST/CXJ8WdJBRs3n7WJtkDB/bgRAiBpEw/y/D/duf9Y+j5tnZxckcv/uhkt8cKe19wFcBHGhA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21269,"size":6702,"noattachment":false,"key":"/type-is/-/type-is-2.0.1.tgz"},"engines":{"node":">= 0.6"},"gitHead":"4a16e0850ec60234a45c4f546bf759ae161c6a36","scripts":{"lint":"eslint .","test":"mocha --reporter spec --check-leaks --bail test/","test-ci":"nyc --reporter=lcovonly --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test","test:debug":"mocha --reporter spec --check-leaks --inspect --inspect-brk test/"},"_npmUser":{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},"repository":{"url":"git+https://github.com/jshttp/type-is.git","type":"git"},"_npmVersion":"10.9.0","description":"Infer the content-type of a request.","directories":{},"_nodeVersion":"22.10.0","dependencies":{"mime-types":"^3.0.0","media-typer":"^1.1.0","content-type":"^1.0.5"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"15.1.0","mocha":"9.2.1","eslint":"7.32.0","eslint-plugin-node":"11.1.0","eslint-plugin-import":"2.25.4","eslint-plugin-promise":"5.2.0","eslint-config-standard":"14.1.1","eslint-plugin-markdown":"2.2.1","eslint-plugin-standard":"4.1.0"},"_npmOperationalInternal":{"tmp":"tmp/type-is_2.0.1_1743038401388_0.12399995026228616","host":"s3://npm-registry-packages-npm-production"},"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":1743038401576,"_cnpm_publish_time":1743038401576,"dist-tags":{"latest":"3.0.0","next":"2.0.0"}}