{"_id":"type-is@3.0.0","bugs":{"url":"https://github.com/jshttp/type-is/issues"},"dist":{"shasum":"65707510f628cc6bb37dae9e3c392fdde7926a72","tarball":"http://registry-npm.ywwl.com/type-is/download/type-is-3.0.0.tgz","integrity":"sha512-txjx+lbH40MgknWZzdizD8FjUukflN5xG/i8t6tggtJuHkEjHD1t6eYE4LwJRDImCbzU6FCg/IAsoyy/BoFIfw==","fileCount":6,"unpackedSize":27670,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/type-is@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHwaRruFHPC1syN2zTR0Qpvt7HX3O9W2PWs7xAUDp9VrAiB0pwc1bzT7l8lDJ8U8muiobVG6k2jGIzHcuPbK86bJBg=="}],"size":7350,"noattachment":false,"key":"/type-is/-/type-is-3.0.0.tgz"},"main":"./dist/index.js","name":"type-is","type":"module","engines":{"node":">= 22"},"exports":"./dist/index.js","funding":{"url":"https://opencollective.com/express","type":"opencollective"},"gitHead":"f61fd0318c775d8e4a9590143eb92487c23afe58","license":"MIT","scripts":{"test":"ts-scripts test","bench":"vitest bench","build":"ts-scripts build","specs":"ts-scripts specs","format":"ts-scripts format","prepare":"ts-scripts install && npm run build"},"typings":"./dist/index.d.ts","version":"3.0.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:483eb0b6-62fa-4e1f-8724-f5da84019dad"},"approver":{"name":"blakeembrey","email":"hello@blakeembrey.com"}},"homepage":"https://github.com/jshttp/type-is#readme","keywords":["content","type","checking"],"repository":{"url":"git+https://github.com/jshttp/type-is.git","type":"git"},"ts-scripts":{"dist":["dist"],"project":["tsconfig.build.json"]},"_npmVersion":"11.19.1","description":"Infer the content-type of a request.","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"}],"_nodeVersion":"26.9.0","contributors":[{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},{"url":"http://jongleberry.com","name":"Jonathan Ong","email":"me@jongleberry.com"}],"dependencies":{"content-type":"^3.1.1"},"devDependencies":{"vitest":"^5.0.1","typescript":"^7.0.2","@types/node":"^22.13.10","@vitest/coverage-v8":"^5.0.1","@borderless/ts-scripts":"^0.15.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/type-is_3.0.0_1790033528159_0.676489204206449"},"_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\n```sh\n$ npm install type-is\n```\n\n## API\n\n```js\nimport { createServer } from \"http\";\nimport { TypeIs } from \"type-is\";\n\nconst isText = new TypeIs([\"text/*\"]);\n\ncreateServer(function (req, res) {\n  res.end(\n    \"you \" + (isText.request(req) ? \"sent\" : \"did not send\") + \" me text\",\n  );\n});\n```\n\n### new TypeIs(types, options?)\n\nCreates a reusable content type matcher. The optional `options` object accepts:\n\n- `lookup`: A function for resolving shorthand types (see [`normalize`](#normalizetype)).\n- `parameterValue`: A `(key: string, value: string) => string` function that normalizes both configured and incoming parameter values before comparison. By default, `charset` values are lowercased and other values are unchanged.\n\nEach type in the `types` array can be one of the following:\n\n- A mime type such as `application/json`.\n- A mime type with a wildcard such as `*/*` or `*/json` or `application/*`.\n- A suffix such as `+json`. This can be combined with a wildcard such as `*/vnd+json` or `application/*+json`.\n- A configured shorthand such as `multipart` or `urlencoded`.\n- Any of the above with parameters that must also match, such as `text/html; charset=utf-8`.\n\n### typeIs.is(value)\n\nChecks a `content-type` value and returns the first configured type that matches, or `undefined` when none match.\n\n```js\nconst isJson = new TypeIs([\"application/json\", \"application/*+json\"]);\n\nisJson.is(\"application/json\"); // => 'application/json'\nisJson.is(\"application/vnd.api+json\"); // => 'application/*+json'\nisJson.is(\"text/html\"); // => undefined\n```\n\n### typeIs.request(request)\n\nChecks a request against the configured types. If the request has no body, even if there is a `Content-Type` header, then `undefined` is returned. Otherwise it uses `is` to check the `content-type` header.\n\n```js\n// req.headers.content-type = 'application/json'\n\nnew TypeIs([\"json\"]).request(req); // => 'application/json'\nnew TypeIs([\"application/*\"]).request(req); // => 'application/*'\nnew TypeIs([\"application/json\"]).request(req); // => 'application/json'\n\nnew TypeIs([\"text/html\"]).request(req); // => undefined\n```\n\n### hasBody(request)\n\nReturns true if the given `request` has a body based on the HTTP headers provided.\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### match(expected)\n\nCompile the type string `expected` into a function that matches a MIME type.\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### normalize(type, options?)\n\nNormalize a `type` string. This works by performing the following:\n\n- If the string contains a `/`, then it is returned as the type.\n- If the string starts with `+` (so it is a `+suffix` shorthand like `+json`), then it is expanded to contain the complete wildcard notation of `*/*+suffix`.\n- Else the string is assumed to be a file extension and the mapped media type is returned, or the original input if there is no mapping.\n\nThe default extensions is kept minimal:\n\n- `'json'` -> `'application/json'`\n- `'multipart'` -> `'multipart/*'`\n- `'urlencoded'` -> `'application/x-www-form-urlencoded'`\n\nYou can pass an options object of `{ lookup: (value: string) => string | string[] | undefined }` to provide additional mappings, e.g. [`mime.lookup`](https://github.com/jshttp/mime-types#mimelookuppath).\n\n## Examples\n\n### Example body parser\n\n```js\nconst express = require(\"express\");\nconst { TypeIs, hasBody } = require(\"type-is\");\n\nconst app = express();\nconst typeIs = new TypeIs([\"urlencoded\", \"json\", \"multipart\"]);\n\napp.use(function bodyParser(req, res, next) {\n  if (!hasBody(req)) {\n    return next();\n  }\n\n  switch (typeIs.request(req)) {\n    case \"application/x-www-form-urlencoded\":\n      // parse urlencoded body\n      throw new Error(\"implement urlencoded body parsing\");\n    case \"application/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":1790033528285,"_cnpm_publish_time":1790033528285,"dist-tags":{"latest":"3.0.0","next":"2.0.0"}}