mirror of
https://github.com/gchq/CyberChef
synced 2025-01-25 18:55:02 +00:00
add offset field to 'Add Line Numbers' operation
This commit is contained in:
parent
a477f47aec
commit
3dddb516c9
1 changed files with 9 additions and 2 deletions
|
@ -22,7 +22,13 @@ class AddLineNumbers extends Operation {
|
|||
this.description = "Adds line numbers to the output.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
this.args = [
|
||||
{
|
||||
"name": "Offset",
|
||||
"type": "number",
|
||||
"value": 0
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
|
|||
run(input, args) {
|
||||
const lines = input.split("\n"),
|
||||
width = lines.length.toString().length;
|
||||
const offset = parseInt(args[0], 10);
|
||||
let output = "";
|
||||
|
||||
for (let n = 0; n < lines.length; n++) {
|
||||
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n";
|
||||
output += (n+1+offset).toString().padStart(width, " ") + " " + lines[n] + "\n";
|
||||
}
|
||||
return output.slice(0, output.length-1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue