{"_id":"base64-url@3.0.1","bugs":{"url":"https://github.com/joaquimserafim/base64-url/issues"},"dist":{"shasum":"ca0fd3b3b7c6714fb8803fd4b22b1fb0559e5cfe","tarball":"http://registry-npm.ywwl.com/base64-url/download/base64-url-3.0.1.tgz","fileCount":9,"integrity":"sha512-hbYD+8sOtUDMHgt/Bl97u21wFZT5FbU/uSq+ceJCrvmGoJ4/gPIfTFPpfCql2kn3+qp2ANe/MOkLGDSJ/otreg==","signatures":[{"sig":"MEUCIQCwRVPbKor87JLAKVSiLRfVAYP9OyOnLNcAwjc7QDaO/gIgVvhUSJwoa+4axrRCKxGjvma1fb3dm169cM68faCSwAo=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCW91Ar6YrCl9wun1EU6u7jOcID6zPWXtdcQ6nafIV9BQIhAPEmEY52xNgXVnkw0cA+G75gqz9cbVPlSAWj5wMUxt85"}],"unpackedSize":32721,"size":8323,"noattachment":false,"key":"/base64-url/-/base64-url-3.0.1.tgz"},"main":"./dist/index.cjs","name":"base64-url","type":"module","types":"./dist/index.d.cts","author":{"name":"@joaquimserafim"},"module":"./dist/index.mjs","engines":{"node":">=24"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"./package.json":"./package.json"},"gitHead":"5b7297a834f8e5ab43c0deecf72669776aafcbca","license":"ISC","scripts":{"lint":"biome check .","test":"vitest run","build":"tsup && node -e \"require('node:fs').renameSync('dist/index.d.ts', 'dist/index.d.mts')\"","check":"pnpm typecheck && pnpm lint && pnpm test:coverage && pnpm build && pnpm test:package","format":"biome check --write .","prepare":"node --run build","test:git":"node test/git-install.mjs","typecheck":"tsc --noEmit","test:watch":"vitest","test:package":"node test/package.mjs","test:coverage":"vitest run --coverage","prepublishOnly":"pnpm check"},"version":"3.0.1","_npmUser":{"name":"quim","email":"joaquim.serafim@gmail.com"},"homepage":"https://github.com/joaquimserafim/base64-url#readme","keywords":["base64","base64url","esm","typescript"],"overrides":{"tsup":{"esbuild":"0.28.1"}},"repository":{"url":"git+https://github.com/joaquimserafim/base64-url.git","type":"git"},"_npmVersion":"11.19.0","description":"Base64url encoding, decoding, and canonical validation for Node.js only (24+)","directories":{},"maintainers":[{"name":"quim","email":"joaquim.serafim@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.21.0","_hasShrinkwrap":false,"packageManager":"pnpm@10.34.6","devDependencies":{"tsup":"^8.5.1","vitest":"^4.1.7","typescript":"^6.0.3","@types/node":"^24.19.1","@biomejs/biome":"^2.5.15","@vitest/coverage-v8":"^4.1.7"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/base64-url_3.0.1_1791322096045_0.42380624621047946"},"readme":"# base64-url\n\n[![CI](https://github.com/joaquimserafim/base64-url/actions/workflows/ci.yml/badge.svg)](https://github.com/joaquimserafim/base64-url/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/base64-url.svg)](https://www.npmjs.com/package/base64-url)\n\nBase64url encoding, decoding, canonical validation, and Base64 conversion for **Node.js only**.\n\nRequires **Node.js 24 or newer**. Zero runtime dependencies. Ships ESM and CommonJS builds with TypeScript declarations for each module format.\n\nThis package uses Node's built-in `Buffer` API. **Browser runtimes, including Angular client-side applications, are not supported.** ESM support lets Node.js applications use `import`; it does not add browser support.\n\n## Install\n\n```sh\nnpm install base64-url\n# or\npnpm add base64-url\n```\n\n## Size\n\nZero runtime dependencies. What ships in the npm tarball:\n\n| What | Raw | Gzipped |\n| --- | ---: | ---: |\n| **ESM runtime** (`index.mjs`) | 1 890 B | 705 B |\n| **CJS runtime** (`index.cjs`) | 2 154 B | 795 B |\n| **Types** (`.d.mts` / `.d.cts`) | 4 232 B | 1 472 B |\n| **Sourcemaps** (debug-only) | 12 028 B | 3 977 B |\n\nYour import style selects the ESM or CommonJS build.\n\nGzipped sizes use Node's default gzip settings. Types and sourcemaps show the sum of both files, compressed individually.\n\n## Usage\n\n### ES modules\n\n```js\nimport base64url, { encode, decode, escape, unescape } from \"base64-url\";\n\nencode(\"Node.js is awesome.\");\n// \"Tm9kZS5qcyBpcyBhd2Vzb21lLg\"\n\ndecode(\"Tm9kZS5qcyBpcyBhd2Vzb21lLg\");\n// \"Node.js is awesome.\"\n\nescape(\"+/8=\");\n// \"-_8\"\n\nunescape(\"-_8\");\n// \"+/8=\"\n\n// The default export exposes all seven methods.\nbase64url.encode(\"hello\");\n// \"aGVsbG8\"\n```\n\n### CommonJS\n\n```js\nconst base64url = require(\"base64-url\");\n// Or: const { encode, decode } = require(\"base64-url\");\n\nbase64url.encode(\"hello\");\n// \"aGVsbG8\"\n```\n\n### Bytes and custom encodings\n\n```js\nimport { Buffer } from \"node:buffer\";\nimport { encode, decode } from \"base64-url\";\n\nencode(Buffer.from([251, 255]));\n// \"-_8\"\n\nencode(new Uint8Array([251, 255]));\n// \"-_8\"\n\nencode(\"fbff\", \"hex\");\n// \"-_8\"\n\ndecode(\"-_8\", \"hex\");\n// \"fbff\"\n\nencode(\"café\");\n// \"Y2Fmw6k\" (UTF-8)\n\nencode(\"café\", \"latin1\");\n// \"Y2Fm6Q\"\n```\n\n### Canonical validation and strict decoding\n\n```js\nimport { isCanonical, decodeStrict } from \"base64-url\";\n\nisCanonical(\"Zg\");\n// true\n\nisCanonical(\"Zh\");\n// false: nonzero unused bits, even though Node decodes it to \"f\"\n\nisCanonical(\"Zg==\");\n// false: padding is outside this package's canonical format\n\ndecodeStrict(\"Zg\");\n// \"f\"\n\ndecodeStrict(\"Zh\");\n// throws SyntaxError\n```\n\n### Decoding binary data\n\n```js\nimport { decodeBytes, encode } from \"base64-url\";\n\nconst bytes = decodeBytes(\"-_8\");\n// Uint8Array [251, 255]\n\nencode(bytes);\n// \"-_8\"\n```\n\n## API\n\n| Method | Input | Returns |\n| --- | --- | --- |\n| `encode(input, encoding?)` | A string, `Buffer`, or `Uint8Array` | Unpadded Base64url string |\n| `decode(input, encoding?)` | Base64url or standard Base64 string | Decoded string |\n| `decodeBytes(input)` | Base64url or standard Base64 string | Decoded bytes as a plain `Uint8Array` |\n| `isCanonical(value)` | Any value | Whether it is a canonical, unpadded Base64url string |\n| `decodeStrict(input, encoding?)` | Canonical, unpadded Base64url string | Decoded string; throws for non-canonical input |\n| `escape(input)` | Base64 string | String with `+` changed to `-`, `/` to `_`, and `=` removed |\n| `unescape(input)` | Base64url string | Standard Base64 alphabet with padding restored |\n\n`encoding` defaults to `\"utf8\"`. For `encode`, it specifies the input string's encoding and is ignored for byte inputs. For `decode` and `decodeStrict`, it specifies the output string's encoding. Supported values are `ascii`, `utf8`, `utf-8`, `utf16le`, `utf-16le`, `ucs2`, `ucs-2`, `base64`, `base64url`, `latin1`, `binary`, and `hex`. Encoding handling follows Node's `Buffer` API.\n\n`decode` and `decodeBytes` follow Node's permissive Base64 decoding behavior: they accept either alphabet, optional padding, whitespace, and other content Node ignores. They do not validate the encoded form. `escape` and `unescape` transform strings without validating them.\n\nAll three decoders require a primitive string and throw `TypeError` for every other input type, including `Buffer`, `Uint8Array`, and boxed `String` objects. If a Buffer contains encoded text, convert it first: `decode(value.toString(\"utf8\"))`.\n\n`isCanonical` checks the exact unpadded format produced by `encode`: only `A–Z`, `a–z`, `0–9`, `-`, and `_`, a valid length, and zero unused trailing bits. It returns `false` for non-strings, padding, whitespace, junk, and aliases such as `\"Zh\"` for `\"Zg\"`. These unused-bit rules come from [RFC 4648's canonical encoding requirements](https://www.rfc-editor.org/rfc/rfc4648.html#section-3.5).\n\n`decodeStrict` applies the same check and throws `SyntaxError` for a non-canonical string. Strictness applies to the Base64url representation, not to UTF-8 validity: `decodeStrict(\"_w\")` returns the replacement character `\"\\ufffd\"`, while `decodeStrict(\"_w\", \"hex\")` returns `\"ff\"`.\n\n`decodeBytes` preserves arbitrary binary data without converting it to text and returns a new, independent `Uint8Array`. For strict binary decoding, check `isCanonical(input)` before calling `decodeBytes(input)`.\n\nThe empty string is canonical. `isCanonical(\"\")` returns `true`, `decodeBytes(\"\")` returns an empty byte array, and the other methods return an empty string for empty input.\n\n### TypeScript\n\n```ts\nimport { decodeBytes, encode, isCanonical, type Encoding } from \"base64-url\";\n\nconst encoding: Encoding = \"hex\";\nconst result: string = encode(\"fbff\", encoding);\n\nconst input: unknown = \"-_8\";\nif (typeof input === \"string\" && isCanonical(input)) {\n  const bytes = decodeBytes(input);\n}\n```\n\nCommonJS TypeScript consumers can use `import base64url = require(\"base64-url\")`. The package supplies separate `.d.mts` and `.d.cts` declarations. Its public types do not require global Node types or an additional `@types` package.\n\nOn TypeScript 5.7 and newer, the inferred `decodeBytes` result retains its `ArrayBuffer` backing type. Older supported compilers infer plain `Uint8Array`. In both cases, the result and its `.subarray()` results can be passed directly to Blob and WebCrypto APIs.\n\n## Migrating from v2\n\n- Upgrade to Node.js 24 or newer.\n- Existing `require(\"base64-url\")` calls and the four method names remain supported. String encodings, padding transformations, and permissive decoding behavior are preserved.\n- ESM consumers can use named imports or the default import.\n- `decode` now rejects all non-string inputs with `TypeError` instead of implicitly coercing them. This includes numbers, booleans, objects, `Buffer`, and `Uint8Array`. For a Buffer containing encoded text, use `decode(value.toString(\"utf8\"))`. Malformed strings still follow Node's permissive decoding behavior.\n- CommonJS exports now include an enumerable `default` property and a non-enumerable `__esModule` marker. The `.default` object holds the same function references, but is separate from the `require()` result. Replacing a method on one object does not replace it on the other.\n- Browser runtimes are unsupported. Existing browser bundles that relied on Buffer polyfills may no longer build or run: v3 imports Node's `Buffer` and uses its native `base64url` encoding, which older polyfills may not implement.\n- Import from `\"base64-url\"`. Internal paths such as `\"base64-url/index.js\"` are no longer public entry points. `\"base64-url/package.json\"` remains available.\n- TypeScript declarations are included. Remove a separate `@types/base64-url` installation if you previously used one.\n\n## Native Node.js alternative\n\nFor simple encoding and decoding, you can use Node's built-in [`Buffer` API](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) without this package:\n\n```js\nimport { Buffer } from \"node:buffer\";\n\nconst encoded = Buffer.from(\"hello\", \"utf8\").toString(\"base64url\");\n// \"aGVsbG8\"\n\nconst decoded = Buffer.from(encoded, \"base64url\").toString(\"utf8\");\n// \"hello\"\n```\n\n## Development\n\nUse the pnpm version pinned in `package.json`:\n\n```sh\npnpm install\npnpm check\n```\n\n| Command | Purpose |\n| --- | --- |\n| `pnpm typecheck` | Check source and test types |\n| `pnpm lint` | Check formatting and lint rules without modifying files |\n| `pnpm format` | Apply formatting and safe lint fixes |\n| `pnpm test` | Run unit tests |\n| `pnpm test:watch` | Run tests in watch mode |\n| `pnpm test:coverage` | Enforce 100% statement, branch, function, and line coverage |\n| `pnpm build` | Build ESM, CommonJS, declarations, and source maps in `dist/` |\n| `pnpm test:package` | Pack and install the build in a temporary consumer, then verify runtime and TypeScript imports |\n| `pnpm test:git` | Install a temporary Git snapshot with npm and verify that it builds and imports correctly; requires Git and registry access unless dependencies are cached |\n| `pnpm check` | Run type, lint, coverage, build, and packed-package checks |\n\nCI runs `pnpm check` on Node 24.0.0, the latest Node 24 release, and the current Node release. The latest Node 24 job also runs `pnpm test:git`. Coverage reports are generated locally in `coverage/`; no external coverage token is needed.\n\nBefore publishing, run `pnpm check` and `pnpm test:git`. The `prepare` script builds `dist/` during local dependency installation, packing, and npm Git dependency installation. Registry packages ship the prebuilt files. Publishing requires pnpm and runs `pnpm check` through `prepublishOnly`. Only `dist/`, the README, license, and package metadata are published.\n\n## Alternatives\n\n- [base64url](https://github.com/brianloveswords/base64url)\n\n## License\n\nISC © 2014-2026 [@joaquimserafim](https://github.com/joaquimserafim).\n","publish_time":1791322096124,"_cnpm_publish_time":1791322096124,"dist-tags":{"latest":"3.0.1"}}