Function formatMediaType

  • Serializes 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 ("").

    Parameters

    • type: string

      The media type to serialize.

    • Optionalparam: Record<string, string> | Iterable<[string, string], any, any>

      Optional parameters to serialize.

    Returns string

    The serialized media type.

    import { formatMediaType } from "@std/media-types/format-media-type";
    import { assertEquals } from "@std/assert";

    assertEquals(formatMediaType("text/plain"), "text/plain");
    import { formatMediaType } from "@std/media-types/format-media-type";
    import { assertEquals } from "@std/assert";

    assertEquals(formatMediaType("text/plain", { charset: "UTF-8" }), "text/plain; charset=UTF-8");