code-excerpt
Advanced tools
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; | ||
}; |
{ | ||
"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) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3681
27
74