{"name":"headers-polyfill","version":"3.0.7","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":"473e50bc3ab16e18d4802e63fe39b92dd184e45f","bugs":{"url":"https://github.com/mswjs/headers-polyfill/issues"},"homepage":"https://github.com/mswjs/headers-polyfill#readme","_id":"headers-polyfill@3.0.7","_nodeVersion":"12.22.7","_npmVersion":"6.14.15","dist":{"integrity":"sha512-JoLCAdCEab58+2/yEmSnOlficyHFpIl0XJqwu3l+Unkm1gXpFUYsThz6Yha3D6tNhocWkCPfyW0YVIGWFqTi7w==","shasum":"725c4f591e6748f46b036197eae102c92b959ff4","tarball":"http://registry-npm.ywwl.com/headers-polyfill/download/headers-polyfill-3.0.7.tgz","fileCount":32,"unpackedSize":32802,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiQQO5ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqZhA//QCOe0NbhlYlICWDwHVZTNO4s10j2LGVIHJy3YILYa/QamcF5\r\nwI6BrAToDfXzUD1VfI38EGKVzZ4UjxBhP0yFlg2QnZLgkocMyulQyE2vN6zx\r\nItGVCIQpMmBt+2qFy1n9dP+t0MX/euK5XRasmNfvU9pry3vLumUEi8K530fY\r\nU7/ATt6AIBmlSviu0Bf2rmioCJmiyOslErubAYG8H7LMjvn69tc/YAfwef7R\r\n2RePokqmLuJfMdEEagrvb5SexHPQpyWbbSFqG3FJwYjQgeR6tZWhcWgysvMt\r\nkJ6BTwm+fq1n3QrB1RgUkdK55EPRrIXbSvHJvD5YK7vYO4zcDRtshzlTRAXt\r\n3np+oXAL/8n7ZF7B5tH14eFLXcmHdl9CPZeBjT87+9uTmpkheLaijd29adVU\r\nvYTby3VOwknuOwLzhPLGENhinGGpa1fca1NC5oVJfzglK6iOFWA/BDr7rCUi\r\nbS/uWIdvhPZtYaoD8xXnsSha4GlA0z8Dm1hwcv/v/BKiZaHFG91DtwRlzGZp\r\nq5kdOo7IG9536b3OzfVq7n3Q6RBCrcTV1OsOveKU5wtzBBy12bWJXf50cuq6\r\nDTgMJ5052frdL0A5VZnjUVwtGBce2RgBb/lPdXgWz40ZzNR9ht84loAZkaqH\r\nIYW2THAoxhuCfG3Rc2CtF/xiBYORIYAfKu0=\r\n=KMd5\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEdAbr2hcF7fXinNhsdlX/AmMhiczyIuegreHsT18eOZAiEA1HAqD6XLRv1nwqnBncNtyMIgajwIxmCo9svmYKNl3i0="}],"size":7460,"noattachment":false,"key":"/headers-polyfill/-/headers-polyfill-3.0.7.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.7_1648427960691_0.37264077991855693"},"_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":1648427961004,"_cnpm_publish_time":1648427961004,"dist-tags":{"latest":"5.0.1"}}