{"library":"negotiator","title":"HTTP Content Negotiation","description":"Negotiator is a lightweight, standalone utility for parsing and evaluating HTTP `Accept`, `Accept-Language`, `Accept-Encoding`, and `Accept-Charset` headers. It allows servers to determine the client's preferred content based on quality values (`q-factors`) specified in these headers. Primarily maintained by the `jshttp` organization, it serves as a core component for web frameworks like Express.js by abstracting complex RFC specifications for content negotiation. The current stable version is `1.0.0`. The package operates in a maintenance mode, with infrequent but significant major releases that often include breaking changes to align with evolving Node.js environments and best practices. It distinguishes itself by providing a robust and dependency-free solution for this specific HTTP concern.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install negotiator"],"cli":null},"imports":["import Negotiator from 'negotiator'","const Negotiator = require('negotiator')"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Negotiator from 'negotiator';\n\nconst mockRequest = {\n  headers: {\n    'accept': 'text/html, application/xhtml+xml, application/json;q=0.9, image/webp, */*;q=0.8',\n    'accept-language': 'en-US,en;q=0.9,es;q=0.7',\n    'accept-encoding': 'gzip, deflate, br;q=0.9, identity;q=0.5'\n  }\n};\n\nconst negotiator = new Negotiator(mockRequest);\n\nconsole.log('Preferred Media Types (all):', negotiator.mediaTypes());\nconsole.log('Preferred Media Type (available):', negotiator.mediaType(['application/json', 'text/plain']));\n\nconsole.log('Preferred Languages (all):', negotiator.languages());\nconsole.log('Preferred Language (available):', negotiator.language(['es', 'fr']));\n\nconsole.log('Preferred Encodings (all):', negotiator.encodings());\nconsole.log('Preferred Encoding (available):', negotiator.encoding(['gzip', 'br', 'identity']));\n\n/* Example Output:\nPreferred Media Types (all): [ 'text/html', 'application/xhtml+xml', 'application/json', 'image/webp', '*/*' ]\nPreferred Media Type (available): application/json\nPreferred Languages (all): [ 'en-US', 'en', 'es' ]\nPreferred Language (available): es\nPreferred Encodings (all): [ 'gzip', 'br', 'identity', 'deflate' ]\nPreferred Encoding (available): gzip\n*/","lang":"javascript","description":"Demonstrates initializing Negotiator with mock request headers and using its methods to determine preferred content types, languages, and encodings based on client preferences and available options.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}