read-last-lines icon indicating copy to clipboard operation
read-last-lines copied to clipboard

read one more line then passed maxLineCount

Open tjx666 opened this issue 2 years ago • 1 comments

Description

image

Reproduction

code:

const fs = require('fs/promises');
const readLastLines = require('read-last-lines');

async function main() {
    const testPath = '/Users/yutengjing/code/scripting-listener/package-lock.json';
    const lines = await readLastLines.read(testPath, 3, 'utf8');
    console.log(lines.split('\n').length);
}

main();

test txt file:

asaa


bb



Environment

  • Version of this library used: 1.8.0
  • node: 16.14.0

tjx666 avatar Mar 15 '22 20:03 tjx666

I know this is caused by: https://github.com/alexbbt/read-last-lines/blob/master/src/index.js#L77

if (NEW_LINE_CHARACTERS.includes(nextCharacter) && lines.length > 1) {
	lineCount++;
}

Don't know why you skip the last line to add lineCount.

tjx666 avatar Mar 15 '22 20:03 tjx666