Skip to content

Instantly share code, notes, and snippets.

@malko
Created March 31, 2017 12:58
Show Gist options
  • Save malko/ff77f0af005f684c44639e4061fa8019 to your computer and use it in GitHub Desktop.
Save malko/ff77f0af005f684c44639e4061fa8019 to your computer and use it in GitHub Desktop.
used in pushManager.Subscribe to correctly encode the key to a Uint8Array
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)));
}
@mauricoder
Copy link

Saved my day! Thanks! :)

@bithavoc
Copy link

beautiful

@msjahun
Copy link

msjahun commented Jan 11, 2019

Thank you!

@kannanhassouna
Copy link

thanks

@lilfish
Copy link

lilfish commented Nov 8, 2019

Saved my life!

@migue802
Copy link

migue802 commented Jul 5, 2021

Tyyyyyyy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment