Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # type-is
  2. [![NPM Version][npm-image]][npm-url]
  3. [![NPM Downloads][downloads-image]][downloads-url]
  4. [![Node.js Version][node-version-image]][node-version-url]
  5. [![Build Status][travis-image]][travis-url]
  6. [![Test Coverage][coveralls-image]][coveralls-url]
  7. Infer the content-type of a request.
  8. ### Install
  9. ```sh
  10. $ npm install type-is
  11. ```
  12. ## API
  13. ```js
  14. var http = require('http')
  15. var is = require('type-is')
  16. http.createServer(function (req, res) {
  17. var istext = is(req, ['text/*'])
  18. res.end('you ' + (istext ? 'sent' : 'did not send') + ' me text')
  19. })
  20. ```
  21. ### type = is(request, types)
  22. `request` is the node HTTP request. `types` is an array of types.
  23. ```js
  24. // req.headers.content-type = 'application/json'
  25. is(req, ['json']) // 'json'
  26. is(req, ['html', 'json']) // 'json'
  27. is(req, ['application/*']) // 'application/json'
  28. is(req, ['application/json']) // 'application/json'
  29. is(req, ['html']) // false
  30. ```
  31. ### type = is.is(mediaType, types)
  32. `mediaType` is the [media type](https://tools.ietf.org/html/rfc6838) string. `types` is an array of types.
  33. ```js
  34. var mediaType = 'application/json'
  35. is.is(mediaType, ['json']) // 'json'
  36. is.is(mediaType, ['html', 'json']) // 'json'
  37. is.is(mediaType, ['application/*']) // 'application/json'
  38. is.is(mediaType, ['application/json']) // 'application/json'
  39. is.is(mediaType, ['html']) // false
  40. ```
  41. ### Each type can be:
  42. - An extension name such as `json`. This name will be returned if matched.
  43. - A mime type such as `application/json`.
  44. - A mime type with a wildcard such as `*/json` or `application/*`. The full mime type will be returned if matched
  45. - 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.
  46. `false` will be returned if no type matches.
  47. ## Examples
  48. #### Example body parser
  49. ```js
  50. var is = require('type-is');
  51. function bodyParser(req, res, next) {
  52. if (!is.hasBody(req)) {
  53. return next()
  54. }
  55. switch (is(req, ['urlencoded', 'json', 'multipart'])) {
  56. case 'urlencoded':
  57. // parse urlencoded body
  58. throw new Error('implement urlencoded body parsing')
  59. break
  60. case 'json':
  61. // parse json body
  62. throw new Error('implement json body parsing')
  63. break
  64. case 'multipart':
  65. // parse multipart body
  66. throw new Error('implement multipart body parsing')
  67. break
  68. default:
  69. // 415 error code
  70. res.statusCode = 415
  71. res.end()
  72. return
  73. }
  74. }
  75. ```
  76. ## License
  77. [MIT](LICENSE)
  78. [npm-image]: https://img.shields.io/npm/v/type-is.svg?style=flat
  79. [npm-url]: https://npmjs.org/package/type-is
  80. [node-version-image]: https://img.shields.io/node/v/type-is.svg?style=flat
  81. [node-version-url]: http://nodejs.org/download/
  82. [travis-image]: https://img.shields.io/travis/jshttp/type-is.svg?style=flat
  83. [travis-url]: https://travis-ci.org/jshttp/type-is
  84. [coveralls-image]: https://img.shields.io/coveralls/jshttp/type-is.svg?style=flat
  85. [coveralls-url]: https://coveralls.io/r/jshttp/type-is?branch=master
  86. [downloads-image]: https://img.shields.io/npm/dm/type-is.svg?style=flat
  87. [downloads-url]: https://npmjs.org/package/type-is