Comparing version 1.2.0 to 1.2.1
186
leet.js
@@ -7,148 +7,106 @@ #!/usr/bin/env node | ||
var app = { | ||
/** | ||
* Convert regular and boring text into 1337 text. | ||
* | ||
* @author Mathias Novas <novasism@gmail.com>, Michael Enger <mike@thelonelycoder.com> | ||
* @license IDGAF | ||
*/ | ||
var leet = { | ||
/** | ||
* Initialize the app | ||
* Map of conversions. | ||
* | ||
* @var object | ||
*/ | ||
init: function () { | ||
var s = process.argv[2]; | ||
if (s) { | ||
var w = app.render(s); | ||
if (w) { | ||
console.log(app.output(w)); | ||
} else { | ||
app.error(); | ||
} | ||
} else { | ||
app.error(); | ||
} | ||
characterMap: { | ||
'a': '4', | ||
'b': '8', | ||
'e': '3', | ||
'g': '6', | ||
'l': '1', | ||
'o': '0', | ||
's': '5', | ||
't': '7' | ||
}, | ||
/** | ||
* Returns a 1337 character | ||
* Convert a string to 1337 based on the character map. | ||
* | ||
* @param string string Regular ol' text to convert | ||
* @return string | ||
*/ | ||
get: function (c) { | ||
var a = { | ||
'a': '4', | ||
'b': '8', | ||
'c': 'C', | ||
'd': 'D', | ||
'e': '3', | ||
'f': 'F', | ||
'g': '6', | ||
'h': 'H', | ||
'i': 'I', | ||
'j': 'J', | ||
'k': 'K', | ||
'l': '1', | ||
'm': 'M', | ||
'n': 'N', | ||
'o': '0', | ||
'p': 'P', | ||
'q': 'Q', | ||
'r': 'R', | ||
's': '5', | ||
't': '7', | ||
'u': 'U', | ||
'v': 'V', | ||
'w': 'W', | ||
'x': 'X', | ||
'y': 'Y', | ||
'z': 'Z', | ||
' ': ' ' | ||
convert: function (string) { | ||
var letter; | ||
string = string || ''; | ||
string = string.replace(/cks/g, 'x'); | ||
for (letter in leet.characterMap) { | ||
if (leet.characterMap.hasOwnProperty(letter)) { | ||
string = string.replace(new RegExp(letter, 'g'), leet.characterMap[letter]); | ||
} | ||
} | ||
return a[c]; | ||
return string.toUpperCase(); | ||
}, | ||
/** | ||
* "Renders" the input | ||
* Test character to see if it's a vovel or special (or neither). | ||
* | ||
* @param string character Character to test | ||
* @return mixed | ||
*/ | ||
render: function (s) { | ||
var x = /cks/g; | ||
test: function (character) { | ||
var vowel = /^[4I30U]$/i, | ||
special = /^[!?.,\-]$/i, | ||
type = false; | ||
if (x.test(s)) { | ||
s = s.replace(x, 'x'); | ||
if (vowel.test(character)) { | ||
type = 'vowel'; | ||
} else if (special.test(character)) { | ||
type = 'special'; | ||
} | ||
var b = s.split(''), | ||
a = []; | ||
for(var i = 0; i < s.length; i++) { | ||
var c = b[i]; | ||
if (app.get(c)) { | ||
a.push(app.get(c)); | ||
} else { | ||
a.push(c); | ||
} | ||
} | ||
return a; | ||
return type; | ||
}, | ||
/** | ||
* Test character | ||
* Converts the string to 1337 along with special rules. | ||
* | ||
* @param string string Regular ol' text to convert | ||
* @return string | ||
*/ | ||
test: function (c) { | ||
var v = /^[4I30U]$/i, | ||
s = /^[!?.,-]$/i, | ||
b = false; | ||
if (v.test(c)) { | ||
b = 'vowel'; | ||
} else if (s.test(c)) { | ||
b = 'special'; | ||
output: function (string) { | ||
string = leet.convert(string); | ||
if ('' === string) { | ||
return string; | ||
} | ||
return b; | ||
}, | ||
var last = string[string.length - 1], | ||
type = leet.test(last), | ||
result; | ||
/** | ||
* Outputs the result | ||
*/ | ||
output: function (s) { | ||
var l = s[s.length - 1], | ||
t = app.test(l), | ||
f = s.join(''); | ||
if (t) { | ||
if (t == 'special') { | ||
return f.substr(0, f.length - 1) + 'ZORZ' + l; | ||
} else if (t == 'vowel') { | ||
return f + 'XOR'; | ||
} | ||
if (type === 'special') { | ||
result = string.substr(0, string.length - 1) + 'ZORZ' + last; | ||
} else if (type === 'vowel') { | ||
result = string + 'XOR'; | ||
} else { | ||
return f + 'ZORZ'; | ||
result = string + 'ZORZ'; | ||
} | ||
}, | ||
/** | ||
* Outputs an error and returns false | ||
*/ | ||
error: function () { | ||
console.log('Looks like something went wrong!'); | ||
return false; | ||
return result; | ||
} | ||
} | ||
}; | ||
if (/(^|\/)leet\.js$/.test(process.argv[1])) { | ||
app.init(); | ||
} else if (typeof exports !== 'undefined') { | ||
// Export only a specific function for converting a string into 1337 | ||
exports.convert = function(string) { | ||
var letters = app.render(string); | ||
if (letters) { | ||
return app.output(letters); | ||
} else { | ||
app.error(); | ||
} | ||
if (undefined !== process.argv[2]) { | ||
console.log(leet.output(process.argv[2])); | ||
} else { | ||
console.error('Usage: leet.js <string>'); | ||
} | ||
} else if (undefined !== exports) { | ||
exports.convert = leet.output; | ||
} else { | ||
app.error(); | ||
console.error('I don\'t know what to do'); | ||
} | ||
}) (); | ||
}()); |
{ | ||
"name": "leet", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Convert boring text to 1337 text", | ||
@@ -5,0 +5,0 @@ "main": "leet.js", |
@@ -7,2 +7,8 @@ # leet.js | ||
It converts the usual suspects into 4W350M3 1337 73X7ZORZ, but with the following caveats: | ||
* Uppercase characters will "bypass" the conversion (`HELLO hello` becomes `HELLO H3110`) | ||
* Any `cks` are replaced by `x` for 100% true 1337N355 | ||
* It will add `ZORZ` or `XOR` to the end of the end of the text | ||
*** | ||
@@ -38,4 +44,2 @@ | ||
**Note:** Uppercase characters will "bypass" the conversion. | ||
### As a standalone script | ||
@@ -42,0 +46,0 @@ |
72
4806
95