{"_id":"@andrew-pyle/basicauthheader","_rev":"1-55325795207366c6604d1807ef53287f","name":"@andrew-pyle/basicauthheader","dist-tags":{"latest":"0.3.0"},"versions":{"0.2.0":{"name":"@andrew-pyle/basicauthheader","version":"0.2.0","description":"Create Authorization HTTP headers. Compatible with `Headers()`, `Request()`, and `fetch()`.","keywords":["http","Basic Auth","Authorization","Header"],"type":"module","main":"index.js","types":"index.d.ts","scripts":{"format":"biome format index.js test.js --write","lint":"oxlint index.js && biome lint index.js","test":"npm run lint && node --test","tsc":"tsc index.js --allowJs --declaration --emitDeclarationOnly --skipLibCheck --target es2021","minify":"esbuild index.js --minify --outfile=index.min.js","build":"npm run tsc && npm run minify","prepublish":"npm run build"},"author":{"name":"Andrew Pyle"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/andrew-pyle/basicauthheader.git"},"devDependencies":{"@biomejs/biome":"1.3.1","esbuild":"^0.19.5","np":"^8.0.4","oxlint":"^0.0.14","typescript":"^5.2.2"},"engines":{"node":"*"},"_id":"@andrew-pyle/basicauthheader@0.2.0","gitHead":"37773dd6a61da44afb399c885433edce8a88f43d","bugs":{"url":"https://github.com/andrew-pyle/basicauthheader/issues"},"homepage":"https://github.com/andrew-pyle/basicauthheader#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-gRosgZdiT2fvebrIDfizSEeB2SR6O6vOkCEM4RUHC2WGlcgLCvrsLJbWHynUBIlBiN93hmToFvHRt1cmjUMZ+A==","shasum":"2cdcd3e5c42d1b7304dceb5ce8823447f805864e","tarball":"https://registry.npmjs.org/@andrew-pyle/basicauthheader/-/basicauthheader-0.2.0.tgz","fileCount":6,"unpackedSize":10263,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDt/8+SxpZWmFjLaIANXHmOemHp938jfpf85pl8fnd3LQIhAIud8Tzm2LiGHkN4l6zAkhS6Xw1buFPoKLk4onOvg1QR"}]},"_npmUser":{"name":"andrew-pyle","email":"andrew.pyle@icloud.com"},"directories":{},"maintainers":[{"name":"andrew-pyle","email":"andrew.pyle@icloud.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/basicauthheader_0.2.0_1698445043178_0.44721127211021683"},"_hasShrinkwrap":false},"0.3.0":{"name":"@andrew-pyle/basicauthheader","version":"0.3.0","description":"Create Authorization HTTP headers. Compatible with `Headers()`, `Request()`, and `fetch()`.","keywords":["http","Basic Auth","Authorization","Header"],"type":"module","main":"index.min.js","types":"index.d.ts","scripts":{"format":"biome format index.js test.js --write","lint":"oxlint index.js && biome lint index.js","test":"npm run lint && node --test","tsc":"tsc index.js --allowJs --declaration --emitDeclarationOnly --skipLibCheck --target es2021","minify":"esbuild index.js --minify --outfile=index.min.js","build":"npm run tsc && npm run minify","prepublish":"npm run build"},"author":{"name":"Andrew Pyle"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/andrew-pyle/basicauthheader.git"},"devDependencies":{"@biomejs/biome":"1.3.1","esbuild":"^0.19.5","np":"^8.0.4","oxlint":"^0.0.14","typescript":"^5.2.2"},"engines":{"node":"*"},"_id":"@andrew-pyle/basicauthheader@0.3.0","gitHead":"b0adfa26bde7f8db2931f94ef79803336e0103b9","bugs":{"url":"https://github.com/andrew-pyle/basicauthheader/issues"},"homepage":"https://github.com/andrew-pyle/basicauthheader#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-20OjLCb7tRUTGc4845lSmgKdDDO+Ht0rVY5jF31hICdtY+kxjzfM7XeaP0XJcROCPsuSKQotwn+rcd9jJaUtzA==","shasum":"dac30a8ae0370721e0c6f93d7836b89df9cfa6e7","tarball":"https://registry.npmjs.org/@andrew-pyle/basicauthheader/-/basicauthheader-0.3.0.tgz","fileCount":5,"unpackedSize":8104,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCoqSV1uQldqPRhGvueo4LbF11BPGrxw/lWjbMG9ODIcQIhAMlHvk3VoYd+LVaW0Y+oAvfQPc4OuRtkK+BaPs80pTyT"}]},"_npmUser":{"name":"andrew-pyle","email":"andrew.pyle@icloud.com"},"directories":{},"maintainers":[{"name":"andrew-pyle","email":"andrew.pyle@icloud.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/basicauthheader_0.3.0_1698445556081_0.01954106175921222"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-27T22:17:23.097Z","0.2.0":"2023-10-27T22:17:23.405Z","modified":"2023-10-27T22:25:56.569Z","0.3.0":"2023-10-27T22:25:56.387Z"},"maintainers":[{"name":"andrew-pyle","email":"andrew.pyle@icloud.com"}],"description":"Create Authorization HTTP headers. Compatible with `Headers()`, `Request()`, and `fetch()`.","homepage":"https://github.com/andrew-pyle/basicauthheader#readme","keywords":["http","Basic Auth","Authorization","Header"],"repository":{"type":"git","url":"git+https://github.com/andrew-pyle/basicauthheader.git"},"author":{"name":"Andrew Pyle"},"bugs":{"url":"https://github.com/andrew-pyle/basicauthheader/issues"},"license":"MIT","readme":"# Basic Authorization Header\nConstruct a Basic Authorization string for the `Authorization` HTTP Header according to [RFC 7617][7]:\n\n>If the user agent wishes to send the user-id \"Aladdin\" and password \"open sesame\", it would use the following header field:\n>```\n>Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n>```\n\n## Installation\n```bash\n$ npm i @andrew-pyle/basicauthheader\n```\n\n## Usage\nUses only standard JavaScript. Nothing Node.js-specific. Code provided as ES module only.\n```js\nimport { BasicAuth } from '@andrew-pyle/basicauthheader';\n// CommonJS environments can probably use import('@andrew-pyle/basicauthheader')\n\nconst username = \"Aladdin\";\nconst password = \"open sesame\";\n\n// Authorization Header String\nconst basicAuthString = new BasicAuth({ username, password }).toString(); \n// => \"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\"\n\n// Directly Compatible with Web APIs: Headers, Request, fetch\n\nconst headers = new Headers({\n  Authorization: new BasicAuth({ username, password })\n});\n// => Headers { authorization: \"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\" }\n\nconst request = new Request(\"https://example.com\", {\n  headers: {\n    Authorization: new BasicAuth({ username, password })\n  }\n});\n// => Response\n\nconst response = await fetch(\"https://example.com\", {\n  headers: {\n    Authorization: new BasicAuth({ username, password })\n  }\n});\n// => Response\n\n// Exposes Credentials Property\nconst base64EncodedCredentials = new BasicAuth({ username, password }).credentials;\n// => \"QWxhZGRpbjpvcGVuIHNlc2FtZQ==\"\n```\n\n## Base64 Encoding Strategy\n\n### Binary Encoding\nEncodes strings into a binary [`Uint8Array`][1] as UTF-8. For a discussion of the need for encoding as UTF-8, see [\"The Unicode Problem\" on MDN][4]. If another text encoding is necessary, Pull Requests are welcome.\n\n### Base64 Conversion\nThe UTF-8 binary data in the [`Uint8Array` (MDN)][1] is then encoded as Base64 by [`Uint8Array.prototype.toBase64()` (TC39)][2], currently a stage 2 TC39 Proposal, falling back to [`btoa()`][3] if the environment doesn't support or polyfill [`Uint8Array.prototype.toBase64()`][2].\n\n## References\n- See [`Uint8Array` on MDN][1]\n- See TC39 Proposal [\"Uint8Array to/from base64 and hex\"][2]\n- Problems for [`btoa()`][3] and Unicode in [\"The Unicode Problem\" on MDN][4]\n- Sindre Sorhus: [\"It's time to move from [Node.js] `Buffer` to `Uint8Array`\"](https://sindresorhus.com/blog/goodbye-nodejs-buffer)\n\n## Prior Art\n- [`basic-authorization-header` (npm)](https://www.npmjs.com/package/basic-authorization-header) \n  - Node.js Only. Rely on non-standard, global `Buffer` to base64 encode. This package uses the standard [`Uint8Array`][1] or the standard [`btoa()`][3] function.\n  - Use [deprecated `new Buffer(string)`][5], instead of [recommended `Buffer.from(string)`][6]. This package does not.\n- [`basic-auth-header` (npm)](https://www.npmjs.com/package/basic-auth-header)\n  - Node.js Only. Rely on non-standard, global `Buffer` to base64 encode. This package uses the standard [`Uint8Array`][1] or the standard [`btoa()`][3] function.\n  - Use [deprecated `new Buffer(string)`][5], instead of [recommended `Buffer.from(string)`][6]. This package does not.\n- [`http-auth-utils` (npm)](https://www.npmjs.com/package/http-auth-utils)\n  - Larger package: 1.8 kB minified & gzip (Tested at https://bundlephobia.com/package/http-auth-utils@5.0.1)\n  - Seems complicated.\n- [`@mitmaro/http-authorization-header` (npm)](https://www.npmjs.com/package/@mitmaro/http-authorization-header)\n  - Larger package: 1.9 kB minified & gzip (Tested at https://bundlephobia.com/package/@mitmaro/http-authorization-header@1.0.0)\n  - Does not appear to perform the Base64 encoding of credentials—It is left to the caller to perform the encoding.\n    \n\n\n[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\n[2]: https://github.com/tc39/proposal-arraybuffer-base64\n[3]: https://developer.mozilla.org/en-US/docs/Web/API/btoa\n[4]: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem\n[5]: https://nodejs.org/api/buffer.html#new-bufferstring-encoding\n[6]: https://nodejs.org/api/buffer.html#static-method-bufferfromstring-encoding\n[7]: https://datatracker.ietf.org/doc/html/rfc7617#section-2","readmeFilename":"README.md"}