Skip to content

Instantly share code, notes, and snippets.

@jasminabasurita
Last active January 29, 2018 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasminabasurita/ac06033962498016feadc17ea30d4964 to your computer and use it in GitHub Desktop.
Save jasminabasurita/ac06033962498016feadc17ea30d4964 to your computer and use it in GitHub Desktop.
const vapidPublicKey =
"< Your Public VAPID Key Here >"
const convertedVapidKey = urlBase64ToUint8Array(vapidPublicKey)
function urlBase64ToUint8Array(base64String) {
const padding = "=".repeat((4 - base64String.length % 4) % 4)
const base64 = (base64String + padding).replace(/\-/g, "+").replace(/_/g, "/")
const rawData = window.atob(base64)
const outputArray = new Uint8Array(rawData.length)
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i)
}
return outputArray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment