(str)
| 316 | } |
| 317 | |
| 318 | function b64EncodeUnicode(str) { |
| 319 | // (1) use encodeURIComponent to get percent-encoded UTF-8 |
| 320 | // (2) convert percent encodings to raw bytes |
| 321 | // (3) convert raw bytes to Base64 |
| 322 | return Buffer.from(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => { |
| 323 | return String.fromCharCode('0x' + p1); |
| 324 | })).toString('base64'); |
| 325 | } |
| 326 | |
| 327 | function b64DecodeUnicode(str) { |
| 328 | // Going backwards: from bytestream, to percent-encoding, to original string. |