Line by line async iterator for node.js
- Uses ESNext async iteration
- Use with
--harmony-async-iterator
flag - Can use with IxJS
- Supports custom promises
- Typescript definitions included
npm install --save lines-async-iterator
# or
yarn add lines-async-iterator
const lines = require("lines-async-iterator");
async function printLines() {
for await(const line of lines("file.txt")){
console.log(line);
}
}
printLines();
const lines = require("lines-async-iterator");
const { promisify } = require("bluebird");
async function printLines() {
for await(const line of lines("file.txt", promisify)){
console.log(line);
}
}
printLines();
const lines = require("lines-async-iterator");
const Ix = require("ix");
async function printEqualLines() {
const iterator = Ix.AsyncIterator
.zip(lines("1.txt"), lines("2.txt"))
.map(([line_1, line_2]) => [
line_1.toLowerCase(),
line_2.toLowerCase(),
])
.filter(([line_1, line_2]) => line_1 === line_2);
console.log("These lines are the same:");
for await(const ([line_1, line_2]) of iterator){
console.log(`${line_1} === ${line_2}`);
}
}
printEqualLines();