Use Unicode-tolerant base64 function
This commit is contained in:
parent
e281ff4c9a
commit
8840d1a61f
13
src/util.mjs
13
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'
|
||||
|
|
Loading…
Reference in a new issue