formatMediaType
import { formatMediaType } from "jsr:@ende/media-types";function
function formatMediaType(type: string, param?: Record<string, string> | Iterable<[string, string]>): stringSerializes the media type and the optional parameters as a media type conforming to RFC 2045 and RFC 2616.
The type and parameter names are written in lower-case.
When any of the arguments results in a standard violation then the return
value will be an empty string ("").
type: stringThe media type to serialize.
param?: Record<string, string> | Iterable<[string, string]>Optional parameters to serialize.
Returns
The serialized media type.
Example: Basic usage
import { formatMediaType } from "@ende/media-types/format-media-type";
import { assertEquals } from "@ende/assert";
assertEquals(formatMediaType("text/plain"), "text/plain");
Example: With parameters
import { formatMediaType } from "@ende/media-types/format-media-type";
import { assertEquals } from "@ende/assert";
assertEquals(formatMediaType("text/plain", { charset: "UTF-8" }), "text/plain; charset=UTF-8");