![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@hapi/accept
Advanced tools
Package description
@hapi/accept is a utility library for HTTP content negotiation. It helps in parsing and matching HTTP headers like Accept, Accept-Charset, Accept-Encoding, and Accept-Language, allowing you to determine the best content to serve based on the client's preferences.
Parsing Accept Header
This feature allows you to parse the 'Accept' header from an HTTP request and get an array of media types sorted by their quality values.
const Accept = require('@hapi/accept');
const headers = { 'accept': 'text/html, application/json;q=0.9, */*;q=0.8' };
const mediaTypes = Accept.mediaTypes(headers.accept);
console.log(mediaTypes); // ['text/html', 'application/json', '*/*']
Parsing Accept-Language Header
This feature allows you to parse the 'Accept-Language' header and get an array of languages sorted by their quality values.
const Accept = require('@hapi/accept');
const headers = { 'accept-language': 'en-US,en;q=0.9,fr;q=0.8' };
const languages = Accept.languages(headers['accept-language']);
console.log(languages); // ['en-US', 'en', 'fr']
Parsing Accept-Charset Header
This feature allows you to parse the 'Accept-Charset' header and get an array of charsets sorted by their quality values.
const Accept = require('@hapi/accept');
const headers = { 'accept-charset': 'utf-8, iso-8859-1;q=0.5' };
const charsets = Accept.charsets(headers['accept-charset']);
console.log(charsets); // ['utf-8', 'iso-8859-1']
Parsing Accept-Encoding Header
This feature allows you to parse the 'Accept-Encoding' header and get an array of encodings sorted by their quality values.
const Accept = require('@hapi/accept');
const headers = { 'accept-encoding': 'gzip, deflate;q=0.8, br;q=0.6' };
const encodings = Accept.encodings(headers['accept-encoding']);
console.log(encodings); // ['gzip', 'deflate', 'br']
Matching Media Types
This feature allows you to match the best media type from a list of available types based on the 'Accept' header.
const Accept = require('@hapi/accept');
const headers = { 'accept': 'text/html, application/json;q=0.9, */*;q=0.8' };
const mediaType = Accept.mediaType(headers.accept, ['application/json', 'text/html']);
console.log(mediaType); // 'text/html'
Negotiator is a library for HTTP content negotiation. It provides similar functionalities to @hapi/accept, such as parsing and matching Accept, Accept-Charset, Accept-Encoding, and Accept-Language headers. However, @hapi/accept is part of the hapi ecosystem and may have better integration with other hapi modules.
Content-Type is a library for parsing and formatting media types. While it does not provide the full range of content negotiation features like @hapi/accept, it is useful for handling media type parsing and formatting in a more lightweight manner.
Readme
accept is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out hapi � they work even better together.
FAQs
HTTP Accept-* headers parsing
The npm package @hapi/accept receives a total of 943,370 weekly downloads. As such, @hapi/accept popularity was classified as popular.
We found that @hapi/accept demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.