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 - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

22

index.js

@@ -18,15 +18,2 @@ 'use strict';

function extendLines(lines) {
const maxLength = Math.max.apply(null, lines.map(line => line.value.length));
return lines
.map(line => {
if (line.value.length < maxLength) {
line.value += ' '.repeat(maxLength - line.value.length);
}
return line;
});
}
module.exports = (source, line, options) => {

@@ -47,12 +34,7 @@ if (typeof source !== 'string') {

options = Object.assign({
around: 3,
equalLength: true
}, options);
options = Object.assign({around: 3}, options);
const output = generateLineNumbers(line, options.around)
return generateLineNumbers(line, options.around)
.filter(line => source[line - 1] !== undefined)
.map(line => ({line, value: source[line - 1]}));
return options.equalLength ? extendLines(output) : output;
};

2

package.json
{
"name": "code-excerpt",
"version": "1.1.0",
"version": "2.0.0",
"description": "Extract code excerpts",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -1,2 +0,2 @@

# code-excerpt [![Build Status](https://travis-ci.org/vdemedes/code-excerpt.svg?branch=master)](https://travis-ci.org/vdemedes/code-excerpt)
# code-excerpt [![Build Status](https://travis-ci.org/vadimdemedes/code-excerpt.svg?branch=master)](https://travis-ci.org/vadimdemedes/code-excerpt)

@@ -34,9 +34,9 @@ > Extract code excerpts

//=> [
// {line: 2, value: ' '},
// {line: 3, value: 'function someFunc() {} '},
// {line: 4, value: ' '},
// {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; '}
// {line: 6, value: ' const a = 1;'},
// {line: 7, value: ' const b = 2;'},
// {line: 8, value: ' const c = 3;'}
// ]

@@ -50,5 +50,2 @@ ```

All lines in the output have equal width for convenience (customizable via `options.equalLength`).
For example, if a line needs to be highlighted, the highlight will be full-width, just like in editors.
#### source

@@ -75,12 +72,5 @@

##### equalLength
Type: `boolean`<br>
Default: `true`
Extend lines to the same length. Useful for highlighting lines.
## License
MIT © [vdemedes](https://github.com/vdemedes)
MIT © [Vadim Demedes](https://github.com/vadimdemedes)
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