Skip to main content


[![ci][ci badge]][ci link] deno doc

A module that assists in resolving media types and extensions. It consumes the mime-db and provides API access to the information.



Lookup the content type associated with a file. The path can be just the extension or the full path name. If the content type cannot be determined the function returns undefined:

import { lookup } from "";

lookup("json"); // "application/json"
lookup(".md"); // "text/markdown"
lookup("folder/file.js"); // "application/javascript"
lookup("folder/.htaccess"); // undefined


Return a full Content-Type header value for a given content type or extension. When an extension is used, lookup() is used to resolve the content type first. A default charset is added if not present. The function will return undefined if the content type cannot be resolved:

import { contentType } from "";
import * as path from "";

contentType("markdown"); // "text/markdown; charset=utf-8"
contentType("file.json"); // "application/json; charset=utf-8"
contentType("text/html"); // "text/html; charset=utf-8"
contentType("text/html; charset=iso-8859-1"); // "text/html; charset=iso-8859-1"

contentType(path.extname("/path/to/file.json")); // "application/json; charset=utf-8"


Return a default extension for a given content type. If there is not an appropriate extension, undefined is returned:

import { extension } from "";

extension("application/octet-stream"); // "bin"


Lookup the implied default charset for a given content type. If the content type cannot be resolved, undefined is returned:

import { charset } from "";

charset("text/markdown"); // "UTF-8"


A Map of extensions by content type, in priority order:

import { extensions } from "";

extensions.get("application/javascript"); // [ "js", "mjs" ]


A Map of content types by extension:

import { types } from "";

types.get("ts"); // "application/javascript"

Adapted from mime-type.

MIT License.