extension

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

function

function extension(type: string): string | undefined

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

Extensions are returned without a leading ..

type: string

The media type to get the extension for.

Returns

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

Example: Usage

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

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

Source