print-code
Print visualized slice of code from its content, line and column for CLI.
Install
$ npm install print-code --save
Usage
var code = ;
And then the output might be (Line No 4 is red):
1| 'use strict';
2|
3| module.exports = code
4| code.Code = Code
----------------^ column: 10
5|
.slice([from] [, to])
Specify which lines should be printed.
- from
Number=
The line number begins to be printed, and the value will beparseInt()
ed. If not specified, it will print all lines. If - to
Number=
If not specified, it will only print the line offrom
; // print all code; // print line 10; // print lines from [10, 20)
Special cases:
; // will print lines from [0, 10); // will print lines except for the last line.; // will only print line 10; // will print line 10
.highlight(line [, ...])
Specify which line number(s) should be highlighted.
- line
Number
The number of code line, starts from1
.max_columns(max)
Limit the max columns to be printed.
- max
Number=
default to the max columns of the current terminal.
.arrow_mark(line, column)
Set a mark, and draw an arrow mark to the target coordinate (line, column).
.get()
Get the formated result content.
.print()
console.log
the formated result content.
License
MIT