{"name":"headers-polyfill","version":"3.0.6","description":"A native \"Headers\" class polyfill.","main":"lib/index.js","types":"lib","repository":{"type":"git","url":"git+https://github.com/mswjs/headers-polyfill.git"},"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"},"gitHead":"36488bfc557dba026ea8c7f3c0f86f3c38d93c19","bugs":{"url":"https://github.com/mswjs/headers-polyfill/issues"},"homepage":"https://github.com/mswjs/headers-polyfill#readme","_id":"headers-polyfill@3.0.6","_nodeVersion":"12.22.7","_npmVersion":"6.14.15","dist":{"integrity":"sha512-bkfRqU/NFMkVRC51B/fQ6qeTno4oZKl3YJyIio3mVzOQ64Z6Pbe3WAu823nHld437ycTHF9Zq3PnUV6JYzvZTQ==","shasum":"657c2f60e54aa19154be5cacdd50b40cf8ac4a4f","tarball":"http://registry-npm.ywwl.com/headers-polyfill/download/headers-polyfill-3.0.6.tgz","fileCount":32,"unpackedSize":32533,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiQQE1ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmohJA/8DCB5nL0gnbb/UeUGbINWieGEqs5YrvejTScIQWBHWo0UWadh\r\n0YAhW5Eef825vltRT+//TLixcw+Fh/p7DYyiQY5f2XbocOGg2by9m7z0R5hQ\r\nywrdLTcTunYs1hFVMBnGMHGyWo2zwKCrVhPAesG1e1YVrtbHyHzfOiKFHr/a\r\nffH/O+tpp+XUXO1Ou/Yrz47gmbcggGlDbZSHR5gDRcQRfBlShguV9WvNBYXv\r\nffS33pGQ3ZJwXaa6N5O0g/dwtX8tzZpLUc7IZ1AqpAkZNWtPjAsGeXgvhu9h\r\nb8W6+iNcYNn5qlocGAKfDwtGJEhdzHGzFHVaIV1v12ifKbcc2D2ntrj+22p2\r\n9ko+aL2ACX4vI2UZg5uNqF3MAD7LYyWu+nfQ44GyxTuznhakRU/Nn04x3J/J\r\nrSccBh8loq7eA1Mcv0K14dawytGtmWNVZ1SjrC77hMwGl1x3iyhr7OhlByj1\r\nvqpnN+Vb4mfwHBrzacw/92m36TJ6x6VYBmON4ryglU8txc6T4r3K1t3fqdhN\r\neT/0+UzH2IRfy0nL9MfQDvsYMxOnp0qRMi2CqsRjA5Q4fAvWBU3A17LZBTPZ\r\nFfmdLe1aMPDvgJyoxoLcMWjhyGGfHkOVw1SSF0gtRXbJVKwMhYO7G4bkb9WK\r\n2bYGoQcngk9Ddyc9qHmfPt0utZGcDiePMog=\r\n=K0v/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCyRXvwgvIfJDhMGngLdr8GPXywZ+hS773zP1Z2n0bvhgIgfinpDFjL4QI4x20xEGpTnmwW53/uPbWMLK6FRqiGYgY="}],"size":7325,"noattachment":false,"key":"/headers-polyfill/-/headers-polyfill-3.0.6.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.6_1648427317455_0.0900865949651195"},"_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":1648427317611,"_cnpm_publish_time":1648427317611,"dist-tags":{"latest":"5.0.1"}}