Add remove ANSI escape codes operation (#2143)

Co-authored-by: GCHQDeveloper581 <63102987+GCHQDeveloper581@users.noreply.github.com> (additional test case)
This commit is contained in:
A Normal Ladd
2026-06-03 10:57:13 +01:00
committed by GitHub
co-authored by GCHQDeveloper581
parent 89b5c7dee3
commit 72ca1aeec7
4 changed files with 105 additions and 0 deletions
+1
View File
@@ -304,6 +304,7 @@
"Diff",
"Remove whitespace",
"Remove null bytes",
"Remove ANSI Escape Codes",
"To Upper case",
"To Lower case",
"Swap case",
@@ -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://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\[[0-?]*[ -/]*[@-~]/g;
return input.replace(ansiRegex, "");
}
}
export default RemoveANSIEscapeCodes;