typeByExtension

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

function

function typeByExtension(extension: string): string | undefined

Returns the media type associated with the file extension, or undefined if no media type is found.

Values are normalized to lower case and matched irrespective of a leading ..

extension: string

The file extension to get the media type for.

Returns

The media type associated with the file extension, or undefined if no media type is found.

Example: Usage

import { typeByExtension } from "@ende/media-types/type-by-extension";
import { assertEquals } from "@ende/assert";

assertEquals(typeByExtension("js"), "text/javascript");
assertEquals(typeByExtension(".HTML"), "text/html");
assertEquals(typeByExtension("foo"), undefined);
assertEquals(typeByExtension("file.json"), undefined);

Source