diff --git a/src/util.mjs b/src/util.mjs index 12bd843..60ac2b5 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -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'