Projekt

Obecné

Profil

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