Function parseMediaType
- parse
Media (type): [mediaType: string, params: Record<string, string> | undefined]Type Parameters
- type: string
The media type to parse.
Returns [mediaType: string, params: Record<string, string> | undefined]
A tuple where the first element is the media type and the second element is the optional parameters or
undefinedif there are none.Example: Usage
import { parseMediaType } from "@std/media-types/parse-media-type";
import { assertEquals } from "@std/assert";
assertEquals(parseMediaType("application/JSON"), ["application/json", undefined]);
assertEquals(parseMediaType("text/html; charset=UTF-8"), ["text/html", { charset: "UTF-8" }]);- type: string
Parses the media type and any optional parameters, per RFC 1521.
Media types are the values in
Content-TypeandContent-Dispositionheaders. On success the function returns a tuple where the first element is the media type and the second element is the optional parameters orundefinedif 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.