UNPKG

1.06 kBMarkdownView Raw
1# babel-code-frame
2
3> Generate errors that contain a code frame that point to source locations.
4
5## Install
6
7```sh
8npm install --save-dev babel-code-frame
9```
10
11## Usage
12
13```js
14import codeFrame from 'babel-code-frame';
15
16const rawLines = `class Foo {
17 constructor()
18}`;
19const lineNumber = 2;
20const colNumber = 16;
21
22const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ });
23
24console.log(result);
25```
26
27```sh
28 1 | class Foo {
29> 2 | constructor()
30 | ^
31 3 | }
32```
33
34If the column number is not known, you may pass `null` instead.
35
36## Options
37
38### `highlightCode`
39
40`boolean`, defaults to `false`.
41
42Toggles syntax highlighting the code as JavaScript for terminals.
43
44### `linesAbove`
45
46`number`, defaults to `2`.
47
48Adjust the number of lines to show above the error.
49
50### `linesBelow`
51
52`number`, defaults to `3`.
53
54Adjust the number of lines to show below the error.
55
56### `forceColor`
57
58`boolean`, defaults to `false`.
59
60Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`.