Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

code-excerpt

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-excerpt

Extract code excerpts

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
866K
decreased by-19.43%
Maintainers
1
Weekly downloads
 
Created

What is code-excerpt?

The code-excerpt npm package is designed to extract and highlight excerpts from code snippets. It is particularly useful for creating documentation, tutorials, or any content that requires displaying code with specific lines highlighted.

What are code-excerpt's main functionalities?

Extracting Code Excerpts

This feature allows you to extract a specific range of lines from a code snippet. The `start` and `end` options specify the range of lines to be extracted.

const codeExcerpt = require('code-excerpt');
const code = `
function add(a, b) {
  return a + b;
}

console.log(add(2, 3));
`;
const excerpt = codeExcerpt(code, { start: 2, end: 4 });
console.log(excerpt);
// Output:
// {
//   value: '  return a + b;\n}\n\nconsole.log(add(2, 3));\n',
//   start: 2,
//   end: 4
// }

Highlighting Specific Lines

This feature allows you to highlight specific lines within the extracted code excerpt. The `highlight` option takes an array of line numbers to be highlighted.

const codeExcerpt = require('code-excerpt');
const code = `
function add(a, b) {
  return a + b;
}

console.log(add(2, 3));
`;
const excerpt = codeExcerpt(code, { start: 2, end: 4, highlight: [3] });
console.log(excerpt);
// Output:
// {
//   value: '  return a + b;\n}\n\nconsole.log(add(2, 3));\n',
//   start: 2,
//   end: 4,
//   highlight: [3]
// }

Other packages similar to code-excerpt

FAQs

Package last updated on 05 Jan 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc