-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1971 from bartblaze/master
Add Leet Speak
- Loading branch information
Showing
4 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* @author bartblaze [] | ||
* @copyright Crown Copyright 2025 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
|
||
/** | ||
* Convert Leet Speak operation | ||
*/ | ||
class ConvertLeetSpeak extends Operation { | ||
/** | ||
* ConvertLeetSpeak constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Convert Leet Speak"; | ||
this.module = "Default"; | ||
this.description = "Converts to and from Leet Speak"; | ||
this.infoURL = "https://wikipedia.org/wiki/Leet"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
name: "Direction", | ||
type: "option", | ||
value: ["To Leet Speak", "From Leet Speak"], | ||
defaultIndex: 0 | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
run(input, args) { | ||
const direction = args[0]; | ||
if (direction === "To Leet Speak") { | ||
return input.replace(/[abcdefghijklmnopqrstuvwxyz]/gi, char => { | ||
return toLeetMap[char.toLowerCase()] || char; | ||
}); | ||
} else if (direction === "From Leet Speak") { | ||
return input.replace(/[48cd3f6h1jklmn0pqr57uvwxyz]/g, char => { | ||
return fromLeetMap[char] || char; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
const toLeetMap = { | ||
"a": "4", | ||
"b": "b", | ||
"c": "c", | ||
"d": "d", | ||
"e": "3", | ||
"f": "f", | ||
"g": "g", | ||
"h": "h", | ||
"i": "1", | ||
"j": "j", | ||
"k": "k", | ||
"l": "l", | ||
"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" | ||
}; | ||
|
||
const fromLeetMap = { | ||
"4": "a", | ||
"b": "b", | ||
"c": "c", | ||
"d": "d", | ||
"3": "e", | ||
"f": "f", | ||
"g": "g", | ||
"h": "h", | ||
"1": "i", | ||
"j": "j", | ||
"k": "k", | ||
"l": "l", | ||
"m": "m", | ||
"n": "n", | ||
"0": "o", | ||
"p": "p", | ||
"q": "q", | ||
"r": "r", | ||
"5": "s", | ||
"7": "t", | ||
"u": "u", | ||
"v": "v", | ||
"w": "w", | ||
"x": "x", | ||
"y": "y", | ||
"z": "z" | ||
}; | ||
|
||
export default ConvertLeetSpeak; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @author bartblaze [] | ||
* @copyright Crown Copyright 2025 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import TestRegister from "../../lib/TestRegister.mjs"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "Convert to Leet Speak: basic text", | ||
input: "leet", | ||
expectedOutput: "l337", | ||
recipeConfig: [ | ||
{ | ||
op: "Convert Leet Speak", | ||
args: ["To Leet Speak"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "Convert from Leet Speak: basic leet", | ||
input: "l337", | ||
expectedOutput: "leet", | ||
recipeConfig: [ | ||
{ | ||
op: "Convert Leet Speak", | ||
args: ["From Leet Speak"] | ||
} | ||
] | ||
} | ||
]); | ||
|