{"name":"headers-polyfill","version":"3.0.3","description":"A native \"Headers\" class polyfill.","main":"lib/index.js","types":"lib","repository":{"type":"git","url":"https://github.com/mswjs/headers-polyfill"},"author":{"name":"Artem Zakharchenko"},"license":"MIT","scripts":{"clean":"rimraf lib","build":"yarn clean && tsc --build","test":"jest","prepublishOnly":"yarn test && yarn build"},"devDependencies":{"@types/jest":"^26.0.20","jest":"^26.6.3","rimraf":"^3.0.2","ts-jest":"^26.5.3","typescript":"^4.2.3"},"_id":"headers-polyfill@3.0.3","dist":{"shasum":"222bd9a6b5a1f610ad563473efb0d34a13eb7ebc","integrity":"sha512-Ak5m549Y+5vBtWNnIUcyARJjF0tQpINuy3+vOqG8tK/qjF0itYhAPgrzJc0zsZJh7AX8PalzICMPuWIqHpZlEA==","tarball":"http://registry-npm.ywwl.com/headers-polyfill/download/headers-polyfill-3.0.3.tgz","fileCount":36,"unpackedSize":32403,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiCQxfCRA9TVsSAnZWagAAnxEQAJdxg+sNGmSkvuwJw3q8\nG3PVtlJXo5aVbxBZhBkrW2wThiwQpeyuFFWjjH3kojRRRv3hMBYVGxs+/Dn6\nFfZDwopSXobKxp9f92pLenwy1OIVJponfKg2yVUDK6dmt5TdwsFMB9/Usadq\ntbxZ/fk57tAO1hEVxSTpBPd0CP5woqjEVEtBRuzRHY9ed0cKocMfiVdeQoPl\nySUjbGF0Zd6xya202A/lWpIasUMgy6rg7eTip8VkaMJxv0IJuQqfuAs5Rsk8\n4sS6hkfgM17ZKJEoVUSrFTUTVw4iHjNBvpo3S/FSfQCY/QjngFlgT4Pq9PiM\n9fO29RK0+XaNjtVUolSwwYak0Gtz9soouOrnRVikgakzlGnkdjA7G07tjojs\nIyWqgilGpftTnU2mDf8nTsmInNIdeKW9mIZoHaUk1fcHeY8CzslYgrLAh2v4\ny/rtYweB21ouUCFnSrCA1yz85HPhxlX1Q9a0Mxzh8NeY5/YMo0ClnGyMI2RF\nwyqPCqVqkItCc8V03TQkYBFGoMck+MTtoRMyKhXuGQJUCD3RZAHqq9s7uDpk\nmSAOABk/5kYJIEkW1dkWGwhrKGw69hGZ36G4ZBEO1sQ9gu/vnV1RuoZ05b0D\niPd08XYzBgf14XZc+UweCi4OhD4vY//qZsfuwk33UA4qZ3+nJoxmzYqtYPKo\nhrx4\r\n=xDHs\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDsGBHDmoklbjACsaeraEpc1F/blQPDN5QPevTmzJoouAiEA6jghsF0vSyVJH5m3w1Ghw1v3f43uqFqR6GUa+MxsAGg="}],"size":7428,"noattachment":false,"key":"/headers-polyfill/-/headers-polyfill-3.0.3.tgz"},"_npmUser":{"name":"kettanaito","email":"kettanaito@gmail.com"},"directories":{},"maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/headers-polyfill_3.0.3_1644760159198_0.11102997032789452"},"_hasShrinkwrap":false,"readme":"[![Published version](https://img.shields.io/npm/v/headers-polyfill.svg)](https://www.npmjs.com/package/headers-polyfill)\n\n# `headers-polyfill`\n\nA `Headers` class polyfill and transformation library.\n\n## Motivation\n\nVarious request issuing libraries utilize a different format of headers. This library chooses the [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) instance as the middle-ground between server and client, and provides functions to convert that instance to primitives and vice-versa.\n\n## Install\n\n```bash\nnpm install headers-polyfill\n```\n\n## Polyfill\n\nThis package exports the `Headers` class that polyfills the native [`window.Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) implementation. This allows you to construct and manage headers using the same API in non-browser environments.\n\n```js\nimport { Headers } from 'headers-polyfill'\n\nconst headers = new Headers({\n  Accept: '*/*',\n  'Content-Type': 'application/json',\n})\n\nheaders.get('accept') // \"*/*\"\n```\n\n## Methods\n\nThe `Headers` polyfill instance supports the same methods as the standard `Headers` instance:\n\n- [`.has()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/has)\n- [`.get()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/get)\n- [`.set()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/set)\n- [`.append()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/append)\n- [`.delete()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete)\n- [`.forEach()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach)\n- [`.getSetCookie()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie)\n\nAs well as the iterator methods:\n\n- [`.keys()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys)\n- [`.values()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/values)\n- [`.entries()`](https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries)\n\n## Transformations\n\n### `getRawHeaders()`\n\nReturns an object consisting of the header name/value pairs but preserving raw header names.\n\n```js\nconst headers = new Headers({\n  Accept: '*/*',\n  'Content-Type': 'application/json',\n})\n\nheaders.raw()\n// { \"Accept\": \"*/*\", \"Content-Type\": \"application/json\" }\n```\n\n### Headers ⭢ N\n\n- `headersToString: (h: Headers): string`\n\n```js\nimport { headersToString } from 'headers-polyfill'\n\nheadersToString(\n  new Headers({\n    connection: 'keep-alive',\n    'content-type': ['text/plain', 'image/png'],\n  })\n)\n// connetion: keep-alive\n// content-type: text/plain, image/png\n```\n\n- `headersToList: (h: Headers): Array<[string, string | string[]]>`\n\n```js\nimport { headersToList } from 'headers-polyfill'\n\nheadersToList(\n  new Headers({\n    connection: 'keep-alive',\n    'content-type': ['text/plain', 'image/png'],\n  })\n)\n// [['connection', 'keep-alive'], ['content-type', ['text/plain', 'image/png']]]\n```\n\n- `headersToObject: (h: Headers): Record<string, string | string[]>`\n\n```js\nimport { headersToObject } from 'headers-polyfill'\n\nheadersToObject(\n  new Headers({\n    connection: 'keep-alive',\n    'content-type': ['text/plain', 'image/png'],\n  })\n)\n// { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }\n```\n\n### N ⭢ Headers\n\n- `stringToHeaders: (s: string): Headers`\n\n```js\nimport { stringToHeaders } from 'headers-polyfill'\n\n\nconst stringToHeaders(`\nconnection: keep-alive\ncontent-type: text/plain, image/png\n`)\n// Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }\n```\n\n- `listToHeaders: (l: Array<[string, string | string[]]>): Headers`\n\n```js\nimport { listToHeaders } from 'headers-polyfill'\n\nlistToHeaders([\n  ['connection', 'keep-alive'],\n  ['content-type', ['text/plain', 'image/png']],\n])\n// Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }\n```\n\n- `objectToHeaders: (o: Record<string, string | string[] | undefined>): Headers`\n\n```js\nimport { objectToHeaders } from 'headers-polyfill'\n\nobjectToHeaders({\n  connection: 'keep-alive',\n  'content-type': ['text/plain', 'image/png'],\n})\n// Headers { connection: 'keep-alive', 'content-type': ['text/plain', 'image/png'] }\n```\n\n---\n\n## Utilities\n\n- `reduceHeadersObject: <R>(o: Record<string, string | string[]>, reducer: (acc: R, name: string, value: string | string[]) => R) => R`\n\n```js\nimport { reduceHeadersObject } from 'headers-polyfill'\n\nreduceHeadersObject <\n  HeadersObject >\n  ({\n    Accept: '*/*',\n    'Content-Type': ['application/json', 'text/plain'],\n  },\n  (headers, name, value) => {\n    headers[name.toLowerCase()] = value\n    return headers\n  },\n  {})\n// { 'accept': '*/*', 'content-type': ['application/json', 'text/plain'] }\n```\n\n- `appendHeader: (o: Record<string, string | string[]>, n: string, v: string | string[]): Record<string, string | string[]>`\n\n```js\nimport { appendHeader } from 'headers-polyfill'\n\nappendHeader(\n  { 'content-type': 'application/json' },\n  'content-type',\n  'text/plain'\n)\n// { 'content-type': ['application/json', 'text/plain']}\n```\n\n- `flattenHeadersList: (l: Array<[string, string | string[]]>): Array<string, string>`\n\n```js\nimport { flattenHeadersList } from 'headers-polyfill'\n\nflattenHeadersList([['content-type', ['text/plain', 'image/png']]])\n// ['content-type', 'text/plain, image/png']\n```\n\n- `flattenHeadersObject: (o: Record<string, string | string[]>): Record<string, string>`\n\n```js\nimport { flattenHeadersObject } from 'headers-polyfill'\n\nflattenHeadersObject({\n  'content-type': ['text/plain', 'image/png'],\n})\n// { 'content-type': 'text/plain, image/png' }\n```\n","publish_time":1644760159561,"_cnpm_publish_time":1644760159561,"dist-tags":{"latest":"5.0.1"}}