-
Content count
3904 -
Joined
-
Last visited
Single Status Update
-
This is it, I wrote the best Node.JS module ever!
function caseRep(letter, low, upp) { return letter.toLowerCase() == letter ? low : upp; } function furrify(word) { return word .replace(/(w)(h)/gi, (match, w, h) => caseRep(w, 'u', 'U') + caseRep(h, 'w', 'W')) .replace(/(g)([aeiou])/gi, (match, g, vowel) => caseRep(g, 'g', 'G') + caseRep(vowel, 'y', 'Y') + vowel) .replace(/(o)(u)/gi, (match, o, u) => caseRep(o, 'e', 'E') + caseRep(u, 'e', 'E')) .replace(/(l)(l)/gi, (match, t, h) => caseRep(t, 'w', 'W') + caseRep(h, 'w', 'W')) .replace(/(t)(h)/gi, (match, t, h) => caseRep(t, 'd', 'D') + caseRep(h, 'h', 'H')) .replace(/ph/g, 'f') .replace(/ph/gi, 'F') .replace(/(p)(p)/gi, (match, p1, p2) => caseRep(p1, 'p', 'P')) .replace(/([lL])([aeiouAEIOU])/gi, (match, l, vowel) => caseRep(l, 'w', 'W') + vowel) .replace(/y(?=[\.\,\;\:\?\!])|y^/gi, (y) => caseRep(y, 'ya', 'YA')) .replace(/r(?=[\.\,\;\:\?\!])|r^/gi, (r) => caseRep(r, 'y', 'Y')) .replace(/(r)/gi, (match, r) => caseRep(r, 'y', 'Y')) .replace(/y(?=!a)/gi, (y) => caseRep(y, 'ii', 'II')) .replace(/(i)(n)/gi, (match, i, n) => caseRep(i, 'iy', 'IY') + n); } module.exports = furrify
Use case:
$ node > var furrify = require('./furrify.js') undefined > furrify('Why did I write this?') 'Uwy did I wyite dhis?' > furrify('Were I sober? Were I serious? Were I even myself?') 'Weye I sobey? Weye I seyiees? Weye I even myself?' > furrify("Gah, I can't even think!") 'Gyah, I can\'t even dhiynk!' > furrify('And I thought I had sanity enough to be the President of the Brazilian Republic.') 'And I dheeght I had sanity eneegh to be dhe Pyesident of dhe Byaziwian Yepubwic.' > furrify('Oh, dreams, fleeing down the sinkhole...') 'Oh, dyeams, fweeiyng down dhe siynkhowe...' >