{"id":18317885,"url":"https://github.com/idiocc/negotiator","last_synced_at":"2025-04-09T13:51:07.166Z","repository":{"id":57113707,"uuid":"184944525","full_name":"idiocc/negotiator","owner":"idiocc","description":"[fork] HTTP Content Negotiation In ES6.","archived":false,"fork":false,"pushed_at":"2019-05-05T06:37:33.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-01T23:42:36.790Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://idio.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiocc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-04T21:08:54.000Z","updated_at":"2019-05-05T06:37:35.000Z","dependencies_parsed_at":"2022-08-21T23:20:35.509Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/negotiator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fnegotiator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fnegotiator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fnegotiator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fnegotiator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/negotiator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054218,"owners_count":21039951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T18:07:47.066Z","updated_at":"2025-04-09T13:51:07.139Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @goa/negotiator\n\n[![npm version](https://badge.fury.io/js/%40goa%2Fnegotiator.svg)](https://npmjs.org/package/@goa/negotiator)\n\n`@goa/negotiator` is a [fork](https://github.com/jshttp/negotiator) of HTTP Content Negotiation In ES6 And Optimised With A JavaScript Compiler For The Best Performance.\n\nThe original module has been updated to be used in [`@goa/koa`](https://artdecocode.com/goa/): _Koa_ web server compiled with _Google Closure Compiler_ using [**Depack**](https://artdecocode.com/depack/) into a single file library (0 dependencies).\n\n```sh\nyarn add @goa/negotiator\n```\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [class Negotiator](#class-negotiator)\n- [`constructor(request: IncomingMessage): Negotiator`](#constructorrequest-incomingmessage-negotiator)\n  * [`_goa.Negotiator`](#type-_goanegotiator)\n- [Copyright](#copyright)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/0.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its default function:\n\n```js\nimport Negotiator from '@goa/negotiator'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## class Negotiator\n\nInstances of this class will allow to negotiate languages, charsets, media types and encodings.\n\n## `constructor(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`request: IncomingMessage,`\u003cbr/\u003e`): Negotiator`\n\nCreates a new instance based on the request from the client.\n\n```js\n/* alanode example/ */\nimport aqt from '@rqt/aqt'\nimport { createServer } from 'http'\nimport Negotiator from '@goa/negotiator'\n\nconst s = createServer((message, response) =\u003e {\n  const n = new Negotiator(message)\n\n  const availableEncodings = ['identity', 'gzip']\n  console.log('encodings', n.encodings())\n  console.log('available encodings', n.encodings(availableEncodings))\n  console.log('encoding', n.encoding(availableEncodings), '\\n')\n\n  const availableLanguages = ['en', 'es', 'fr']\n  console.log('languages', n.languages())\n  console.log('available languages', n.languages(availableLanguages))\n  console.log('language', n.language(availableLanguages), '\\n')\n\n  const availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']\n  console.log('charsets', n.charsets())\n  console.log('available charsets', n.charsets(availableCharsets))\n  console.log('charset', n.charset(availableCharsets), '\\n')\n\n  const availableMediaTypes = ['text/html', 'text/plain', 'application/json']\n  console.log('media types', n.mediaTypes())\n  console.log('available media types', n.mediaTypes(availableMediaTypes))\n  console.log('media type', n.mediaType(availableMediaTypes))\n\n  response.end()\n})\n\ns.listen(0, async () =\u003e {\n  const url = `http://localhost:${s.address().port}`\n  await aqt(url, {\n    headers: {\n      'accept-encoding': 'gzip, compress;q=0.2, identity;q=0.5',\n      'accept-charset': 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2',\n      'accept-language': 'en;q=0.8, es, pt',\n      accept: 'text/html, application/*;q=0.2, image/jpeg;q=0.8',\n    },\n  })\n  s.close()\n})\n```\n```\nencodings [ 'gzip', 'deflate', 'identity' ]\navailable encodings [ 'gzip', 'identity' ]\nencoding gzip \n\nlanguages [ 'es', 'pt', 'en' ]\navailable languages [ 'es', 'en' ]\nlanguage es \n\ncharsets [ 'utf-8', 'iso-8859-1', 'utf-7' ]\navailable charsets [ 'utf-8', 'iso-8859-1' ]\ncharset utf-8 \n\nmedia types [ 'text/html', 'image/jpeg', 'application/*' ]\navailable media types [ 'text/html', 'application/json' ]\nmedia type text/html\n```\n\n__\u003ca name=\"type-_goanegotiator\"\u003e`_goa.Negotiator`\u003c/a\u003e__: HTTP Content Negotiation In ES6.\n\n|      Name       |                              Type                              |                                             Description                                             |\n| --------------- | -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |\n| __charset*__    | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): string\u003c/em\u003e               | Returns the most preferred charset from the client.                                                 |\n| __charsets*__   | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): !Array\u0026lt;string\u0026gt;\u003c/em\u003e | Returns an array of preferred charsets ordered by the client preference.                            |\n| __encoding*__   | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): string\u003c/em\u003e               | Returns the most preferred encoding from the client.                                                |\n| __encodings*__  | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): !Array\u0026lt;string\u0026gt;\u003c/em\u003e | Returns an array of preferred encodings ordered by the client preference.                           |\n| __language*__   | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): string\u003c/em\u003e               | Returns the most preferred language from the client.                                                |\n| __languages*__  | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): !Array\u0026lt;string\u0026gt;\u003c/em\u003e | Returns an array of preferred languages ordered by priority from a list of available languages.     |\n| __mediaType*__  | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): string\u003c/em\u003e               | Returns the most preferred media type from the client.                                              |\n| __mediaTypes*__ | \u003cem\u003efunction(!Array\u0026lt;string\u0026gt;=): !Array\u0026lt;string\u0026gt;\u003c/em\u003e | Returns an array of preferred media types ordered by priority from a list of available media types. |\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/2.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\nThe original programming work, documentation and NPM package by [Federico Romero, Isaac Z. Schlueter, Douglas Christopher Wilson](https://github.com/jshttp/negotiator).\n\n---\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://artd.eco\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\" alt=\"Art Deco\" /\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e© \u003ca href=\"https://artd.eco\"\u003eArt Deco\u003c/a\u003e for \u003ca href=\"https://idio.cc\"\u003eIdio\u003c/a\u003e 2019\u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://idio.cc\"\u003e\n        \u003cimg src=\"https://avatars3.githubusercontent.com/u/40834161?s=100\" width=\"100\" alt=\"Idio\" /\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif\"\n          alt=\"Tech Nation Visa\" /\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003ca href=\"https://www.technation.sucks\"\u003eTech Nation Visa Sucks\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/-1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fnegotiator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Fnegotiator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fnegotiator/lists"}