Use Unicode-tolerant base64 function
This commit is contained in:
parent
e281ff4c9a
commit
8840d1a61f
1 changed files with 12 additions and 1 deletions
13
src/util.mjs
13
src/util.mjs
|
|
@ -2,6 +2,15 @@
|
||||||
|
|
||||||
import {execSync} from 'node:child_process';
|
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
|
* terrible terrible terrible string diff helper for debugging
|
||||||
* @param {string} a
|
* @param {string} a
|
||||||
|
|
@ -12,9 +21,11 @@ export function diff (a, b) {
|
||||||
// https://stackoverflow.com/a/60221847
|
// https://stackoverflow.com/a/60221847
|
||||||
// also use `|| true` to not throw an error when `diff` returns non-zero
|
// also use `|| true` to not throw an error when `diff` returns non-zero
|
||||||
execSync(`bash -c '
|
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`, {
|
' || true`, {
|
||||||
// display result directly in terminal
|
// display result directly in terminal
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
'yeet'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue