1. code-excerpt
Extract code excerpts
code-excerpt
Package: code-excerpt
Created by: vadimdemedes
Last modified: Mon, 13 Jun 2022 06:25:15 GMT
Version: 4.0.0
License: MIT
Downloads: 3,180,731
Repository: https://github.com/vadimdemedes/code-excerpt

Install

npm install code-excerpt
yarn add code-excerpt

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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code