File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed
Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class ConvertLeetSpeak extends Operation {
1818
1919 this . name = "Convert Leet Speak" ;
2020 this . module = "Default" ;
21- this . description = "Converts to and from Leet Speak" ;
21+ this . description = "Converts to and from Leet Speak. " ;
2222 this . infoURL = "https://wikipedia.org/wiki/Leet" ;
2323 this . inputType = "string" ;
2424 this . outputType = "string" ;
@@ -39,13 +39,16 @@ class ConvertLeetSpeak extends Operation {
3939 */
4040 run ( input , args ) {
4141 const direction = args [ 0 ] ;
42+
4243 if ( direction === "To Leet Speak" ) {
43- return input . replace ( / [ a b c d e f g h i j k l m n o p q r s t u v w x y z ] / gi, char => {
44- return toLeetMap [ char . toLowerCase ( ) ] || char ;
44+ return input . replace ( / [ a - z ] / gi, char => {
45+ const leetChar = toLeetMap [ char . toLowerCase ( ) ] || char ;
46+ return char === char . toUpperCase ( ) ? leetChar . toUpperCase ( ) : leetChar ;
4547 } ) ;
4648 } else if ( direction === "From Leet Speak" ) {
47- return input . replace ( / [ 4 8 c d 3 f 6 h 1 j k l m n 0 p q r 5 7 u v w x y z ] / g, char => {
48- return fromLeetMap [ char ] || char ;
49+ return input . replace ( / [ 4 8 c d 3 f 6 h 1 j k l m n 0 p q r 5 7 u v w x y z ] / gi, char => {
50+ const normalChar = fromLeetMap [ char ] || char ;
51+ return normalChar ;
4952 } ) ;
5053 }
5154 }
Original file line number Diff line number Diff line change @@ -28,6 +28,28 @@ TestRegister.addTests([
2828 args : [ "From Leet Speak" ]
2929 }
3030 ]
31+ } ,
32+ {
33+ name : "Convert to Leet Speak: basic text, keep case" ,
34+ input : "HELLO" ,
35+ expectedOutput : "H3LL0" ,
36+ recipeConfig : [
37+ {
38+ op : "Convert Leet Speak" ,
39+ args : [ "To Leet Speak" ]
40+ }
41+ ]
42+ } ,
43+ {
44+ name : "Convert from Leet Speak: basic leet, keep case" ,
45+ input : "H3LL0" ,
46+ expectedOutput : "HeLLo" ,
47+ recipeConfig : [
48+ {
49+ op : "Convert Leet Speak" ,
50+ args : [ "From Leet Speak" ]
51+ }
52+ ]
3153 }
3254] ) ;
3355
You can’t perform that action at this time.
0 commit comments