Last active
October 18, 2021 01:14
-
-
Save johandalabacka/53d93dba910a0af3cb0462c1ba5f0f03 to your computer and use it in GitHub Desktop.
Iterator file lines (naive version)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs/promises'; | |
async function* lines(path) { | |
const content = await fs.readFile(path, { encoding: 'utf-8' }) | |
const lines = content.split(/\n/) | |
for (const line of lines) { | |
yield line | |
} | |
} | |
for await (let i of lines('app.mjs')) { | |
console.log('>>' + i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment