Compatible with any binary data and every modern JS engine.
import {encode, decode} from 'uint8-to-base64';// const {encode, decode} = require('uint8-to-base64');const utf8Binary = new Uint8Array(anyArrayBuffer);// encode converts Uint8Array instances to base64 stringsconst encoded = encode(utf8Binary);// it's just like any other stringconsole.log(encoded);// decode converts base64 strings, encoded via this module,// into their original Uint8Array representationconst decoded = decode(encoded);console.assert( JSON.stringify([...utf8Binary]) === JSON.stringify([...decoded]), 'safe Uint8Array to utf-16 conversion');
Please note this module requires global atob and btoa in NodeJS < 16, polyfilled in old tests in here as such.