Created
September 3, 2017 03:39
-
-
Save JosePedroDias/624f216fa97828f96ea4451c609cfea6 to your computer and use it in GitHub Desktop.
handmade js crunch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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