JSPM

uint8-to-base64

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6197
  • Score
    100M100P100Q126487F
  • License ISC

A safe Uint8Array to base64 string converter

Package Exports

  • uint8-to-base64
  • uint8-to-base64/cjs/index.js
  • uint8-to-base64/esm/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uint8-to-base64) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

A safe Uint8Array to base64 string converter

Build Status Coverage Status

Social Media Photo by Suzanne D. Williams on Unsplash

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 strings
const encoded = encode(utf8Binary);

// it's just like any other string
console.log(encoded);

// decode converts base64 strings, encoded via this module,
// into their original Uint8Array representation
const 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.

global.btoa = str => Buffer.from(str).toString('base64');
global.atob = str => Buffer.from(str, 'base64').toString();

Looking for a drop in module that converts into utf-16 strings instead? Check uint8-to-utf16 out!