code-error
Wrapper around Error intended for build/dev tools to use to report errors found in source code in any language. You supply the text body and line number details, and this offers methods for getting a pretty-printed excerpt of the text body highlighting the location of the error.
Install
npm install code-error
Use
; const error = message options; errorexcerpt; // plain text excerpterroransiExcerpt; // same with some colour using ANSI escape codeserrorexcerptHTML; // same but colours done in HTMLerrorsuffix; // a conventional filename suffix such as ":12:34" meaning line 12, col 34
Options
file
(string) – the path to the filecontents
(string/buffer) – the contents of the fileline
(number) – the line on which the error occured (starting from 1 – there is no line 0)column
(number) – the column where the error occured (again, starting from 1)maxLines
(number, default:8
) – the maximum number of lines of context to show before the error.
(In future endLine
and endColumn
might be used, but currently these are ignored.)