Function contentType
- content
Type <T>(extensionOrType): Lowercase<T> extends KnownExtensionOrType
? string
: string | undefined Type Parameters
- T extends string & {} | KnownExtensionOrType
Type of the extension or media type to resolve.
Parameters
- extensionOrType: T
The extension or media type to resolve.
Returns Lowercase<T> extends KnownExtensionOrType
? string
: string | undefinedThe full
Content-TypeorContent-Dispositionheader value, orundefinedif unable to resolve the media type.Example: Usage
import { contentType } from "@std/media-types/content-type";
import { assertEquals } from "@std/assert";
assertEquals(contentType(".json"), "application/json; charset=UTF-8");
assertEquals(contentType("text/html"), "text/html; charset=UTF-8");
assertEquals(contentType("text/html; charset=UTF-8"), "text/html; charset=UTF-8");
assertEquals(contentType("txt"), "text/plain; charset=UTF-8");
assertEquals(contentType("foo"), undefined);
assertEquals(contentType("file.json"), undefined);- T extends string & {} | KnownExtensionOrType
Returns the full
Content-TypeorContent-Dispositionheader value for the given extension or media type.The function will treat the
extensionOrTypeas a media type when it contains a/, otherwise it will process it as an extension, with or without the leading..Returns
undefinedif unable to resolve the media type.