Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/oak_commons/media_types.ts>matches

A set of APIs for handling HTTP and HTTPS requests with Deno 🐿️ 🦕
Go to Latest
function matches
import { matches } from "https://deno.land/x/oak_commons@0.6.0/media_types.ts";

Determines if the provided media type matches one of the supplied media types. If there is a match, the matched media type is returned, otherwise undefined is returned.

Each type in the media types array can be one of the following:

  • A file extension name such as json. This name will be returned if matched.
  • A media type such as application/json.
  • A media type with a wildcard such as *​/* or *​/json or application/*. The full media type will be returned if matched.
  • A suffix such as +json. This can be combined with a wildcard such as *​/vnd+json or application/*+json. The full mime type will be returned if matched.
  • Special cases of urlencoded and multipart which get normalized to application/x-www-form-urlencoded and multipart/* respectively.

Parameters

value: string
mediaTypes: string[]

Returns

string | undefined