# babel-code-frame

> Generate errors that contain a code frame that point to source locations.

Latest version **6.26.0** (published 2017-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-code-frame
pnpm add babel-code-frame
yarn add babel-code-frame
bun add babel-code-frame
```

## Health

**Score 38/100 (D)** — status: abandoned.

Positive: has types package; no vulnerabilities; high maintenance score; popular repo.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 6.26.0 |
| Published | 2017-08-16 |
| First published | 2015-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/babel-code-frame) |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43994 |
| Author | Sebastian McKenzie |
| Maintainers | thejameskyle, sebmck, danez, hzoo, loganfsmyth |

## Links

- npm: https://www.npmjs.com/package/babel-code-frame
- Repository: https://github.com/babel/babel/tree/master/packages/babel-code-frame
- Homepage: https://babeljs.io/
- npm.io page: https://npm.io/package/babel-code-frame

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [esutils](https://npm.io/package/esutils.md) ^2.0.2
- [js-tokens](https://npm.io/package/js-tokens.md) ^3.0.2

## Recent versions

- 6.26.0 (latest) — 2017-08-16
- 7.0.0-beta.3 (next) — 2017-10-15
- 7.0.0-beta.2 — 2017-09-26
- 7.0.0-beta.1 — 2017-09-19
- 7.0.0-beta.0 — 2017-09-12
- 7.0.0-alpha.20 — 2017-08-30
- 7.0.0-alpha.19 — 2017-08-07
- 7.0.0-alpha.18 — 2017-08-03
- 7.0.0-alpha.17 — 2017-07-26
- 7.0.0-alpha.16 — 2017-07-25
- 7.0.0-alpha.15 — 2017-07-12
- 7.0.0-alpha.14 — 2017-07-12
- 7.0.0-alpha.13 — 2017-07-12
- 7.0.0-alpha.12 — 2017-05-31
- 7.0.0-alpha.11 — 2017-05-31
- … 39 more at https://npm.io/package/babel-code-frame/versions

## README

# babel-code-frame

> Generate errors that contain a code frame that point to source locations.

## Install

```sh
npm install --save-dev babel-code-frame
```

## Usage

```js
import codeFrame from 'babel-code-frame';

const rawLines = `class Foo {
  constructor()
}`;
const lineNumber = 2;
const colNumber = 16;

const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ });

console.log(result);
```

```sh
  1 | class Foo {
> 2 |   constructor()
    |                ^
  3 | }
```

If the column number is not known, you may pass `null` instead.

## Options

### `highlightCode`

`boolean`, defaults to `false`.

Toggles syntax highlighting the code as JavaScript for terminals.

### `linesAbove`

`number`, defaults to `2`.

Adjust the number of lines to show above the error.

### `linesBelow`

`number`, defaults to `3`.

Adjust the number of lines to show below the error.

### `forceColor`

`boolean`, defaults to `false`.

Enable this to forcibly syntax highlight the code as JavaScript (for non-terminals); overrides `highlightCode`.

---
_Source: https://npm.io/package/babel-code-frame · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
