x/oak/deps.ts

A middleware framework for handling HTTP with Deno 🐿️ 🦕
Very Popular
Go to Latest
function contentType
import { contentType } from "https://dotland-vbqsvsrpfncg.deno-staging.dev/x/oak@v11.1.0/deps.ts?s=contentType";

Given an extension or media type, return a full Content-Type or Content-Disposition header value.

The function will treat the extensionOrType as a media type when it contains a /, otherwise it will process it as an extension, with or without the leading ..

Returns undefined if unable to resolve the media type.

Examples

import { contentType } from "https://deno.land/std@$STD_VERSION/media_types/mod.ts";

contentType(".json"); // `application/json; charset=UTF-8`
contentType("text/html"); // `text/html; charset=UTF-8`
contentType("text/html; charset=UTF-8"); // `text/html; charset=UTF-8`
contentType("txt"); // `text/plain; charset=UTF-8`
contentType("foo"); // undefined
contentType("file.json"); // undefined

Type Parameters

T extends (string & { }) | KnownExtensionOrType[src]

Parameters

extensionOrType: T[src]

Returns

Lowercase<T> extends KnownExtensionOrType ? string : string | undefined[src]