Skip to main content

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function parseMediaType
parseMediaType(v: string): [string, Record<string, string> | undefined]

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 "@std/media-types/parse_media_type";

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

Parameters

Return Type

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

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/media-types

Import symbol

import { parseMediaType } from "@std/media-types/parse_media_type";
or

Import directly with a jsr specifier

import { parseMediaType } from "jsr:@std/media-types/parse_media_type";