mime-types lookup: working versions (tested 2026-10-16)
Look up content-type from an extension and extension from a type with mime-types, asserting json, html, png and wasm plus the charset helper and graceful unknown handling, offline.
passed5 passed · 0 failed2026-10-16 15:20 UTC- Status
- passed
- Last passed
- 2026-10-16 15:20 UTC
- Tests
- 5 / 5
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
mime-types@3.0.2@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38923127324
The code
Exactly the files that passed. Your agent can pull them with get_recipe("mime-types-lookup") (install), or see them on GitHub.
package.json
{
"name": "mime-types-lookup",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"mime-types": "3.0.2"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/mime.ts
import mime from "mime-types";
export function typeFromExtension(extension: string): string | undefined {
const type = mime.lookup(extension);
return type === false ? undefined : type;
}
export function extensionFromType(type: string): string | undefined {
const extension = mime.extension(type);
return extension === false ? undefined : extension;
}
export function contentTypeFor(extension: string): string | undefined {
const type = mime.contentType(extension);
return type === false ? undefined : type;
}
export function charsetFor(type: string): string | undefined {
const charset = mime.charset(type);
return charset === false ? undefined : charset;
}
test/mime.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import {
charsetFor,
contentTypeFor,
extensionFromType,
typeFromExtension,
} from "../src/mime.ts";
test("resolves content-type from common extensions", () => {
assert.equal(typeFromExtension("json"), "application/json");
assert.equal(typeFromExtension(".json"), "application/json");
assert.equal(typeFromExtension("html"), "text/html");
assert.equal(typeFromExtension(".png"), "image/png");
assert.equal(typeFromExtension("wasm"), "application/wasm");
});
test("resolves extension from common types", () => {
assert.equal(extensionFromType("application/json"), "json");
assert.equal(extensionFromType("text/html"), "html");
assert.equal(extensionFromType("image/png"), "png");
assert.equal(extensionFromType("application/wasm"), "wasm");
});
test("builds a full content-type with charset", () => {
assert.equal(contentTypeFor("json"), "application/json; charset=utf-8");
assert.equal(contentTypeFor("html"), "text/html; charset=utf-8");
assert.equal(charsetFor("text/html"), "UTF-8");
assert.equal(charsetFor("application/json"), "UTF-8");
});
test("handles unknown input gracefully", () => {
assert.equal(typeFromExtension("not-a-real-ext-xyz"), undefined);
assert.equal(extensionFromType("application/x-not-a-real-type"), undefined);
assert.equal(contentTypeFor("not-a-real-ext-xyz"), undefined);
assert.equal(charsetFor("application/wasm"), undefined);
});
test("round trips a lookup back to its extension", () => {
const type = typeFromExtension("wasm");
assert.equal(type, "application/wasm");
assert.equal(extensionFromType(type as string), "wasm");
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.