mirror of
https://github.com/gchq/CyberChef.git
synced 2026-01-30 12:20:33 -08:00
Merge fe13f6401d into dd26c09003
This commit is contained in:
commit
f2d81753e0
3 changed files with 87 additions and 0 deletions
|
|
@ -291,6 +291,7 @@
|
|||
"Diff",
|
||||
"Remove whitespace",
|
||||
"Remove null bytes",
|
||||
"Remove ANSI Escape Codes",
|
||||
"To Upper case",
|
||||
"To Lower case",
|
||||
"Swap case",
|
||||
|
|
|
|||
41
src/core/operations/RemoveANSIEscapeCodes.mjs
Normal file
41
src/core/operations/RemoveANSIEscapeCodes.mjs
Normal file
|
|
@ -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|\\e)\[[0-?]*[ -/]*[@-~]/g;
|
||||
return input.replace(ansiRegex, "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default RemoveANSIEscapeCodes;
|
||||
45
tests/operations/tests/RemoveANSIEscapeCodes.mjs
Normal file
45
tests/operations/tests/RemoveANSIEscapeCodes.mjs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* @author Louis-Ladd [lewisharshman1@gmail.com]
|
||||
* @copyright Crown Copyright 2025
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "Remove ANSI Escape Codes: x1b escape code",
|
||||
"input": "\\x1b[31;1;3;4;9mHello, \\x1b[31;1;3;4;9mWorld!",
|
||||
"expectedOutput": "Hello, World!",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Remove ANSI Escape Codes",
|
||||
"args": [
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Remove ANSI Escape Codes: 033 escape code",
|
||||
"input": "\\033[32;1;3;4;9mHello, \\033[32;1;3;4;9mWorld!",
|
||||
"expectedOutput": "Hello, World!",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Remove ANSI Escape Codes",
|
||||
"args": [
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Remove ANSI Escape Codes: e escape code",
|
||||
"input": "\\e[32;1;3;4;9mHello, \\e[32;1;3;4;9mWorld!",
|
||||
"expectedOutput": "Hello, World!",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Remove ANSI Escape Codes",
|
||||
"args": [
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue