3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
9 Simple RFC 6838 media type parser
14 $ npm install media-typer
20 var typer = require('media-typer')
23 ### typer.parse(string)
26 var obj = typer.parse('image/svg+xml; charset=utf-8')
29 Parse a media type string. This will return an object with the following
30 properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
32 - `type`: The type of the media type (always lower case). Example: `'image'`
34 - `subtype`: The subtype of the media type (always lower case). Example: `'svg'`
36 - `suffix`: The suffix of the media type (always lower case). Example: `'xml'`
38 - `parameters`: An object of the parameters in the media type (name of parameter always lower case). Example: `{charset: 'utf-8'}`
43 var obj = typer.parse(req)
46 Parse the `content-type` header from the given `req`. Short-cut for
47 `typer.parse(req.headers['content-type'])`.
52 var obj = typer.parse(res)
55 Parse the `content-type` header set on the given `res`. Short-cut for
56 `typer.parse(res.getHeader('content-type'))`.
61 var obj = typer.format({type: 'image', subtype: 'svg', suffix: 'xml'})
64 Format an object into a media type string. This will return a string of the
65 mime type for the given object. For the properties of the object, see the
66 documentation for `typer.parse(string)`.
72 [npm-image]: https://img.shields.io/npm/v/media-typer.svg?style=flat
73 [npm-url]: https://npmjs.org/package/media-typer
74 [node-version-image]: https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat
75 [node-version-url]: http://nodejs.org/download/
76 [travis-image]: https://img.shields.io/travis/jshttp/media-typer.svg?style=flat
77 [travis-url]: https://travis-ci.org/jshttp/media-typer
78 [coveralls-image]: https://img.shields.io/coveralls/jshttp/media-typer.svg?style=flat
79 [coveralls-url]: https://coveralls.io/r/jshttp/media-typer
80 [downloads-image]: https://img.shields.io/npm/dm/media-typer.svg?style=flat
81 [downloads-url]: https://npmjs.org/package/media-typer