code-excerpt
Extract code excerpts
Last updated 4 years ago by vdemedes .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install code-excerpt 
SYNC missed versions from official npm registry.

code-excerpt test

Extract code excerpts

Install

$ npm install --save code-excerpt

Usage

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
Default: 3

Number of surrounding lines to extract.

Current Tags

  • 4.0.0                                ...           latest (3 years ago)

9 Versions

  • 4.0.0                                ...           3 years ago
  • 3.0.0                                ...           4 years ago
  • 2.1.1                                ...           7 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE