-
-
Save bohdaq/65671948d571987f5dd8ff8001f379f4 to your computer and use it in GitHub Desktop.
used in pushManager.Subscribe to correctly encode the key to a Uint8Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function urlBase64ToUint8Array(base64String) { | |
const padding = '='.repeat((4 - base64String.length % 4) % 4); | |
const base64 = (base64String + padding) | |
.replace(/\-/g, '+') | |
.replace(/_/g, '/') | |
; | |
const rawData = window.atob(base64); | |
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment