{"type":"module","name":"headers-polyfill","version":"5.0.1","description":"A native \"Headers\" class polyfill.","main":"./lib/index.cjs","module":"./lib/index.mjs","exports":{".":{"require":{"types":"./lib/index.d.cts","default":"./lib/index.cjs"},"default":{"types":"./lib/index.d.mts","default":"./lib/index.mjs"}}},"repository":{"type":"http","url":"git+https://github.com/mswjs/headers-polyfill.git"},"author":{"name":"Artem Zakharchenko"},"license":"MIT","devDependencies":{"@ossjs/release":"^0.10.1","jsdom":"^28.1.0","publint":"^0.3.18","tsdown":"^0.21.0","typescript":"^5.9.3","vitest":"^4.0.18"},"dependencies":{"@types/set-cookie-parser":"^2.4.10","set-cookie-parser":"^3.0.1"},"scripts":{"start":"tsdown --watch","build":"tsdown","test":"vitest","lint":"publint","release":"release publish"},"_id":"headers-polyfill@5.0.1","bugs":{"url":"https://github.com/mswjs/headers-polyfill/issues"},"homepage":"https://github.com/mswjs/headers-polyfill#readme","_integrity":"sha512-1TJ6Fih/b8h5TIcv+1+Hw0PDQWJTKDKzFZzcKOiW1wJza3XoAQlkCuXLbymPYB8+ZQyw8mHvdw560e8zVFIWyA==","_resolved":"/tmp/49ffbf0b0dbbb0d9174c6646f3e0fe7d/headers-polyfill-5.0.1.tgz","_from":"file:headers-polyfill-5.0.1.tgz","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-1TJ6Fih/b8h5TIcv+1+Hw0PDQWJTKDKzFZzcKOiW1wJza3XoAQlkCuXLbymPYB8+ZQyw8mHvdw560e8zVFIWyA==","shasum":"9554eb2892b666db1c7a3380a91b6cfd467a6b19","tarball":"http://registry-npm.ywwl.com/headers-polyfill/download/headers-polyfill-5.0.1.tgz","fileCount":41,"unpackedSize":112642,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/headers-polyfill@5.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHv8+NzXFFfjQFqBwUN1OM9pCR9ATJbpPRiZns4OiluEAiAPG3VuYMObjvoTof3YJ2UrPyOYH1X7tZjMnb/xEo3ogA=="}],"size":19335,"noattachment":false,"key":"/headers-polyfill/-/headers-polyfill-5.0.1.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:08c042bd-58b0-4674-83da-d7493d64f426"}},"directories":{},"maintainers":[{"name":"kettanaito","email":"kettanaito@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/headers-polyfill_5.0.1_1772703866151_0.8804247557916203"},"_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":1772703866283,"_cnpm_publish_time":1772703866283,"dist-tags":{"latest":"5.0.1"}}