6745 |
20 May 22 |
nicklas |
'use strict'; |
6745 |
20 May 22 |
nicklas |
2 |
|
6745 |
20 May 22 |
nicklas |
var WAUtils = function() |
6745 |
20 May 22 |
nicklas |
4 |
{ |
6745 |
20 May 22 |
nicklas |
var utils = {}; |
6745 |
20 May 22 |
nicklas |
6 |
|
6745 |
20 May 22 |
nicklas |
7 |
/* |
6745 |
20 May 22 |
nicklas |
Encode a ByteArray object to Base64-urlencocding. |
6745 |
20 May 22 |
nicklas |
9 |
*/ |
6745 |
20 May 22 |
nicklas |
utils.byteArrayToBase64 = function(byteArray) |
6745 |
20 May 22 |
nicklas |
11 |
{ |
6792 |
05 Aug 22 |
nicklas |
if (!byteArray) return null; |
6745 |
20 May 22 |
nicklas |
return btoa(Array.from(new Uint8Array(byteArray)).map(val => { |
6745 |
20 May 22 |
nicklas |
return String.fromCharCode(val); |
6745 |
20 May 22 |
nicklas |
}).join('')).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, ''); |
6745 |
20 May 22 |
nicklas |
16 |
} |
6745 |
20 May 22 |
nicklas |
17 |
|
6745 |
20 May 22 |
nicklas |
18 |
/* |
6745 |
20 May 22 |
nicklas |
Decode a Base64-urlencoded string to a Uint8Array. |
6745 |
20 May 22 |
nicklas |
20 |
*/ |
6745 |
20 May 22 |
nicklas |
utils.base64ToUint8Array = function(b64urlstring) |
6745 |
20 May 22 |
nicklas |
22 |
{ |
6745 |
20 May 22 |
nicklas |
return new Uint8Array(atob(b64urlstring.replace(/-/g, '+').replace(/_/g, '/')).split('').map(val => { |
6745 |
20 May 22 |
nicklas |
return val.charCodeAt(0); |
6745 |
20 May 22 |
nicklas |
25 |
})); |
6745 |
20 May 22 |
nicklas |
26 |
} |
6745 |
20 May 22 |
nicklas |
27 |
|
6745 |
20 May 22 |
nicklas |
28 |
|
6745 |
20 May 22 |
nicklas |
return utils; |
6745 |
20 May 22 |
nicklas |
30 |
}(); |
6745 |
20 May 22 |
nicklas |
31 |
|
6745 |
20 May 22 |
nicklas |
32 |
|