UNPKG

remix-utils-rt

Version:

This package contains simple utility functions to use with [React Router](https://reactrouter.com/home).

22 lines 916 B
/** * Given an accept header like `text/html, application/json;q=0.9` it will parse * it and return an array of object with the mime-type, subtype and params of * each media type. * @param header The Accept header value * @returns An array of objects with the type, subtype and params of each media type */ export function parseAcceptHeader(header) { let types = header.split(",").map((type) => type.trim()); let parsedTypes = types .map((value) => { let [mediaType, ...params] = value.split(";"); if (!mediaType) return; let [type, subtype] = mediaType.split("/").map((part) => part.trim()); let parsedParams = Object.fromEntries(params.map((param) => param.split("="))); return { type, subtype, params: parsedParams }; }) .filter((v) => v !== undefined); return parsedTypes; } //# sourceMappingURL=parse-accept-header.js.map