Skip to content

Instantly share code, notes, and snippets.

@JosePedroDias
Created September 3, 2017 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosePedroDias/624f216fa97828f96ea4451c609cfea6 to your computer and use it in GitHub Desktop.
Save JosePedroDias/624f216fa97828f96ea4451c609cfea6 to your computer and use it in GitHub Desktop.
handmade js crunch
const CHARS = `αβγδϵζηθικλμνξοπρστυϕχψωΓΔΘΛΞΠΣΦΨΩ`;
function replaceAll(txt, a, b) {
return txt.split(a).join(b);
}
function generateCrunchedCode(code, replacements) {
let a = code;
let b = '';
for (let i = 0; i < replacements.length; ++i) {
let char = CHARS[i];
let rep = replacements[i];
a = replaceAll(a, rep, char) + char + rep;
b = char + b;
}
return `_=\`${a}\`;for(Y in $='${b}')with(_.split($[Y]))_=join(pop());eval(_)`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment