MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / b64EncodeUnicode

Function b64EncodeUnicode

tests/testFileEditor.js:318–325  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

316}
317
318function 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
327function b64DecodeUnicode(str) {
328 // Going backwards: from bytestream, to percent-encoding, to original string.

Callers 2

badPostFunction · 0.70
editPostFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected