read-last-lines
read-last-lines copied to clipboard
read one more line then passed maxLineCount
Description

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
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.