Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/xserver/src/deps.ts>media.getCharset

X-Server a Deno server module with middleware
Go to Latest
function media.getCharset
Re-export
import { media } from "https://deno.land/x/xserver@2.0.0/src/deps.ts";
const { getCharset } = media;

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

Examples

Example 1

import { getCharset } from "https://deno.land/std@0.224.0/media_types/get_charset.ts";

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

Parameters

type: string

Returns

string | undefined