console-questions
is a simple way to make questions on the console.
-
From npm:
npm install console-questions
-
From GitHub:
npm install https://github.com/javalsai/console-questions
Just as simple as that.
The returned module is a EventEmitter
overwritten.
{
- ask:
[Function: ask]
, - setDefaultOptions:
[Function: setDefaultOptions]
- getDefaultOptions:
[Function: getDefaultOptions]
- getCustomizedOptions:
[Function: getCustomizedOptions]
- restartOptions:
[Function: restartOptions]
}
// The events of the EventEmitter
are at events.
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
}
- 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.
- Return value: options (the argument).
- Argumets:
Object
: Options
// Set the default options instead of using the default options.
- Return value: The default options.
- Arguments: None.
// IMPORTANT: Returns the default options, not your customized default options.
- Return value: Your customized default options.
- Arguments: None.
// IMPORTANT: Returns your customized default options not the default options.
- Return value: The default options.
- Arguments: None.
// This restart your customized default options to the default options.
Emited when a key is pressed.
const cq = require('console-questions');
cq.on('keypress', key => {
console.log('You pressed: ' + key);
});
Emited when the user press Enter
.
const cq = require('console-questions');
cq.on('input', sentence => {
console.log('You written: \n' + sentence);
});