mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
ESM: Ported Tidy operations. Updated portOperation script to attempt to find the run function and list related constants.
This commit is contained in:
parent
037e2f3771
commit
66c768fe31
6 changed files with 409 additions and 6 deletions
70
src/core/operations/PadLines.mjs
Normal file
70
src/core/operations/PadLines.mjs
Normal file
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
|
||||
/**
|
||||
* Pad lines operation
|
||||
*/
|
||||
class PadLines extends Operation {
|
||||
|
||||
/**
|
||||
* PadLines constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Pad lines";
|
||||
this.module = "Default";
|
||||
this.description = "Add the specified number of the specified character to the beginning or end of each line";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Position",
|
||||
"type": "option",
|
||||
"value": ["Start", "End"]
|
||||
},
|
||||
{
|
||||
"name": "Length",
|
||||
"type": "number",
|
||||
"value": 5
|
||||
},
|
||||
{
|
||||
"name": "Character",
|
||||
"type": "binaryShortString",
|
||||
"value": " "
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [position, len, chr] = args,
|
||||
lines = input.split("\n");
|
||||
let output = "",
|
||||
i = 0;
|
||||
|
||||
if (position === "Start") {
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
output += lines[i].padStart(lines[i].length+len, chr) + "\n";
|
||||
}
|
||||
} else if (position === "End") {
|
||||
for (i = 0; i < lines.length; i++) {
|
||||
output += lines[i].padEnd(lines[i].length+len, chr) + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return output.slice(0, output.length-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PadLines;
|
Loading…
Add table
Add a link
Reference in a new issue