Function extension

  • Returns the most relevant extension for the given media type, or undefined if no extension can be found.

    Extensions are returned without a leading ..

    Parameters

    • type: string

      The media type to get the extension for.

    Returns string | undefined

    The extension for the given media type, or undefined if no extension is found.

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

    assertEquals(extension("text/plain"), "txt");
    assertEquals(extension("application/json"), "json");
    assertEquals(extension("text/html; charset=UTF-8"), "html");
    assertEquals(extension("application/foo"), undefined);