Ohm-Management - Projektarbeit B-ME
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 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # content-type
  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. Create and parse HTTP Content-Type header according to RFC 7231
  8. ## Installation
  9. ```sh
  10. $ npm install content-type
  11. ```
  12. ## API
  13. ```js
  14. var contentType = require('content-type')
  15. ```
  16. ### contentType.parse(string)
  17. ```js
  18. var obj = contentType.parse('image/svg+xml; charset=utf-8')
  19. ```
  20. Parse a content type string. This will return an object with the following
  21. properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
  22. - `type`: The media type (the type and subtype, always lower case).
  23. Example: `'image/svg+xml'`
  24. - `parameters`: An object of the parameters in the media type (name of parameter
  25. always lower case). Example: `{charset: 'utf-8'}`
  26. Throws a `TypeError` if the string is missing or invalid.
  27. ### contentType.parse(req)
  28. ```js
  29. var obj = contentType.parse(req)
  30. ```
  31. Parse the `content-type` header from the given `req`. Short-cut for
  32. `contentType.parse(req.headers['content-type'])`.
  33. Throws a `TypeError` if the `Content-Type` header is missing or invalid.
  34. ### contentType.parse(res)
  35. ```js
  36. var obj = contentType.parse(res)
  37. ```
  38. Parse the `content-type` header set on the given `res`. Short-cut for
  39. `contentType.parse(res.getHeader('content-type'))`.
  40. Throws a `TypeError` if the `Content-Type` header is missing or invalid.
  41. ### contentType.format(obj)
  42. ```js
  43. var str = contentType.format({type: 'image/svg+xml'})
  44. ```
  45. Format an object into a content type string. This will return a string of the
  46. content type for the given object with the following properties (examples are
  47. shown that produce the string `'image/svg+xml; charset=utf-8'`):
  48. - `type`: The media type (will be lower-cased). Example: `'image/svg+xml'`
  49. - `parameters`: An object of the parameters in the media type (name of the
  50. parameter will be lower-cased). Example: `{charset: 'utf-8'}`
  51. Throws a `TypeError` if the object contains an invalid type or parameter names.
  52. ## License
  53. [MIT](LICENSE)
  54. [npm-image]: https://img.shields.io/npm/v/content-type.svg
  55. [npm-url]: https://npmjs.org/package/content-type
  56. [node-version-image]: https://img.shields.io/node/v/content-type.svg
  57. [node-version-url]: http://nodejs.org/download/
  58. [travis-image]: https://img.shields.io/travis/jshttp/content-type/master.svg
  59. [travis-url]: https://travis-ci.org/jshttp/content-type
  60. [coveralls-image]: https://img.shields.io/coveralls/jshttp/content-type/master.svg
  61. [coveralls-url]: https://coveralls.io/r/jshttp/content-type
  62. [downloads-image]: https://img.shields.io/npm/dm/content-type.svg
  63. [downloads-url]: https://npmjs.org/package/content-type