v138 · javascript
Uint8Array to/from base64 and hex
base64 is a common way to represent arbitrary binary data as ASCII. JavaScript has Uint8Arrays to work with binary data, but no built-in mechanism to encode that data as base64, nor to take base64'd data and produce a corresponding Uint8Arrays. This is a proposal to fix that. It also adds methods for converting between hex strings and Uint8Arrays.
concepts
-
Uint8Array <-> Base64/Hex
First-class base64/hex methods on Uint8Array. Stop importing yet another encoder.
-
SRI fingerprint generator
Real end-to-end: fetch a script, SHA-384 hash, emit both
integrity="sha384-…"and a hex digest — new methods next to the legacybtoa(String.fromCharCode)for comparison. -
Format options lab
Every option exercised:
alphabet(base64 vs base64url),omitPadding, and the decoder'slastChunkHandling(loose / strict / stop-before-partial). Encode → decode → round-trip with five preset failure-mode inputs. -
Binary Converter
Type text or paste binary data and instantly see it as UTF-8 bytes, standard base64, URL-safe base64url, and hex. Decode base64 or hex back to text — a full round-trip using all four new native methods.
why it shipped
base64 is a common way to represent arbitrary binary data as ASCII. JavaScript has Uint8Arrays to work with binary data, but no built-in mechanism to encode that data as base64, nor to take base64'd data and produce a corresponding Uint8Arrays. This is a proposal to fix that. It also adds methods for converting between hex strings and Uint8Arrays.