Inquirer.js: Continuous prompting

Created on 1 Jul 2017  路  3Comments  路  Source: SBoudrias/Inquirer.js

Does inquirer.js currently have an api for continuously prompting the user?

For example, something like:

What are your favorite animals? (Leave empty when done) cats
What are your favorite animals? (Leave empty when done) dogs
What are your favorite animals? (Leave empty when done) lions
What are your favorite animals? (Leave empty when done)

...

And then the promise would return an array of answers, or in this case: ['cats', 'dogs', 'lions']

Most helpful comment

You can do something just like this @mechanical-turk

I know that is closed but may this will help him

  function myFunction(callback) {
  prompt(questions).then(answ => {
    usersList.push({
      name: answ.userName,
      value: answ.userValue
    });

    if ( /* repeat condition */ ) {
      myFunction(() => {
        callback();
      });
    } else {
      callback()
    }
  })
}

All 3 comments

No, but you can use recursion to do the same thing by yourself. No need for an API, just use JavaScript :)

You can do something just like this @mechanical-turk

I know that is closed but may this will help him

  function myFunction(callback) {
  prompt(questions).then(answ => {
    usersList.push({
      name: answ.userName,
      value: answ.userValue
    });

    if ( /* repeat condition */ ) {
      myFunction(() => {
        callback();
      });
    } else {
      callback()
    }
  })
}

@Rawnly thanks mate

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PierBover picture PierBover  路  6Comments

aguerrieri picture aguerrieri  路  6Comments

lvjiaxuan picture lvjiaxuan  路  6Comments

XhmikosR picture XhmikosR  路  7Comments

dantasfiles picture dantasfiles  路  3Comments