Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
Last active June 9, 2018 00:27
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 friendlyanon/fd04601ca277c43d79ed4e3a10d4cbca to your computer and use it in GitHub Desktop.
Save friendlyanon/fd04601ca277c43d79ed4e3a10d4cbca to your computer and use it in GitHub Desktop.
function* shrinkGen(s) {
let i = -1, c;
while (c = s.charCodeAt(++i)) yield c << 0 | (s.charCodeAt(++i) || 0) << 8;
}
function shrink(input) {
return String.fromCodePoint(...shrinkGen(input));
}
function* expandGen(str) {
let i = -1, c;
while (c = str.codePointAt(++i)) {
yield c & 0x00FF;
const high = (c & 0xFF00) >> 8;
if (high) yield high;
}
}
function expand(input) {
return String.fromCharCode(...expandGen(input));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment