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,442,096
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

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin