IF Commons GitHub

media-types

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-formats FR-018

Media types by file extension (commons 0001-formats FR-018): what a server says a file is, with charset=UTF-8 on text, so a page, a stylesheet, a feed or a book is served as what it is. The table holds the types the harnesses serve and publish (web, documents, images, fonts, audio and video, archives, data); an extension it does not hold is application/octet-stream to contentType. Replaces @std/media-types in erga.

import { contentType, mediaType } from "./media-types.ts";
contentType("site/index.html"); // "text/html; charset=UTF-8"
mediaType(".epub"); // "application/epub+zip"

Source: commons/formats/src/media-types.ts

4 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

contentTypefunction
function contentType(pathOrExtension: string): string

What a Content-Type header says for a path or an extension: its media type, with ; charset=UTF-8 for text; application/octet-stream where it is not known.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

extensionOffunction
function extensionOf(pathOrExtension: string): string

The extension of a path (site/index.html gives html), or an extension given on its own (.html or html), in lower case without its dot; "" where a path has none. A name that starts with a dot and has no other (.epub) is taken as an extension.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

isTextualfunction
function isTextual(type: string): boolean

Whether text of a media type is read as characters, and so served with a charset.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

MEDIA_TYPESconstno test imports it
const MEDIA_TYPES: Readonly<Record<string, string>>

The media type of each extension (lower case, without its dot).

mediaTypefunction
function mediaType(pathOrExtension: string): string | undefined

The media type of a path or an extension, or undefined where the table does not hold it.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.