jUst Cuz
A compiler* for the next generation (and the one after that)
by Christopher McCulloh
HTML
<form name="justcuz">Convert to jUst Cuz:
<br>
<textarea id="chars">Can I has just cuz?</textarea>
<br>
<input type="button" value="Encode" id='encode'>
<br>
<br>
<textarea id="codebox" cols="50" rows="11" style="width:70%" wrap="virtual"> </textarea>
<br>
<input type="button" value="Decode" id='decode'>
</form>
JavaScript
var charCodes = {};
function binaryToJC(num, index) {
var char = 'justcuz'[index];
if (char === 'c') char = ' ' + char;
if (num === '1') char = char.toUpperCase();
return char;
};
Array.prototype.forEach.call('abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ', function generateCharMap(char, index) {
var binary = ('0000000' + (index >>> 0).toString(2)).slice(-7);
var jc = Array.prototype.map.call(binary, binaryToJC).join('');
charCodes[char] = jc;
charCodes[jc] = char;
});
$('#encode').on('click', function encode() {
var chars = Array.prototype.map.call($('#chars').val(), function charToJC(char) {
if (charCodes[char]) {
return charCodes[char];
} else if (char !== ' ') {
return char;
}
});
$('#codebox').val(chars.join(' '));
});
$('#decode').on('click', function decode() {
var temp;
var chars = $('#codebox').val().split(' ').map(function jcToChar(jc) {
var char;
if (jc.toLowerCase() === 'just') {
temp = jc + ' ';
} else if (temp) {
temp = temp + jc;
char = charCodes[temp];
temp = undefined;
} else if (jc.length > 0) {
char = jc;
} else {
char = ' ';
}
return char;
});
$('#chars').val(chars.join(''));
});