Open Ayoub-Mabrouk opened 2 weeks ago
/**
* Determines if the specified MIME type(s) are acceptable based on the request's `Accept` header.
* Returns the best match if a type is acceptable; otherwise, returns `undefined`.
* If no acceptable type is found, the server should respond with a 406 "Not Acceptable".
*
* The `type` argument can be a:
* - Single MIME type string (e.g., "application/json")
* - Extension name (e.g., "json")
* - Comma-delimited list of types (e.g., "json, html, text/plain")
* - Argument list (e.g., `"json", "html", "text/plain"`)
* - Array of types (e.g., `["json", "html", "text/plain"]`)
*
* The function returns the best match if any is found, otherwise `undefined`.
*
* Examples:
*
* // Accept: text/html
* req.accepts('html');
* // => "html"
*
* // Accept: text/*, application/json
* req.accepts('html');
* // => "html"
* req.accepts('text/html');
* // => "text/html"
* req.accepts('json, text');
* // => "json"
* req.accepts('application/json');
* // => "application/json"
*
* // Accept: text/*, application/json
* req.accepts('image/png');
* req.accepts('png');
* // => undefined
*
* // Accept: text/*;q=.5, application/json
* req.accepts(['html', 'json']);
* req.accepts('html', 'json');
* req.accepts('html, json');
* // => "json"
*
* @param {String|Array} types - A single type, list of types, or array of types to check against the `Accept` header.
* @return {String|undefined} - The best matching type, or `undefined` if no match is found.
* @public
*/
add this docs please
write some tests please :)
...types
).accepts(this).types(...types)
, simplifying the code and improving readability.