Socket
Socket
Sign inDemoInstall

code-excerpt

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    code-excerpt

Extract code excerpts


Version published
Weekly downloads
742K
decreased by-6.91%
Maintainers
1
Install size
9.11 kB
Created
Weekly downloads
 

Readme

Source

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.

FAQs

Last updated on 06 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc