Skip to content

Commit

Permalink
add repl to executable
Browse files Browse the repository at this point in the history
  • Loading branch information
David Adam Justice committed May 3, 2014
1 parent 3e78e12 commit 6069cff
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions fuck.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
#!/usr/bin/env node

var stream = require('stream');
var util = require('util');
var lib = require("./jsfuck.js");
var repl = require('repl');

if(process.argv.length !== 3) {
console.error("Usage: jsfuck <js file>");
return;
}

var data = require("fs").readFileSync(process.argv[2], "utf8");
var output = lib.JSFuck.encode(data, false);
console.log(output);
function Stream() {
stream.Transform.call(this);
}
util.inherits(Stream, stream.Transform);

Stream.prototype._transform = function (chunk, encoding, callback) {
var script = lib.JSFuck.encode(chunk.toString());
var lines = script.split(/\n+/);
for (var i = 0; i < lines.length; i++) {
// ignore empty lines
if (lines[i] !== '') this.push(lines[i] + '\n');
}
callback();
};

var fuckScript = new Stream();
repl.start({
prompt: "FUCK> ",
input: fuckScript,
useColors: true,
output: process.stdout
});

process.stdin.pipe(fuckScript);
} else {
var data = require("fs").readFileSync(process.argv[2], "utf8");
var output = lib.JSFuck.encode(data, false);
console.log(output);
}

0 comments on commit 6069cff

Please sign in to comment.