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