aboutsummaryrefslogtreecommitdiff
path: root/node_modules/code-excerpt/readme.md
blob: 216b6b3d5c8c753fe833785d49e318c0e52d4b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# code-excerpt [![Build Status](https://travis-ci.org/vadimdemedes/code-excerpt.svg?branch=master)](https://travis-ci.org/vadimdemedes/code-excerpt)

> Extract code excerpts


## Install

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


## Usage

```js
const codeExcerpt = require('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.


## License

MIT © [Vadim Demedes](https://github.com/vadimdemedes)