@suaveplan/readline - Terminal I/O primitive: AsyncGenerator line reader and interactive prompt interface
Summary
AsyncGenerator line reader and interactive prompt interface for Node.js streams, file paths, and Web Streams.
Documentation tree
- errors — (no submodules)
- errors — (no submodules)
- interface — (no submodules)
- interface — (no submodules)
- reader — (no submodules)
- reader — (no submodules)
- scanner — (no submodules)
- scanner — (no submodules)
Install
bun add @suaveplan/readline
Modules
| Module | Description | Docs |
|---|---|---|
reader |
readLines() — multi-source AsyncGenerator line reader |
reader.md |
interface |
createInterface() — interactive prompt / REPL interface |
interface.md |
errors |
ReadlineError and stable error-code registry |
errors.md |
Quick Start
readLines() — iterate lines from any source
import { readLines } from "@suaveplan/readline/reader/reader";
// From a file path
for await (const line of readLines("/var/log/app.log")) {
console.log(line);
}
// From a Node.js Readable
import { createReadStream } from "node:fs";
for await (const line of readLines(createReadStream("data.csv"), { skipEmpty: true })) {
process(line);
}
// With abort support and line-length guard
const ac = new AbortController();
setTimeout(() => ac.abort(), 5_000);
for await (const line of readLines("huge.txt", { maxLineLength: 4096, signal: ac.signal })) {
console.log(line);
}
createInterface() — interactive prompt
import { createInterface } from "@suaveplan/readline/interface/interface";
const rl = createInterface({ input: process.stdin, output: process.stdout });
const name = await rl.question("Your name: ");
console.log(`Hello, ${name}!`);
// Iterate all lines (useful for piped input)
for await (const line of rl) {
if (line === "quit") break;
console.log(`echo: ${line}`);
}
rl.close();
Benchmarks
Measured on Linux 6.6 / WSL2, Bun v1.x, AMD Ryzen 9 5900X.
Scanner throughput (createScanner)
| Benchmark | ops/sec | avg latency |
|---|---|---|
| scanner 1 MB (50 k lines) | PLACEHOLDER | PLACEHOLDER |
| scanner 10 MB (500 k lines) | PLACEHOLDER | PLACEHOLDER |
Reader throughput (readLines)
| Benchmark | ops/sec | avg latency |
|---|---|---|
| readLines() file path (10 k lines) | PLACEHOLDER | PLACEHOLDER |
| readLines() Readable (10 k lines) | PLACEHOLDER | PLACEHOLDER |
License
MIT