UNPKG

chuckscript

Version:

Chuck Norris programing language, code only with zeroes

24 lines (22 loc) 790 B
// ABC - a generic, native JS (A)scii(B)inary(C)onverter. // (c) 2013 Stephan Schmitz <eyecatchup@gmail.com> // License: MIT, http://eyecatchup.mit-license.org // URL: https://gist.github.com/eyecatchup/6742657 // Minor changes by @demiurgosoft var ABC = { toAscii: function(bin) { return bin.replace(/\s*[01]{8}\s*/g, function(bin) { return String.fromCharCode(parseInt(bin, 2)); }); }, toBinary: function(str, spaceSeparatedOctets) { return str.replace(/[\s\S]/g, function(str) { str = ABC.zeroPad(str.charCodeAt().toString(2)); return !spaceSeparatedOctets ? str : str + " "; }); }, zeroPad: function(num) { return "00000000".slice(String(num).length) + num; } }; module.exports = ABC;