Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
regality committed Aug 27, 2012
0 parents commit ae7bae7
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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__.
64 changes: 64 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
8 changes: 8 additions & 0 deletions tests/bear.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
("-^-/")
`o__o' ]
(_Y_) _/
_..`--'-.`,
(__)_,--(__)
7: ; 1
_/,`-.-' :
(_,)-~~(_,)
32 changes: 32 additions & 0 deletions tests/eagle.txt
Original file line number Diff line number Diff line change
@@ -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-" ~^
~-<_(_.^-~"
17 changes: 17 additions & 0 deletions tests/pig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_,--. ,--._
\ > `-"""-' < /
`-. .-'
/ 'e___e` \
( (o o) )
_\_ `=' _/_
/ /|`-._.-'|\ \
/ /||_______||\ \
_/ /_||=======||_\ \_
/ _/==|| ||==\_ \
`'( ^^ ^^ )`'
\ /
\______|______/ hjw
|______|______|
)__| |__(
/ ] [ \
`--' `--'
29 changes: 29 additions & 0 deletions tests/t-rex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.-=-==--==--.
..-==" ,'o`) `.
,' `"' \
: ( `.__...._
| ) / `-=-.
: ,vv.-._ / / `---==-._
\/\/\/VV ^ d88`;' / `.
`` ^/d88P!' / , `._
^/ !' ,. , / "-,,__,,--'""""-.
^/ !' ,' \ . .( ( _ ) ) ) ) ))_,-.\
^(__ ,!',"' ;:+.:%:a. \:.. . ,' ) ) ) ) ,"' '
',,,'',' /o:::":%:%a. \:.:.: . ) ) _,'
"""' ;':::'' `+%%%a._ \%:%| ;.). _,-""
,-='_.-' ``:%::) )%:| /:._,"
(/(/" ," ,'_,'%%%: (_,'
( (//(`.___; \
\ \ ` `
`. `. `. :
\. . .\ : . . . :
\. . .: `.. . .:
`..:.:\ \:...\
;:.:.; ::...:
):%:: :::::;
__,::%:( :::::
,;:%%%%%%%: ;:%::
;,--""-.`\ ,=--':%:%:\
/" "| /-".:%%%%%%%\
;,-"'`)%%) (CJ)
/" "|
26 changes: 26 additions & 0 deletions tests/wolf.txt
Original file line number Diff line number Diff line change
@@ -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.