Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit d3bdde23629e0812dfd21cec0a48732014ab79c9 @octopi committed Feb 16, 2012
Showing with 37 additions and 0 deletions.
  1. +5 −0 README.md
  2. +32 −0 linify.js
@@ -0,0 +1,5 @@
+### Linify ###
+
+Make anything into a Jeremy Lin pun!
+
+See it in action: [http://davidhu.me/linify/](http://davidhu.me/linify/)
@@ -0,0 +1,32 @@
+/**
+linify.js
+Returns a Jeremy Lin-pun-riddled version of text.
+*/
+
+var pairings = [
+ [/Lin/, '<img src="l.png" alt="Lin" />'],
+ [/ling$/, 'LIN\''],
+ [/lin/i, 'LIN'],
+ [/^in/, 'lin'],
+ [/^In/, 'Lin'],
+ [/^.in/, 'lin'],
+ [/^li/, 'lin'],
+ [/^Li/, 'Lin'],
+];
+function linify(text) {
+ var words = text.replace(/\n/g, '<br /> ').split(' ');
+ var linified = '';
+ for(var i=0;i<words.length;i++) {
+ var curr = words[i];
+ var j = 0;
+ var rep = '';
+ do {
+ rep = curr.replace(pairings[j][0], pairings[j][1]);
+ j++;
+ } while (rep === curr && j < pairings.length);
+ linified += (rep === '') ? curr : rep;
+ if(i<words.length-1)
+ linified += ' ';
+ }
+ return linified;
+}

0 comments on commit d3bdde2

Please sign in to comment.