1// # `mime.for`
2// Retrieves the 'Content-Type' header to use given a file extension.
3test("for", () => {
4 // accepts extension as string
5 assert.equal(mime.for("txt"), "text/plain");
6 // accepts
7 assert.equal(mime.for(".xml"), "application/xml");
8 // accepts file path
9 assert.equal(mime.for("filename.xml"), "application/xml");
10 assert.equal(mime.for("a.directory/.xml"), "application/xml");
11 // accepts absolute file path
12 assert.equal(mime.for("/path/to/filename.xml"), "application/xml");
13 assert.equal(mime.for("C:\\path\\to\\filename.xml"), "application/xml");
14
15 // rss is special-cased
16 assert.equal(mime.for("rss.xml"), "application/rss+xml");
17
18 // supports modern innovations
19 assert.equal(mime.for(".avif"), "image/avif");
20 assert.equal(mime.for(".jxl"), "image/jxl");
21
22 // fallback
23 assert.equal(mime.for(".unknown"), "application/octet-stream");
24});
25
26import assert from "node:assert";
27import { test } from "vitest";
28import * as mime from "./mime.ts";