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

x/capi/deps/std/http.ts>acceptsLanguages

[WIP] A framework for crafting interactions with Substrate chains
Latest
function acceptsLanguages
import { acceptsLanguages } from "https://deno.land/x/capi@v0.1.1-beta.1/deps/std/http.ts";

Returns an array of languages accepted by the request, in order of preference. If there are no languages supplied in the request, then ["*"] is returned, imply any language is accepted.

Examples

Example 1

import { acceptsLanguages } from "https://deno.land/std@0.224.0/http/negotiation.ts";

const req = new Request("https://example.com/", {
  headers: {
    "accept-language": "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5",
  },
});

acceptsLanguages(req); // ["fr-CH", "fr", "en", "de", "*"]

Returns

string[]

For a given set of languages, return the best match accepted in the request. If no languages match, then the function returns undefined.

Examples

Example 1

import { acceptsLanguages } from "https://deno.land/std@0.224.0/http/negotiation.ts";

const req = new Request("https://example.com/", {
  headers: {
    "accept-language": "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5",
  },
});

acceptsLanguages(req, "en-gb", "en-us", "en"); // "en"

Parameters

request: Request
...langs: string[]

Returns

string | undefined