Standard input/output manager for Node.js with command-line parsing, async file reading, interactive terminal, and progress bars
npx @tessl/cli install tessl/npm-stdio@2.1.0stdio is a comprehensive standard input/output management library for Node.js applications, offering TypeScript-first development with promise-based APIs for terminal interactions. It provides command-line argument parsing, asynchronous file reading, interactive terminal capabilities, and visual progress bars.
npm install stdioimport { getopt, read, readLine, ask, ProgressBar } from "stdio";Default import:
import stdio from "stdio";
// Access as stdio.getopt, stdio.read, etc.CommonJS:
const { getopt, read, readLine, ask, ProgressBar } = require("stdio");import { getopt, read, ask, ProgressBar } from "stdio";
// Parse command-line arguments
const options = getopt({
verbose: { key: 'v', description: 'Verbose output' },
output: { key: 'o', args: 1, description: 'Output file' }
});
// Read from stdin line by line
await read(async (line, index) => {
console.log(`Line ${index}: ${line}`);
});
// Ask interactive questions
const name = await ask("What's your name?");
const choice = await ask("Choose option", { options: ['yes', 'no'] });
// Show progress bars
const progress = new ProgressBar(100);
progress.tick(); // Increment by 1
progress.setValue(50); // Set to 50%stdio is built around five core modules:
UNIX-like command-line argument parser with automatic help generation and comprehensive configuration options.
function getopt(
config: Config,
command?: string[],
options?: Options
): GetoptResponse | null;
interface Config {
[key: string]: {
key?: string;
description?: string;
multiple?: boolean;
args?: number | string;
required?: boolean;
default?: string | string[] | boolean;
} | boolean | undefined;
}
interface GetoptResponse {
[key: string]: string | number | boolean | Array<string | number | boolean>;
}Line-by-line processing of standard input or large files without memory concerns, with processing statistics.
function read(
lineHandler: LineHandler,
input?: NodeJS.ReadableStream
): Promise<Stats>;
type LineHandler = (line: string, index: number) => Promise<any>;Read individual lines from standard input with stream management and automatic cleanup.
function readLine(options?: ReadLineOptions): Promise<string>;
interface ReadLineOptions {
stream?: NodeJS.ReadableStream;
close?: boolean;
}Ask questions in terminal with option validation and retry mechanisms.
function ask(question: string, config?: AskConfig): Promise<string>;
interface AskConfig {
options?: string[];
maxRetries?: number;
inputStream?: any;
}Visual command-line progress bars with automatic time calculations and customizable display.
class ProgressBar {
constructor(
size?: number,
options?: {
tickSize?: number;
silent?: boolean;
terminalWidth?: number;
}
);
setValue(value: number): string;
tick(): string;
onFinish(callback: Function): void;
}Core types used across multiple capabilities:
// Common option types
interface Options {
exitOnFailure?: boolean;
throwOnFailure?: boolean;
printOnFailure?: boolean;
}
// Statistics tracking
interface Stats {
length: number;
times: number[];
timeAverage: number;
}