From ae5c7daf8b35dd9fbdfded088da189a45b2e7148 Mon Sep 17 00:00:00 2001 From: Arnim Rupp <46819580+2d4d@users.noreply.github.com> Date: Sat, 26 Dec 2020 00:46:25 +0100 Subject: [PATCH] Add new module: Convert to Emoji alphabe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a fun 'cipher' for kids. Converts characters to their representation in the Emoji animal alphabet, matching first letters of the animal. Can be combined with 'Generate QR Code'. Example: πŸ… πŸ™ 🐧 🐍 🐘 ℃ πŸ€ 🐘 πŸ… ❗️ --- .gitignore | 1 + src/core/config/Categories.json | 3 +- .../operations/ConvertToEmojiAlphabet.mjs | 89 +++++++++++++++++++ .../tests/ConvertToEmojiAlphabet.mjs | 33 +++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/core/operations/ConvertToEmojiAlphabet.mjs create mode 100644 tests/operations/tests/ConvertToEmojiAlphabet.mjs diff --git a/.gitignore b/.gitignore index 40682646..a37e17cd 100755 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ src/node/index.mjs **/*.DS_Store tests/browser/output/* +package-lock.json diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 77e3d319..66ae1b3d 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -202,7 +202,8 @@ "Decode text", "Remove Diacritics", "Unescape Unicode Characters", - "Convert to NATO alphabet" + "Convert to NATO alphabet", + "Convert to Emoji alphabet" ] }, { diff --git a/src/core/operations/ConvertToEmojiAlphabet.mjs b/src/core/operations/ConvertToEmojiAlphabet.mjs new file mode 100644 index 00000000..5374dd19 --- /dev/null +++ b/src/core/operations/ConvertToEmojiAlphabet.mjs @@ -0,0 +1,89 @@ +/** + * @author Arnim Rupp https://github.com/2d4d/crypto_puzzles + * @copyright Crown Copyright 2020 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; + +/** + * Convert to Emoji alphabet operation + */ +class ConvertToEmojiAlphabet extends Operation { + /** + * ConvertToEmojiAlphabet constructor + */ + constructor() { + super(); + + this.name = "Convert to Emoji alphabet"; + this.module = "Default"; + this.description = "This is a fun 'cipher' for kids. Converts characters to their representation in the Emoji animal alphabet, matching first letters of the animal. Can be combined with 'Generate QR Code'."; + this.infoURL = "https://en.wikipedia.org/wiki/Emoji"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + return input.replace(/[a-z0-9,.\-+*#?! ]/ig, letter => { + return lookup[letter.toUpperCase()]; + }); + } +} + +const lookup = { + "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": "πŸ¦“ ", + "0": "πŸ…ΎοΈ ", + "1": "πŸ₯‡ ", + "2": "⚁ ", + "3": "α—± ", + "4": "ΰΌ₯ ", + "5": "βš„ ", + "6": "πŸƒ– ", + "7": "ㇴ ", + "8": "🎱 ", + "9": "9️⃣ ", + "+": "βž• ", + "-": "βž– ", + "#": "#️⃣ ", + "*": "✳️ ", + ".": ". ", + ",": ", ", + " ": " ", + "?": "οΏ½ ", + "!": "❗️ " + +}; + +export default ConvertToEmojiAlphabet; diff --git a/tests/operations/tests/ConvertToEmojiAlphabet.mjs b/tests/operations/tests/ConvertToEmojiAlphabet.mjs new file mode 100644 index 00000000..330156e6 --- /dev/null +++ b/tests/operations/tests/ConvertToEmojiAlphabet.mjs @@ -0,0 +1,33 @@ +/** + * @author Arnim Rupp https://github.com/2d4d/crypto_puzzles + * @copyright Crown Copyright 2020 + * @license Apache-2.0 + */ + + +import TestRegister from "../../lib/TestRegister.mjs"; + +TestRegister.addTests([ + { + name: "Convert to Emoji alphabet: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "Convert to Emoji alphabet", + args: [] + } + ] + }, + { + name: "Convert to Emoji alphabet: full alphabet with numbers", + input: "abcdefghijklmnopqrstuvwxyz1234567890,.-#+*-", + expectedOutput: "🐜 🐻 ℃ 🐬 🐘 🦊 πŸ¦’ 🐹 ℹ️ ʝ 🦘 🦁 🐁 β„• πŸ™ 🐧 πŸ‚­ πŸ€ 🐍 πŸ… αΆ™ ✌ πŸ‹ βš”οΈ Β₯ πŸ¦“ πŸ₯‡ ⚁ α—± ΰΌ₯ βš„ πŸƒ– ㇴ 🎱 9️⃣ πŸ…ΎοΈ , . βž– #️⃣ βž• ✳️ βž– ", + recipeConfig: [ + { + op: "Convert to Emoji alphabet", + args: [] + } + ] + } +]);