Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
"Diff",
"Remove whitespace",
"Remove null bytes",
"Remove ANSI Escape Codes",
"To Upper case",
"To Lower case",
"Swap case",
Expand Down
41 changes: 41 additions & 0 deletions src/core/operations/RemoveANSIEscapeCodes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @author Louis-Ladd [[email protected]]
* @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;
Loading