Skip to content

Commit

Permalink
Merge pull request #1866 from Adamkadaban/master
Browse files Browse the repository at this point in the history
add offset field to 'Add Line Numbers' operation
  • Loading branch information
a3957273 authored Feb 11, 2025
2 parents e1d3af2 + d4da81f commit bf36fe8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/core/operations/AddLineNumbers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
];
}

/**
Expand All @@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
run(input, args) {
const lines = input.split("\n"),
width = lines.length.toString().length;
const offset = args[0] ? parseInt(args[0], 10) : 0;
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);
}
Expand Down

0 comments on commit bf36fe8

Please sign in to comment.