Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit ae7bae78f812103225fe17181872dec1e8cbc9f8 @regality committed Aug 27, 2012
Showing with 243 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +41 −0 README.md
  3. +64 −0 index.js
  4. +11 −0 test.js
  5. +8 −0 tests/bear.txt
  6. +32 −0 tests/eagle.txt
  7. +17 −0 tests/pig.txt
  8. +29 −0 tests/t-rex.txt
  9. +26 −0 tests/wolf.txt
@@ -0,0 +1,15 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
@@ -0,0 +1,41 @@
+# Ascii Art Reverse
+
+This is package is essentially a rainbow being
+farted from the aft portion of a unicorn. It's pure magic.
+
+# Install
+
+`npm install ascii-art-reverse`
+
+# Usage
+
+```javascript
+var reverse = require('ascii-art-reverse');
+
+var art =
+ " ("-^-/") " +
+ " `o__o' ] " +
+ " (_Y_) _/ " +
+ " _..`--'-.`, " +
+ " (__)_,--(__) " +
+ " 7: ; 1 " +
+ " _/,`-.-' : " +
+ " (_,)-~~(_,) ";
+
+console.log(reverse(art));
+```
+
+### Output:
+
+```
+ ("\-^-")
+ [ 'o__o`
+ \_ (_Y_)
+,`.-'--`.._
+(__)--,_(__)
+1 ; :7
+: '-.-`,\_
+(,_)~~-(,_)
+```
+
+Like I said, __MAGIC__.
@@ -0,0 +1,64 @@
+"use strict";
+
+var fs = require('fs');
+
+// map of characters with opposites
+var opposites = {
+ "b": "d",
+ "d": "b",
+ "z": "s",
+ "(": ")",
+ ")": "(",
+ "[": "]",
+ "]": "[",
+ "{": "}",
+ "}": "{",
+ "<": ">",
+ ">": "<",
+ "/": "\\",
+ "\\": "/"
+};
+
+// Read a file, and return the reveresed and original
+function reverseArtFile(file, cb) {
+ fs.readFile(file, function(err, data) {
+ if (err) return cb(err);
+ var orig = data.toString();
+ var art = reverseArt(orig);
+ cb(null, art, orig);
+ });
+}
+
+// Reverse a string of ascii art
+function reverseArt(art) {
+ art = art.replace('\r\n', '\n')
+ .split('\n');
+
+ var maxLineLen = art.reduce(function(max, line) {
+ return Math.max(line.length, max);
+ }, 0);
+
+ var art = art.map(function(line) {
+ var pad = (new Array(1 + maxLineLen - line.length)).join(' ');
+ line = reverseLine(line + pad);
+ return line.replace(/\s\+$/, '');
+ }).join('\n');
+
+ return art;
+}
+
+// Reverse a line of ascii art
+function reverseLine(art) {
+ var rev = '';
+ for (var i = art.length - 1; i >= 0; --i) {
+ if (opposites.hasOwnProperty(art[i])) {
+ rev += opposites[art[i]];
+ } else {
+ rev += art[i];
+ }
+ }
+ return rev;
+}
+
+module.exports = reverseArt;
+reverseArt.reverseArtFile = reverseArtFile;
11 test.js
@@ -0,0 +1,11 @@
+var fs = require('fs')
+ , reverse = require('./index');
+
+['eagle', 't-rex', 'pig', 'wolf', 'bear'].forEach(function(name) {
+ var file = './tests/' + name + '.txt';
+ reverse.reverseArtFile(file, function(err, art, orig) {
+ if (err) throw err;
+ console.log(orig);
+ console.log(art);
+ });
+});
@@ -0,0 +1,8 @@
+ ("-^-/")
+ `o__o' ]
+ (_Y_) _/
+ _..`--'-.`,
+(__)_,--(__)
+ 7: ; 1
+ _/,`-.-' :
+ (_,)-~~(_,)
@@ -0,0 +1,32 @@
+ /T /I
+ / |/ | .-~/
+ T\ Y I |/ / _
+ /T | \I | I Y.-~/
+ I l /I T\ | | l | T /
+ T\ | \ Y l /T | \I l \ ` l Y
+ __ | \l \l \I l __l l \ ` _. |
+ \ ~-l `\ `\ \ \ ~\ \ `. .-~ |
+ \ ~-. "-. ` \ ^._ ^. "-. / \ |
+ .--~-._ ~- ` _ ~-_.-"-." ._ /._ ." ./
+ >--. ~-. ._ ~>-" "\ 7 7 ]
+ ^.___~"--._ ~-{ .-~ . `\ Y . / |
+ <__ ~"-. ~ /_/ \ \I Y : |
+ ^-.__ ~(_/ \ >._: | l______
+ ^--.,___.-~" /_/ ! `-.~"--l_ / ~"-.
+ (_/ . ~( /' "~"--,Y -=b-. _)
+ (_/ . \ : / l c"~o \
+ \ / `. . .^ \_.-~"~--. )
+ (_/ . ` / / ! )/
+ / / _. '. .': / '
+ ~(_/ . / _ ` .-<_
+ /_/ . ' .-~" `. / \ \ ,z=.
+ ~( / ' : | K "-.~-.______//
+ "-,. l I/ \_ __{----._(==.
+ //( \ < ~"~" //
+ /' /\ \ \ ,v=. ((
+ .^. / /\ " }__ //===- `
+ / / ' ' "-.,__ {---(==-
+ .^ ' : T ~" ll -Row
+ / . . . : | :! \
+ (_/ / | | j-" ~^
+ ~-<_(_.^-~"
@@ -0,0 +1,17 @@
+ _,--. ,--._
+ \ > `-"""-' < /
+ `-. .-'
+ / 'e___e` \
+ ( (o o) )
+ _\_ `=' _/_
+ / /|`-._.-'|\ \
+ / /||_______||\ \
+ _/ /_||=======||_\ \_
+ / _/==|| ||==\_ \
+ `'( ^^ ^^ )`'
+ \ /
+ \______|______/ hjw
+ |______|______|
+ )__| |__(
+ / ] [ \
+ `--' `--'
@@ -0,0 +1,29 @@
+ .-=-==--==--.
+ ..-==" ,'o`) `.
+ ,' `"' \
+ : ( `.__...._
+ | ) / `-=-.
+ : ,vv.-._ / / `---==-._
+ \/\/\/VV ^ d88`;' / `.
+ `` ^/d88P!' / , `._
+ ^/ !' ,. , / "-,,__,,--'""""-.
+ ^/ !' ,' \ . .( ( _ ) ) ) ) ))_,-.\
+ ^(__ ,!',"' ;:+.:%:a. \:.. . ,' ) ) ) ) ,"' '
+ ',,,'',' /o:::":%:%a. \:.:.: . ) ) _,'
+ """' ;':::'' `+%%%a._ \%:%| ;.). _,-""
+ ,-='_.-' ``:%::) )%:| /:._,"
+ (/(/" ," ,'_,'%%%: (_,'
+ ( (//(`.___; \
+ \ \ ` `
+ `. `. `. :
+ \. . .\ : . . . :
+ \. . .: `.. . .:
+ `..:.:\ \:...\
+ ;:.:.; ::...:
+ ):%:: :::::;
+ __,::%:( :::::
+ ,;:%%%%%%%: ;:%::
+ ;,--""-.`\ ,=--':%:%:\
+ /" "| /-".:%%%%%%%\
+ ;,-"'`)%%) (CJ)
+ /" "|
@@ -0,0 +1,26 @@
+ __
+ .d$$b
+ .' TO$;\
+ / : TP._;
+ / _.; :Tb|
+ / / ;j$j
+ _.-" d$$$$
+ .' .. d$$$$;
+ / /P' d$$$$P. |\
+ / " .d$$$P' |\^"l
+ .' `T$P^""""" :
+ ._.' _.' ;
+ `-.-".-'-' ._. _.-" .-"
+ `.-" _____ ._ .-"
+ -(.g$$$$$$$b. .'
+ ""^^T$$$P^) .(:
+ _/ -" /.' /:/;
+ ._.'-'`-' ")/ /;/;
+ `-.-"..--"" " / / ;
+ .-" ..--"" -' :
+ ..--""--.-" (\ .-(\
+ ..--"" `-\(\/;`
+ _. :
+ ;`-
+ :\
+ ; bug

0 comments on commit ae7bae7

Please sign in to comment.