File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change 11const runningOnBrowser = typeof window !== 'undefined'
22
3- // Pad out with standard base64 required padding characters if missing
4- const base64AddPadding = base64String => {
5- const missingPadding = '=' . repeat ( ( 4 - base64String . length % 4 ) % 4 )
6- return base64String + missingPadding
7- }
8-
9- // Replace non-url compatible chars with base64 standard chars
10- const base64UrlDecode = base64UrlString => {
11- return base64UrlString
3+ const base64urlToBase64 = base64UrlString => {
4+ // Replace non-url compatible chars with base64 standard chars
5+ const base64 = base64UrlString
126 . replace ( / - / g, '+' )
137 . replace ( / _ / g, '/' )
8+
9+ // Pad out with standard base64 required padding characters if missing
10+ const missingPadding = '=' . repeat ( ( 4 - base64 . length % 4 ) % 4 )
11+
12+ return base64 + missingPadding
1413}
1514
16- const atob = data => {
15+ const base64Decode = data => {
1716 if ( runningOnBrowser ) {
18- return window . atob ( data )
17+ return atob ( data )
1918 }
2019 // atob polyfill for Node
2120 return Buffer . from ( data , 'base64' ) . toString ( 'binary' )
2221}
2322
2423const base64ToUint8Array = base64String => {
2524 // base64 sanitizing
26- const base64 = base64UrlDecode ( base64AddPadding ( base64String ) )
25+ const base64 = base64urlToBase64 ( base64String )
2726
2827 // base64 decoding
29- const rawData = atob ( base64 )
28+ const rawData = base64Decode ( base64 )
3029
3130 // Converting raw data to Uint8Array
3231 return Uint8Array . from ( rawData , char => char . charCodeAt ( 0 ) )
You can’t perform that action at this time.
0 commit comments