- deprecatedLatest
- v2.13.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.12.3
- v2.12.2
- v2.12.1
- v2.12.0
- v2.11.1
- v2.11.0
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.4
- v2.9.3
- v2.9.2
- v2.9.1
- 0.1.0
- v2.9.0
- v2.8.4
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.1
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.7
- v2.4.6
- v2.4.5
- v2.4.4
- v2.4.3
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.8
- v2.3.7
- v2.3.6
- v2.3.5
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- v1.0.0
media_types
A module that assists in resolving media types and extensions. It consumes a media type database derived from mime-db and provides API access to the information.
Usage
lookup(path)
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 "https://deno.land/x/media_types/mod.ts";
lookup("json"); // "application/json"
lookup(".md"); // "text/markdown"
lookup("folder/file.js"); // "application/javascript"
lookup("folder/.htaccess"); // undefined
contentType(type)
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 "https://deno.land/x/media_types/mod.ts";
import * as path from "https://deno.land/std/path/mod.ts";
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"
extension(type)
Return a default extension for a given content type. If there is not an
appropriate extension, undefined
is returned:
import { extension } from "https://deno.land/x/media_types/mod.ts";
extension("application/octet-stream"); // "bin"
charset(type)
Lookup the implied default charset for a given content type. If the content type
cannot be resolved, undefined
is returned:
import { charset } from "https://deno.land/x/media_types/mod.ts";
charset("text/markdown"); // "UTF-8"
extensions
A Map
of extensions by content type, in priority order:
import { extensions } from "https://deno.land/x/media_types/mod.ts";
extensions.get("application/javascript"); // [ "js", "mjs" ]
types
A Map
of content types by extension:
import { types } from "https://deno.land/x/media_types/mod.ts";
types.get("js"); // "application/javascript"
Adapted from mime-types and mime-db.
MIT License.