package.json 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {
  2. "name": "type-is",
  3. "description": "Infer the content-type of a request.",
  4. "version": "1.6.0",
  5. "author": {
  6. "name": "Jonathan Ong",
  7. "email": "me@jongleberry.com",
  8. "url": "http://jongleberry.com"
  9. },
  10. "contributors": [
  11. {
  12. "name": "Douglas Christopher Wilson",
  13. "email": "doug@somethingdoug.com"
  14. }
  15. ],
  16. "license": "MIT",
  17. "repository": {
  18. "type": "git",
  19. "url": "git://github.com/jshttp/type-is"
  20. },
  21. "dependencies": {
  22. "media-typer": "0.3.0",
  23. "mime-types": "~2.0.9"
  24. },
  25. "devDependencies": {
  26. "istanbul": "0.3.5",
  27. "mocha": "~1.21.5"
  28. },
  29. "engines": {
  30. "node": ">= 0.6"
  31. },
  32. "files": [
  33. "LICENSE",
  34. "HISTORY.md",
  35. "index.js"
  36. ],
  37. "scripts": {
  38. "test": "mocha --reporter spec --check-leaks --bail test/",
  39. "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
  40. "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
  41. },
  42. "keywords": [
  43. "content",
  44. "type",
  45. "checking"
  46. ],
  47. "readme": "# type-is\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][travis-image]][travis-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\nvar http = require('http')\nvar is = require('type-is')\n\nhttp.createServer(function (req, res) {\n var istext = is(req, ['text/*'])\n res.end('you ' + (istext ? 'sent' : 'did not send') + ' me text')\n})\n```\n\n### type = is(request, types)\n\n`request` is the node HTTP request. `types` is an array of types.\n\n```js\n// req.headers.content-type = 'application/json'\n\nis(req, ['json']) // 'json'\nis(req, ['html', 'json']) // 'json'\nis(req, ['application/*']) // 'application/json'\nis(req, ['application/json']) // 'application/json'\n\nis(req, ['html']) // false\n```\n\n### type = is.is(mediaType, types)\n\n`mediaType` is the [media type](https://tools.ietf.org/html/rfc6838) string. `types` is an array of types.\n\n```js\nvar mediaType = 'application/json'\n\nis.is(mediaType, ['json']) // 'json'\nis.is(mediaType, ['html', 'json']) // 'json'\nis.is(mediaType, ['application/*']) // 'application/json'\nis.is(mediaType, ['application/json']) // 'application/json'\n\nis.is(mediaType, ['html']) // false\n```\n\n### Each type can be:\n\n- An 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/*`. The full mime type will be returned if matched.\n- A suffix such as `+json`. This can be combined with a wildcard such as `*/vnd+json` or `application/*+json`. The full mime type will be returned if matched.\n\n`false` will be returned if no type matches.\n\n`null` will be returned if the request does not have a body.\n\n## Examples\n\n#### Example body parser\n\n```js\nvar is = require('type-is');\n\nfunction bodyParser(req, res, next) {\n if (!is.hasBody(req)) {\n return next()\n }\n\n switch (is(req, ['urlencoded', 'json', 'multipart'])) {\n case 'urlencoded':\n // parse urlencoded body\n throw new Error('implement urlencoded body parsing')\n break\n case 'json':\n // parse json body\n throw new Error('implement json body parsing')\n break\n case 'multipart':\n // parse multipart body\n throw new Error('implement multipart body parsing')\n break\n default:\n // 415 error code\n res.statusCode = 415\n res.end()\n return\n }\n}\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/type-is.svg?style=flat\n[npm-url]: https://npmjs.org/package/type-is\n[node-version-image]: https://img.shields.io/node/v/type-is.svg?style=flat\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/jshttp/type-is.svg?style=flat\n[travis-url]: https://travis-ci.org/jshttp/type-is\n[coveralls-image]: https://img.shields.io/coveralls/jshttp/type-is.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/jshttp/type-is?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/type-is.svg?style=flat\n[downloads-url]: https://npmjs.org/package/type-is\n",
  48. "readmeFilename": "README.md",
  49. "bugs": {
  50. "url": "https://github.com/jshttp/type-is/issues"
  51. },
  52. "homepage": "https://github.com/jshttp/type-is",
  53. "_id": "type-is@1.6.0",
  54. "_shasum": "efcb9223fafad5a03be14d8f6c9e1785f2c0e7c3",
  55. "_from": "type-is@~1.6.0",
  56. "_resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.0.tgz"
  57. }