Permalink
Browse files

First commit! Not finished, but it is stupid late

  • Loading branch information...
0 parents commit a34ef67206c1b14ae7e41f26d728983159050111 @jfhbrook committed Sep 9, 2011
Showing with 70 additions and 0 deletions.
  1. +25 −0 lib/trollscript.js
  2. +22 −0 package.json
  3. +23 −0 test/test.js
@@ -0,0 +1,25 @@
+var bf = require("bf");
+
+module.exports = function(tscript, cb) {
+ var trigraphs = [];
+ (function() { for(var i = 0; i+3 < tscript.length; trigraphs.push(i+=3)); })();
+ bf(trigraphs.map(function(i) {
+ var trigraph = Array.prototype.slice.call(tscript, i, i+3),
+ lut = {
+ "ooo": ">",
+ "ool": "<",
+ "olo": "+",
+ "oll": "-",
+ "loo": ".",
+ "lol": ",",
+ "llo": "[",
+ "lll": "]"
+ };
+
+ return Object.keys(lut).filter(function(k) {
+ return trigraph === k;
+ }).map(function(k) {
+ return lut[k];
+ });
+ }).join(""), cb);
+}
@@ -0,0 +1,22 @@
+{
+ "author": "Joshua Holbrook <josh.holbrook@gmail.com> (http://jesusabdullah.github.com)",
+ "name": "trollscript",
+ "description": "Because Brainfuck is so last year, right?",
+ "version": "0.0.0",
+ "homepage": "https://github.com/tombell/trollscript",
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:jesusabdullah/node-trollscript.git"
+ },
+ "main": "lib/trollscript",
+ "scripts": {
+ "test": "nodeunit test/*.js"
+ },
+ "engines": {
+ "node": "~v0.4.9"
+ },
+ "dependencies": {
+ "bf": "0.1.2"
+ },
+ "devDependencies": {}
+}
@@ -0,0 +1,23 @@
+var trollscript = require(__dirname + "/../lib/trollscript");
+
+exports["Hello world!"] = function (test) {
+ var hiworld = '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.';
+ var tscript = hiworld
+ .replace(/>/g, "ooo")
+ .replace(/</g, "ool")
+ .replace(/\+/g, "olo")
+ .replace(/-/g, "oll")
+ .replace(/\./g, "loo")
+ .replace(/,/g, "lol")
+ .replace(/\[/g, "llo")
+ .replace(/\]/g, "lll");
+
+ console.log("Here is the tscript:");
+ console.log(tscript);
+ trollscript(tscript, function(output) {
+ console.log(output);
+ test.equal(output, "Hello world!");
+ test.done();
+ });
+
+}

0 comments on commit a34ef67

Please sign in to comment.