Skip to content

Instantly share code, notes, and snippets.

@johandalabacka
Last active October 18, 2021 01:14
Show Gist options
  • Save johandalabacka/53d93dba910a0af3cb0462c1ba5f0f03 to your computer and use it in GitHub Desktop.
Save johandalabacka/53d93dba910a0af3cb0462c1ba5f0f03 to your computer and use it in GitHub Desktop.
Iterator file lines (naive version)
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