# media-typer

[![NPM Version](https://img.shields.io/npm/v/media-typer.svg?style=flat)](https://npmjs.org/package/media-typer) [![NPM Downloads](https://img.shields.io/npm/dm/media-typer.svg?style=flat)](https://npmjs.org/package/media-typer) [![Node.js Version](https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat)](http://nodejs.org/download/) [![Build Status](https://img.shields.io/travis/jshttp/media-typer.svg?style=flat)](https://travis-ci.org/jshttp/media-typer) [![Test Coverage](https://img.shields.io/coveralls/jshttp/media-typer.svg?style=flat)](https://coveralls.io/r/jshttp/media-typer)

Simple RFC 6838 media type parser

## Installation

```sh
$ npm install media-typer
```

## API

```js
var typer = require('media-typer')
```

### typer.parse(string)

```js
var obj = typer.parse('image/svg+xml; charset=utf-8')
```

Parse a media type string. This will return an object with the following properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):

* `type`: The type of the media type (always lower case). Example: `'image'`
* `subtype`: The subtype of the media type (always lower case). Example: `'svg'`
* `suffix`: The suffix of the media type (always lower case). Example: `'xml'`
* `parameters`: An object of the parameters in the media type (name of parameter always lower case). Example: `{charset: 'utf-8'}`

### typer.parse(req)

```js
var obj = typer.parse(req)
```

Parse the `content-type` header from the given `req`. Short-cut for `typer.parse(req.headers['content-type'])`.

### typer.parse(res)

```js
var obj = typer.parse(res)
```

Parse the `content-type` header set on the given `res`. Short-cut for `typer.parse(res.getHeader('content-type'))`.

### typer.format(obj)

```js
var obj = typer.format({type: 'image', subtype: 'svg', suffix: 'xml'})
```

Format an object into a media type string. This will return a string of the mime type for the given object. For the properties of the object, see the documentation for `typer.parse(string)`.

## License

[MIT](https://github.com/pingponglabs/mediamagic-platform/blob/main/services/graphql-gateway/node_modules/media-typer/LICENSE/README.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mediamagic.dev/product-docs/services/graphql-gateway/node_modules/media-typer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
