console-questions

1.1.1 • Public • Published

console-questions

console-questions is a simple way to make questions on the console.

logo

Instalation

  • From npm:

    npm install console-questions
    
  • From GitHub:

    npm install https://github.com/javalsai/console-questions
    

Code Sample

easy code sample with it's result

Just as simple as that.

Structure

The returned module is a EventEmitter overwritten.

{

}

// The events of the EventEmitter are at events.

Options

This are the default options used in the module.

{
    after: '\n', // A string to put after every question
    before: '',  // A string to put before every question
    limit: null, // The limit of time to answer a question in ms (if exceeded return null)
    showTyping: true, // If show what the user is typing or not

    callback: () => {} // Just a callback
}

Functions

ask (question: String, options: Object)

  • Return value: Promise
  • Arguments:
    • String (the question)
    • Object the options.
  • Resolved value: String (the user response for the question).

// The options will be assigned with Object.assign() to the default options.


setDefaultOptions (options)

  • Return value: options (the argument).
  • Argumets:

// Set the default options instead of using the default options.


getDefaultOptions ()

// IMPORTANT: Returns the default options, not your customized default options.


getCustomizedOptions ()

// IMPORTANT: Returns your customized default options not the default options.


restartOptions ()

// This restart your customized default options to the default options.


Events

"keypress"

Emited when a key is pressed.

const cq = require('console-questions');

cq.on('keypress', key => {
    console.log('You pressed: ' + key);
});

"input"

Emited when the user press Enter.

const cq = require('console-questions');

cq.on('input', sentence => {
    console.log('You written: \n' + sentence);
});

Other

  • Go to the main page at npm of this package.
  • Please, report issues at GitHub.
  • Join our discord community to make your suggestions, ask some doubts or vote for new features.

Package Sidebar

Install

npm i console-questions

Weekly Downloads

6

Version

1.1.1

License

ISC

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • javalsai