{
  "type": "module",
  "source": "doc/api/api-contenttype.md",
  "modules": [
    {
      "textRaw": "MIME Type Parsing",
      "name": "mime_type_parsing",
      "introduced_in": "v4.13.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>undici exposes helpers for parsing and serializing MIME types according to the\nWHATWG <a href=\"https://mimesniff.spec.whatwg.org/\">MIME Sniffing Standard</a>. These are the same primitives undici uses\ninternally to interpret <code>Content-Type</code> headers and <code>data:</code> URLs.</p>\n<p>Import the functions from <code>'undici'</code>:</p>\n<pre><code class=\"language-mjs\">import { parseMIMEType, serializeAMimeType } from 'undici'\n</code></pre>\n<p>A parsed MIME type is represented as a plain object with the following shape:</p>\n<ul>\n<li><code>type</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The lowercased type, for example <code>'text'</code>.</li>\n<li><code>subtype</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The lowercased subtype, for example <code>'html'</code>.</li>\n<li><code>parameters</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>&#x3C;Map></code></a>&#x3C;<a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a>, <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a>> The parameters, keyed by lowercased\nparameter name.</li>\n<li><code>essence</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The concatenation of <code>type</code>, <code>'/'</code>, and <code>subtype</code>, for\nexample <code>'text/html'</code>.</li>\n</ul>",
      "methods": [
        {
          "textRaw": "`parseMIMEType(input)`",
          "name": "parseMIMEType",
          "type": "method",
          "meta": {
            "added": [
              "v4.13.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`input` {string} The MIME type string to parse.",
                  "name": "input",
                  "type": "string",
                  "desc": "The MIME type string to parse."
                }
              ],
              "return": {
                "textRaw": "Returns: {Object|string} A parsed MIME type record, or the string literal `'failure'` when `input` cannot be parsed.",
                "name": "return",
                "type": "Object|string",
                "desc": "A parsed MIME type record, or the string literal `'failure'` when `input` cannot be parsed.",
                "options": [
                  {
                    "textRaw": "`type` {string} The lowercased type.",
                    "name": "type",
                    "type": "string",
                    "desc": "The lowercased type."
                  },
                  {
                    "textRaw": "`subtype` {string} The lowercased subtype.",
                    "name": "subtype",
                    "type": "string",
                    "desc": "The lowercased subtype."
                  },
                  {
                    "textRaw": "`parameters` {Map}<{string}, {string}> The parsed parameters, keyed by lowercased parameter name.",
                    "name": "parameters",
                    "type": "Map",
                    "desc": "<{string}, {string}> The parsed parameters, keyed by lowercased parameter name."
                  },
                  {
                    "textRaw": "`essence` {string} The MIME type essence, ``${type}/${subtype}``.",
                    "name": "essence",
                    "type": "string",
                    "desc": "The MIME type essence, ``${type}/${subtype}``."
                  }
                ]
              }
            }
          ],
          "desc": "<p>Implements the WHATWG <a href=\"https://mimesniff.spec.whatwg.org/#parse-a-mime-type\">parse a MIME type</a> algorithm. The <code>type</code> and <code>subtype</code>\nare lowercased, and only the first occurrence of a duplicate parameter name is\nretained. When <code>input</code> is empty, lacks a <code>/</code>, or otherwise violates the grammar,\nthe string literal <code>'failure'</code> is returned instead of a record.</p>\n<pre><code class=\"language-mjs\">import { parseMIMEType } from 'undici'\n\nparseMIMEType('text/html; charset=gbk')\n// {\n//   type: 'text',\n//   subtype: 'html',\n//   parameters: Map(1) { 'charset' => 'gbk' },\n//   essence: 'text/html'\n// }\n\nparseMIMEType('not a mime type')\n// 'failure'\n</code></pre>"
        },
        {
          "textRaw": "`serializeAMimeType(mimeType)`",
          "name": "serializeAMimeType",
          "type": "method",
          "meta": {
            "added": [
              "v5.11.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`mimeType` {Object} A MIME type record, as returned by `parseMIMEType()`.",
                  "name": "mimeType",
                  "type": "Object",
                  "desc": "A MIME type record, as returned by `parseMIMEType()`.",
                  "options": [
                    {
                      "textRaw": "`type` {string} The type.",
                      "name": "type",
                      "type": "string",
                      "desc": "The type."
                    },
                    {
                      "textRaw": "`subtype` {string} The subtype.",
                      "name": "subtype",
                      "type": "string",
                      "desc": "The subtype."
                    },
                    {
                      "textRaw": "`parameters` {Map}<{string}, {string}> The parameters to serialize, in insertion order.",
                      "name": "parameters",
                      "type": "Map",
                      "desc": "<{string}, {string}> The parameters to serialize, in insertion order."
                    },
                    {
                      "textRaw": "`essence` {string} The MIME type essence, ``${type}/${subtype}``.",
                      "name": "essence",
                      "type": "string",
                      "desc": "The MIME type essence, ``${type}/${subtype}``."
                    }
                  ]
                }
              ],
              "return": {
                "textRaw": "Returns: {string} The serialized MIME type.",
                "name": "return",
                "type": "string",
                "desc": "The serialized MIME type."
              }
            }
          ],
          "desc": "<p>Implements the WHATWG <a href=\"https://mimesniff.spec.whatwg.org/#serialize-a-mime-type\">serialize a MIME type</a> algorithm. The essence is\nemitted followed by each parameter as <code>;name=value</code>. A parameter value that\ncontains characters outside the HTTP token set is quoted, and any <code>\"</code> or <code>\\</code>\ncharacters within it are escaped.</p>\n<pre><code class=\"language-mjs\">import { serializeAMimeType } from 'undici'\n\nserializeAMimeType({\n  type: 'text',\n  subtype: 'html',\n  parameters: new Map([['charset', 'gbk']]),\n  essence: 'text/html'\n})\n// 'text/html;charset=gbk'\n</code></pre>"
        }
      ]
    }
  ]
}