0.1.2 • Published 5 years ago
n-readline v0.1.2
n-readline
Features
- Read text files line by line.
- Support for pause/resume operations.
- Skip and limit strings.
Commands
npm i n-readlineUsage
const NReadline = require('n-readline')
let rl = new NReadline({
filepath: './example.txt',
start: 100,
limit: 50,
skipEmptyLines: true
})
rl.start()
rl.on('error', err => console.log('Error', err))
rl.on('line', (line, lineNumber) => {
// on line 110, pause reader for 100ms
if (lineNumber === 109) {
rl.pause()
setTimeout(() => rl.resume(), 100)
// on line 120, stop reader
} else if (lineNumber === 119) {
rl.stop()
}
console.log(line, lineNumber)
})
rl.on('end', () => console.log('Done'))API
constructor(params)
Creates instance of NReadline.
filepath: the path to the source file.encoding: text encoding used by a read stream,utf8by default.start: the first string number to read, zero based.limit: the count of strings to read.skipEmptyLines: if true, skips empty lines, otherwise not,falseby default.
start(): void
Starts reader.
pause: void
Pauses reader.
resume: void
Resumes reader.
stop: void
Stops reader.
on(event: string; handler: () => {})
Event handler.
error: emitted in the case of any error, parametererr.line: emitted when a next string is read, parameterslineandlineNumber.end: emitted when the whole file is read orstopwas called.
Author
Alexander Mac
Licence
Licensed under the MIT license.