# highlight-error

> This is a small utility that helps you format error positions in code.

Latest version **1.0.2** (published 2017-06-17) · 0 weekly downloads

## Install

```sh
npm install highlight-error
pnpm add highlight-error
yarn add highlight-error
bun add highlight-error
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-06-17 |
| First published | 2017-06-17 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | dwaynejf |

## Links

- npm: https://www.npmjs.com/package/highlight-error
- npm.io page: https://npm.io/package/highlight-error

## Dependencies (3)

- [chalk](https://npm.io/package/chalk.md) ^1.1.3
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [lines-and-columns](https://npm.io/package/lines-and-columns.md) ^1.1.6

## Recent versions

- 1.0.2 (latest) — 2017-06-17
- 1.0.1 — 2017-06-17
- 1.0.0 — 2017-06-17

## README

# highlight-error

This is a small utility that helps you format error positions in code.

### Installation

```bash
npm install --save highlight-error
```

### Usage

```js
const highlightError = require('highlight-error');

const code = `function a() {
  return a + *;
}`;

console.log(highlightError(code, {
  line: 2,
  column: 13
}));
```

This will print:

![colored example](https://raw.githubusercontent.com/droooney/highlight-error/master/colored_example.png)

If you want the output without colors just add the option:

```js
console.log(highlightError(code, {
  line: 2,
  column: 13
}, { colors: false }));
```

This will print:

```
  1 | function a() {
> 2 |   return a + *;
                   ^
  3 | }
```

### API

##### highlightError

```
highlightError(
  code: string,
  pos: Location | number,
  options?: Options
): string
```

The first argument is the code you want to highlight the error in.

The second argument is the error position. Can be a number (meaning
the position from the start of the code) or a `{ line, column }` object
with 1-indexed line.

The third argument is options:

* `options.neighborLinesCount` (default: `2`): how many lines above
and below the selected line should be printed.
* `options.colors` (default: `true`): whether to use colors for the
output or not.

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