Function typeByExtension

  • 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 ..

    Parameters

    • extension: string

      The file extension to get the media type for.

    Returns string | undefined

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

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

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