Utilities to work with structured fields
npm install structured-field-utilssh
npm|pnpm|yarn add structured-field-utils
`
Usage
$3
Setup for the following examples:
`js
import { parseList } from "structured-headers";
import { item } from "sf-utils";
const parsedList = parseList("foo";param="something";q=0.7, "bar";q=0.5, "baz";q=0.6);
`
#### Sort
Sorts a list/an array of items (in the structured fields format) based on HTTP rules specified in [RFC9110].
`js
const sortedList = item.sort(parsedList);
`
#### Match
Compares requested item with an allowed item to determine if they match.
Return a Boolean unless any of the parameter values mismatch, in which case it returns a Map containing the mismatched parameters.
`js
const matched = item.match(parsedList[0], ["foo", new Map([["param", "nothing"]])]);
`
$3
Setup for the following examples:
`js
import { parseList } from "structured-headers";
import { mediaType } from "sf-utils";
const parsedAccept = parseList(text/html;level=3;q=0.7, text/html;q=0.7, text/plain;q=0.5, text/*;q=0.1);
`
#### Sort
Sorts an array of media-types (in the structured fields format) based on HTTP rules specified in [RFC9110].
`js
const sortedAccept = mediaType.sort(parsedAccept);
`
#### Match
Compares requested media-type with an allowed media-type to determine if they match based on type, subtype, and parameters.
Return a Boolean unless any of the parameter values mismatch, in which case it returns a Map containing the mismatched parameters.
`js
import { Token } from "structured-headers";
const matched = mediaType.match(parsedAccept[3], [new Token("text/html"), new Map([["level", 2]])]]);
``