getCharset

import { getCharset } from "jsr:@ende/media-types";

function

function getCharset(type: string): string | undefined

Given a media type or header value, identify the encoding charset. If the charset cannot be determined, the function returns undefined.

type: string

The media type or header value to get the charset for.

Returns

The charset for the given media type or header value, or undefined if the charset cannot be determined.

Example: Usage

import { getCharset } from "@ende/media-types/get-charset";
import { assertEquals } from "@ende/assert";

assertEquals(getCharset("text/plain"), "UTF-8");
assertEquals(getCharset("application/foo"), undefined);
assertEquals(getCharset("application/news-checkgroups"), "US-ASCII");
assertEquals(getCharset("application/news-checkgroups; charset=UTF-8"), "UTF-8");

Source