From e8fb73ca6c881b65083757f91b59e2c8324ecaf3 Mon Sep 17 00:00:00 2001 From: Joshua Ebert Date: Sat, 19 Oct 2024 13:02:20 +0200 Subject: [PATCH 1/2] Added Print --- src/core/config/Categories.json | 3 +- src/core/operations/Print.mjs | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/core/operations/Print.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index bebdd6a5e2..1f96e2ab3c 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -537,7 +537,8 @@ "HTML To Text", "Generate Lorem Ipsum", "Numberwang", - "XKCD Random Number" + "XKCD Random Number", + "Print" ] }, { diff --git a/src/core/operations/Print.mjs b/src/core/operations/Print.mjs new file mode 100644 index 0000000000..d2b1972a2f --- /dev/null +++ b/src/core/operations/Print.mjs @@ -0,0 +1,50 @@ +/** + * @author Joshua [ebert.joshua@protonmail.com] + * @copyright Crown Copyright 2024 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; + +/** + * Print operation + */ +class Print extends Operation { + + /** + * Print constructor + */ + constructor() { + super(); + + this.name = "Print"; + this.module = "Other"; + this.description = "Prints a register"; + this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc) + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + name: "Text to print", + type: "string", + value: "" + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + console.log(args); + + //input = args[0].value; + //return input; + return args[0].toString(); + } + +} + +export default Print; From 479bb609f572b513beab66d3ff1142e2ecdf6c3c Mon Sep 17 00:00:00 2001 From: Joshua Ebert Date: Sat, 19 Oct 2024 13:08:10 +0200 Subject: [PATCH 2/2] Made replacing the text optional --- src/core/operations/Print.mjs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core/operations/Print.mjs b/src/core/operations/Print.mjs index d2b1972a2f..4f88c9d680 100644 --- a/src/core/operations/Print.mjs +++ b/src/core/operations/Print.mjs @@ -19,7 +19,7 @@ class Print extends Operation { this.name = "Print"; this.module = "Other"; - this.description = "Prints a register"; + this.description = "Prints a text to the output."; this.infoURL = ""; // Usually a Wikipedia link. Remember to remove localisation (i.e. https://wikipedia.org/etc rather than https://en.wikipedia.org/etc) this.inputType = "string"; this.outputType = "string"; @@ -28,6 +28,11 @@ class Print extends Operation { name: "Text to print", type: "string", value: "" + }, + { + name: "Replace", + type: "boolean", + value: true } ]; } @@ -38,11 +43,11 @@ class Print extends Operation { * @returns {string} */ run(input, args) { - console.log(args); - - //input = args[0].value; - //return input; - return args[0].toString(); + const [text, replace] = args; + if (replace) { + return text.toString(); + } + return input + text.toString(); } }