File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,13 @@ class AddLineNumbers extends Operation {
22
22
this . description = "Adds line numbers to the output." ;
23
23
this . inputType = "string" ;
24
24
this . outputType = "string" ;
25
- this . args = [ ] ;
25
+ this . args = [
26
+ {
27
+ "name" : "Offset" ,
28
+ "type" : "number" ,
29
+ "value" : 0
30
+ }
31
+ ] ;
26
32
}
27
33
28
34
/**
@@ -33,10 +39,11 @@ class AddLineNumbers extends Operation {
33
39
run ( input , args ) {
34
40
const lines = input . split ( "\n" ) ,
35
41
width = lines . length . toString ( ) . length ;
42
+ const offset = args [ 0 ] ? parseInt ( args [ 0 ] , 10 ) : 0 ;
36
43
let output = "" ;
37
44
38
45
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" ;
40
47
}
41
48
return output . slice ( 0 , output . length - 1 ) ;
42
49
}
You can’t perform that action at this time.
0 commit comments