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

x/ayonli_jsext/esm/workerd/http.js>parseAccepts

A JavaScript extension package for building strong and modern applications.
Latest
function parseAccepts
import { parseAccepts } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/workerd/http.js";

Parses the Accept, Accept-Encoding and Accept-Language headers.

NOTE: This function automatically sorts the results by the q-factor value in descending order.

Examples

Example 1

import { parseAccepts } from "@ayonli/jsext/http";

const accepts = parseAccepts("text/html,application/xhtml+xml;q=0.9");
console.log(accepts);
// [
//     { value: "text/html", weight: 1 },
//     { value: "application/xhtml+xml", weight: 0.9 }
// ]

const acceptEncodings = parseAccepts("gzip, deflate, br;q=0.8");
console.log(acceptEncodings);
// [
//     { value: "gzip", weight: 1 },
//     { value: "deflate", weight: 1 },
//     { value: "br", weight: 0.8 }
// ]

const acceptLanguages = parseAccepts("en-US,en;q=0.9");
console.log(acceptLanguages);
// [
//     { value: "en-US", weight: 1 },
//     { value: "en", weight: 0.9 }
// ]