Skip to content

Commit bf36fe8

Browse files
authored
Merge pull request #1866 from Adamkadaban/master
add offset field to 'Add Line Numbers' operation
2 parents e1d3af2 + d4da81f commit bf36fe8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/core/operations/AddLineNumbers.mjs

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ class AddLineNumbers extends Operation {
2222
this.description = "Adds line numbers to the output.";
2323
this.inputType = "string";
2424
this.outputType = "string";
25-
this.args = [];
25+
this.args = [
26+
{
27+
"name": "Offset",
28+
"type": "number",
29+
"value": 0
30+
}
31+
];
2632
}
2733

2834
/**
@@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
3339
run(input, args) {
3440
const lines = input.split("\n"),
3541
width = lines.length.toString().length;
42+
const offset = args[0] ? parseInt(args[0], 10) : 0;
3643
let output = "";
3744

3845
for (let n = 0; n < lines.length; n++) {
39-
output += (n+1).toString().padStart(width, " ") + " " + lines[n] + "\n";
46+
output += (n+1+offset).toString().padStart(width, " ") + " " + lines[n] + "\n";
4047
}
4148
return output.slice(0, output.length-1);
4249
}

0 commit comments

Comments
 (0)