Skip to content
Snippets Groups Projects
Commit 81a1d80f authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Add function base64EncodeUnicode

parent d8843c57
No related branches found
No related tags found
No related merge requests found
......@@ -53,4 +53,21 @@ module.exports = {
list.forEach((item) => {data.push({id: item, text: item})});
return data;
},
/**
* Does generic Base64 Encoding with support for 16-bit encoded strings
* @see https://www.base64encoder.io/javascript/
*
* @param str
* @returns {string}
*/
base64EncodeUnicode: (str) => {
// First we escape the string using encodeURIComponent to get the UTF-8 encoding of the characters,
// then we convert the percent encodings into raw bytes, and finally feed it to btoa() function.
const utf8Bytes = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
return String.fromCharCode('0x' + p1);
});
return btoa(utf8Bytes);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment