Skip to main content

latest
Works with
It is unknown whether this package works with Node.js, Deno, Browsers, Cloudflare Workers, Bun
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)

Functions

f
contentType<T extends (string & { }) | KnownExtensionOrType>(extensionOrType: T): Lowercase<T> extends KnownExtensionOrType ? string : string | undefined

Given an extension or media type, return a full Content-Type or Content-Disposition header value.

f
extension(type: string): string | undefined

For a given media type, return the most relevant extension, or undefined if no extension can be found.

f
extensionsByType(type: string): string[] | undefined

Returns the extensions known to be associated with the media type type. The returned extensions will each begin with a leading dot, as in .html.

f
formatMediaType(
type: string,
param?: Record<string, string> | Iterable<[string, string]>
): string

Serializes the media type and the optional parameters as a media type conforming to RFC 2045 and RFC 2616.

f
getCharset(type: string): string | undefined

Given a media type or header value, identify the encoding charset. If the charset cannot be determined, the function returns undefined.

f
parseMediaType(v: string): [string, Record<string, string> | undefined]

Parses the media type and any optional parameters, per RFC 1521. Media types are the values in Content-Type and Content-Disposition headers. On success the function returns a tuple where the first element is the media type and the second element is the optional parameters or undefined if there are none.

f
typeByExtension(extension: string): string | undefined

Returns the media type associated with the file extension. Values are normalized to lower case and matched irrespective of a leading ..

Type Aliases

T
ContentTypeToExtension = [K in keyof DB]: DB[K] extends { extensions: readonly string[]; } ? DB[K]["extensions"][number] : never

Maps content types to their corresponding file extensions.

T
DB = db

MIME-types database.

T
KnownExtensionOrType =
keyof ContentTypeToExtension
| ContentTypeToExtension[keyof ContentTypeToExtension]
| `.${ContentTypeToExtension[keyof ContentTypeToExtension]}`

Known extension or type. Used in contentType.

Variables

v
extensions: Map<string, string[]>

A map of extensions for a given media type.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/media-types

Import symbol

import * as mod from "@std/media-types";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/media-types";