Skip to content

ungap/base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@ungap/base64

A polyfill for Uint8Array.fromBase64 and Uint8Array.prototype.toBase64.

In modern browsers and Node.js >= 25, this module is a no-op. Otherwise, it patches both the constructor and the prototype once.

This implementation relies on atob and btoa. On Node.js < 16, polyfill those globals before importing this module.

import 'https://esm.run/@ungap/base64';

const asBase64 = new TextEncoder().encode('hello base64!').toBase64();
// aGVsbG8gYmFzZTY0IQ==

const fromBase64 = new TextDecoder().decode(Uint8Array.fromBase64(asBase64));
// 'hello base64!'

API

  • Uint8Array.prototype.toBase64(options) — fully supports the optional options
  • Uint8Array.fromBase64(string, options) — supports only alphabet and lastChunkHandling: 'loose'; throws if lastChunkHandling is provided with any other value (options)

About

Uint8Array.fromBase64 and Uint8Array.prototype.toBase64 polyfill.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors