Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

readline2

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

readline2

Readline Façade fixing bugs and issues found in releases 0.8 and 0.10

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is readline2?

The readline2 npm package is a Node.js module that provides an interface for reading data from a Readable stream (such as process.stdin) one line at a time. It is a more feature-rich and flexible alternative to the built-in readline module in Node.js.

What are readline2's main functionalities?

Basic Line Reading

This feature allows you to read a line of input from the user and then process it. The example code demonstrates how to prompt the user for their name and then print a greeting.

const readline = require('readline2');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.question('What is your name? ', (answer) => {
  console.log(`Hello, ${answer}!`);
  rl.close();
});

Handling Multiple Lines

This feature allows you to handle multiple lines of input. The example code demonstrates how to listen for 'line' events and process each line of input as it is received.

const readline = require('readline2');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', (input) => {
  console.log(`Received: ${input}`);
});

rl.on('close', () => {
  console.log('Interface closed');
});

Custom Completer

This feature allows you to provide custom tab completion for user input. The example code demonstrates how to set up a completer that suggests commands like 'help', 'error', and 'exit'.

const readline = require('readline2');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  completer: (line) => {
    const completions = 'help error exit'.split(' ');
    const hits = completions.filter((c) => c.startsWith(line));
    return [hits.length ? hits : completions, line];
  }
});

rl.question('Type a command: ', (answer) => {
  console.log(`You typed: ${answer}`);
  rl.close();
});

Other packages similar to readline2

Keywords

FAQs

Package last updated on 17 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc