diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 434c8bb619..1671c0133e 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -291,6 +291,7 @@ "Diff", "Remove whitespace", "Remove null bytes", + "Remove ANSI Escape Codes", "To Upper case", "To Lower case", "Swap case", diff --git a/src/core/operations/RemoveANSIEscapeCodes.mjs b/src/core/operations/RemoveANSIEscapeCodes.mjs new file mode 100644 index 0000000000..dbaeb706fe --- /dev/null +++ b/src/core/operations/RemoveANSIEscapeCodes.mjs @@ -0,0 +1,41 @@ +/** + * @author Louis-Ladd [lewisharshman1@gmail.com] + * @copyright Crown Copyright 2025 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; + +/** + * Remove ANSI Escape Codes operation + */ +class RemoveANSIEscapeCodes extends Operation { + + /** + * RemoveANSIEscapeCodes constructor + */ + constructor() { + super(); + + this.name = "Remove ANSI Escape Codes"; + this.module = "Default"; + this.description = "Removes ANSI Escape Codes."; + this.infoURL = "https://en.wikipedia.org/wiki/ANSI_escape_code"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const ansiRegex = /(?:\x1B|\\x1b|\\033|\\u001b)\[[0-?]*[ -/]*[@-~]/g; + return input.replace(ansiRegex, ""); + } + +} + +export default RemoveANSIEscapeCodes;