Use Unicode-tolerant base64 function

This commit is contained in:
ewin 2025-03-27 15:15:00 -04:00
parent e281ff4c9a
commit 8840d1a61f
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc

View file

@ -2,6 +2,15 @@
import {execSync} from 'node:child_process';
/**
* Converts a string from UTF-8 to base64.
* @param {string} str
* @returns {string}
*/
function toBase64 (str) {
return Buffer.from(str, 'utf-8').toString('base64');
}
/**
* terrible terrible terrible string diff helper for debugging
* @param {string} a
@ -12,9 +21,11 @@ export function diff (a, b) {
// https://stackoverflow.com/a/60221847
// also use `|| true` to not throw an error when `diff` returns non-zero
execSync(`bash -c '
diff --color -u <(echo ${btoa(a)} | base64 -d) <(echo ${btoa(b)} | base64 -d)
diff --color -u <(echo ${toBase64(a)} | base64 -d) <(echo ${toBase64(b)} | base64 -d)
' || true`, {
// display result directly in terminal
stdio: 'inherit',
});
}
'yeet'