Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/lume/deps/media_types.ts>parseMediaType

🔥 Static site generator for Deno 🦕
Very Popular
Go to Latest
function parseMediaType
Re-export
import { parseMediaType } from "https://deno.land/x/lume@v1.18.4/deps/media_types.ts";

Parses the media type and any optional parameters, per RFC 1521. Media types are the values in Content-Type and Content-Disposition headers. On success the function returns a tuple where the first element is the media type and the second element is the optional parameters or undefined if there are none.

The function will throw if the parsed value is invalid.

The returned media type will be normalized to be lower case, and returned params keys will be normalized to lower case, but preserves the casing of the value.

Examples

Example 1

import { parseMediaType } from "https://deno.land/std@0.224.0/media_types/parse_media_type.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

assertEquals(
  parseMediaType("application/JSON"),
  [
    "application/json",
    undefined
  ]
);

assertEquals(
  parseMediaType("text/html; charset=UTF-8"),
  [
    "application/json",
    { charset: "UTF-8" },
  ]
);

Parameters

v: string

Returns

[string, Record<string, string> | undefined]