Skip to content

Instantly share code, notes, and snippets.

@Klerith
Klerith / urlBase64ToUint8array.js
Last active April 7, 2024 14:16
web-push: urlBase64ToUint8array
// Web-Push
// Public base64 to Uint
function urlBase64ToUint8Array(base64String) {
var padding = '='.repeat((4 - base64String.length % 4) % 4);
var base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/');
var rawData = window.atob(base64);
var outputArray = new Uint8Array(rawData.length);