src/util/best-format

Accept header media type parsing module
Source:

(require("src/util/best-format"))(acceptHeader, defaultMime) → {Object}

Function to get a media type from a given accept handler using a default media type as fallback.
Parameters:
Name Type Description
acceptHeader string accept request-header
defaultMime string fallback media type
Source:
Returns:
best fitting media type object
Type
Object
Example
bestFormat('image/webp,*\/*;q=0.8', 'image/png')
// {mime: 'image/webp', type: 'webp'}

bestFormat('*\/*;q=0.8', 'image/png')
// {mime: 'image/png', type: 'png'}

bestFormat('image/jpeg,image/png,image/svg+xml,image/*;q=0.8,*\/*;q=0.5', 'image/png')
// {mime: 'image/jpeg', type: 'jpeg'}