Module

x/opine/deps.ts>Accepts#types

Fast, minimalist web framework for Deno ported from ExpressJS.
Go to Latest
method Accepts.prototype.types
import { Accepts } from "https://dotland.deno.dev/x/opine@2.2.0/deps.ts";

Check if the given type(s) is acceptable, returning the best match when true, otherwise undefined, in which case you should respond with 406 "Not Acceptable".

The type value may be a single mime type string such as "application/json", the extension name such as "json" or an array ["json", "html", "text/plain"]. When a list or array is given the best match, if any is returned.

Examples:

// Accept: text/html
this.types(['html']);
// => ["html"]

// Accept: text/*, application/json
this.types(['html']);
// => ["html"]
this.types(['text/html']);
// => ["text/html"]
this.types(['json', 'text']);
// => ["json"]
this.types(['application/json']);
// => ["application/json"]

// Accept: text/*, application/json
this.types(['image/png']);
this.types(['png']);
// => []

// Accept: text/*;q=.5, application/json
this.types(['html', 'json']);
// => ["json"]

Parameters

optional
types: string[]

Returns

string[] | string | false