# code-excerpt

> Extract code excerpts

Latest version **4.0.0** (published 2022-02-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install code-excerpt
pnpm add code-excerpt
yarn add code-excerpt
bun add code-excerpt
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-02-06 |
| First published | 2016-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 1 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | vdemedes |
| Maintainers | vdemedes |

## Links

- npm: https://www.npmjs.com/package/code-excerpt
- Repository: https://github.com/vadimdemedes/code-excerpt
- Homepage: https://github.com/vadimdemedes/code-excerpt#readme
- Issues: https://github.com/vadimdemedes/code-excerpt/issues
- npm.io page: https://npm.io/package/code-excerpt

## Dependencies (1)

- [convert-to-spaces](https://npm.io/package/convert-to-spaces.md) ^2.0.1

## Recent versions

- 4.0.0 (latest) — 2022-02-06
- 3.0.0 — 2020-06-16
- 2.1.1 — 2018-01-20
- 2.1.0 — 2017-02-01
- 2.0.0 — 2017-01-05
- 1.1.0 — 2017-01-05
- 1.0.2 — 2016-11-19
- 1.0.1 — 2016-11-13
- 1.0.0 — 2016-11-13

## README

# code-excerpt ![test](https://github.com/vadimdemedes/code-excerpt/workflows/test/badge.svg)

> Extract code excerpts

## Install

```
$ npm install --save code-excerpt
```

## Usage

```js
import codeExcerpt from 'code-excerpt';

const source = `
'use strict';

function someFunc() {}

module.exports = () => {
	const a = 1;
	const b = 2;
	const c = 3;

	someFunc();
};
`.trim();

const excerpt = codeExcerpt(source, 5);
//=> [
//	{line: 2, value: ''},
//	{line: 3, value: 'function someFunc() {}'},
//	{line: 4, value: ''},
//	{line: 5, value: 'module.exports = () => {'},
//	{line: 6, value: '  const a = 1;'},
//	{line: 7, value: '  const b = 2;'},
//	{line: 8, value: '  const c = 3;'}
// ]
```

## API

### codeExcerpt(source, line, [options])

#### source

Type: `string`

Source code.

#### line

Type: `number`

Line number to extract excerpt for.

#### options

##### around

Type: `number`<br>
Default: `3`

Number of surrounding lines to extract.

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