0

I'm using Enquirer, not Inquirer, but there is no tag for Enquirer and I don't have 1500 reputation to create one, so I'm using Inquirerjs instead.

Code of example prompt, where I tried to use object choices (got the idea from here), but it does not contain value with zero index. That's unproductive solution anyway. Also I remember that somehow, when I was trying to get only values from pair of key:value from custom map, about which says official documentation and its given example, I got the indexes of answers, but as I sat here brainstorming for an hour - sadly, I cannot remeber how I did it. So, how do you do it, what it says in the title?

Tried:

enquirer.prompt({
    type: 'multiselect',
    name: 'choice',
    choices: [
        {name: `dynamiclyGeneratedName`, value: `dynamicID`},
        {name: `dynamiclyGeneratedName`, value: `dynamicID`},
        ...
    ],
    result (result) {
        return Object.fromEntries(Object.entries(this.choices).filter(([key, value]) => value.enabled));
    },
})
.then(async (result) => {
    console.log(result);
})
.catch(console.error);

From official documentation:

  result(names) {
   return this.map(names);
  }

Expected result:

{
    choice: [0, 6, 9]
}

0 Answers0