Base64 and base64url to string or arraybuffer, and back. Node, Deno or browser.
npm install @hexagon/base64

Probably the only JavaScript base64 library you'll ever need!
Encode, decode and validate base64/base64url to string/arraybuffer and vice-versa. Works in Node, Deno and browser.

  

* Supports regular base64 and base64url
* Convert to/from string or arraybuffer
* Validate / identify base64 and base64url
* Works in Node.js >=4.0 (both require and import).
* Works in Deno >=1.16.
* Works in browsers as standalone, UMD or ES-module.
* Includes TypeScript typings.
``javascript
// Encode string as regular base64
const example1enc = base64.fromString("Hellö Wörld, how are you doing today?!");
console.log(example1enc);
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==
// Decode string as regular base64
const example1dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ==");
console.log(example1dec);
// > Hellö Wörld, how are you doing today?!
`
Full documentation available at base64.56k.guru
Node.js:
`bash`
npm install @hexagon/base64 --save
Deno (x):
`js`
import { base64 } from "https://deno.land/x/b64@2.0.3/src/base64.ts";
Deno (jsr.io):
`js`
import { base64 } from "jsr:@hexagon/base64";
For browser/cdn usage, refer to the documentation.
- __fromArrayBuffer(buffer, urlMode)__ - Encodes ArrayBuffer into base64 or base64url if urlMode(optional) is trueArrayBuffer
- __toArrayBuffer(str, urlMode)__ - Decodes base64url string (or base64url string if urlMode is true) to
- __fromString(str, urlMode)__ - Encodes String into base64 string(base64url string if urlMode is true)String
- __toString(str, urlMode)__ - Decodes base64 or base64url string to
- __validate(str, urlMode)__ - Returns true if String` str is valid base64/base64 dependending on urlMode
If you found this library helpful and wish to support its development, consider making a donation through Hexagon's GitHub Sponsors page. Your generosity ensures the library's continued development and maintenance.
The underlying code is loosely based on github.com/niklasvh/base64-arraybuffer
MIT