mirror of
https://github.com/Warky-Devs/artemis-kit.git
synced 2025-07-04 14:27:33 +00:00
21 lines
613 B
TypeScript
21 lines
613 B
TypeScript
/**
|
|
* Decodes a base64 string that contains Unicode characters.
|
|
* This function handles Unicode characters correctly by:
|
|
* 1. Converting base64 to binary
|
|
* 2. Converting each byte to a hex representation
|
|
* 3. Converting hex-encoded UTF-8 sequences back to Unicode characters
|
|
*
|
|
* @param str - The base64 encoded string to decode
|
|
* @returns The decoded Unicode string
|
|
*/
|
|
export function b64DecodeUnicode(str: string): any {
|
|
return decodeURIComponent(
|
|
Array.prototype.map
|
|
.call(
|
|
atob(str),
|
|
(c) => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`
|
|
)
|
|
.join('')
|
|
)
|
|
}
|