From 3dddb516c9470d609d87318ffe0469c70802022c Mon Sep 17 00:00:00 2001 From: Adamkadaban Date: Sat, 27 Jul 2024 20:06:18 -0700 Subject: [PATCH 1/2] add offset field to 'Add Line Numbers' operation --- src/core/operations/AddLineNumbers.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/operations/AddLineNumbers.mjs b/src/core/operations/AddLineNumbers.mjs index c1c6159af3..7b05c8484b 100644 --- a/src/core/operations/AddLineNumbers.mjs +++ b/src/core/operations/AddLineNumbers.mjs @@ -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); } From 6b75ba8903149a01575ccdbe3e9f0378e87e52d3 Mon Sep 17 00:00:00 2001 From: Adamkadaban Date: Mon, 13 Jan 2025 15:48:18 -0500 Subject: [PATCH 2/2] fix bug where no input leads to error in console --- src/core/operations/AddLineNumbers.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/operations/AddLineNumbers.mjs b/src/core/operations/AddLineNumbers.mjs index 7b05c8484b..3eee654442 100644 --- a/src/core/operations/AddLineNumbers.mjs +++ b/src/core/operations/AddLineNumbers.mjs @@ -39,7 +39,7 @@ class AddLineNumbers extends Operation { run(input, args) { const lines = input.split("\n"), width = lines.length.toString().length; - const offset = parseInt(args[0], 10); + const offset = args[0] ? parseInt(args[0], 10) : 0; let output = ""; for (let n = 0; n < lines.length; n++) {