File tree 2 files changed +30
-5
lines changed
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 {
18
18
19
19
this . name = "Convert Leet Speak" ;
20
20
this . module = "Default" ;
21
- this . description = "Converts to and from Leet Speak" ;
21
+ this . description = "Converts to and from Leet Speak. " ;
22
22
this . infoURL = "https://wikipedia.org/wiki/Leet" ;
23
23
this . inputType = "string" ;
24
24
this . outputType = "string" ;
@@ -39,13 +39,16 @@ class ConvertLeetSpeak extends Operation {
39
39
*/
40
40
run ( input , args ) {
41
41
const direction = args [ 0 ] ;
42
+
42
43
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 ;
45
47
} ) ;
46
48
} 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 ;
49
52
} ) ;
50
53
}
51
54
}
Original file line number Diff line number Diff line change @@ -28,6 +28,28 @@ TestRegister.addTests([
28
28
args : [ "From Leet Speak" ]
29
29
}
30
30
]
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
+ ]
31
53
}
32
54
] ) ;
33
55
You can’t perform that action at this time.
0 commit comments