mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Adding character wrap operation and test
This commit is contained in:
parent
d635cca210
commit
ce07f48eab
4 changed files with 82 additions and 1 deletions
35
src/core/operations/Wrap.mjs
Normal file
35
src/core/operations/Wrap.mjs
Normal file
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* @author 0xff1ce [github.com/0xff1ce]
|
||||
* @copyright Crown Copyright 2024
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
|
||||
class Wrap extends Operation {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Wrap";
|
||||
this.module = "Default";
|
||||
this.description = "Wraps the input text at a specified number of characters per line.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Line Width",
|
||||
"type": "number",
|
||||
"value": 64,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
run(input, args) {
|
||||
if (!input) return ""; // Handle empty input
|
||||
const lineWidth = args[0];
|
||||
const regex = new RegExp(`.{1,${lineWidth}}`, 'g');
|
||||
return input.match(regex).join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
export default Wrap;
|
Loading…
Add table
Add a link
Reference in a new issue