Skip to content

Commit d3357d2

Browse files
authored
Merge pull request #1981 from bartblaze/master
2 parents 1b8c229 + 7babef6 commit d3357d2

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/core/operations/ConvertLeetSpeak.mjs

+8-5
Original file line numberDiff line numberDiff 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(/[abcdefghijklmnopqrstuvwxyz]/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(/[48cd3f6h1jklmn0pqr57uvwxyz]/g, char => {
48-
return fromLeetMap[char] || char;
49+
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/gi, char => {
50+
const normalChar = fromLeetMap[char] || char;
51+
return normalChar;
4952
});
5053
}
5154
}

tests/operations/tests/ConvertLeetSpeak.mjs

+22
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)