How do I format data from an Inquirer output into markdown file

330 Views Asked by At

I'm making a README generator for a school project, and my inquirer prompts are all functioning fine, but when I call the data from this prompt:

{
  type: "checkbox",
  name: "languages",
  message: "What languages/technologies were used to create this project?",
  choices: ["HTML", "CSS", "JavaScript", "Node.JS"],
}

I am using template literal to incorporate. The corresponding markdown entry appears as such:

${data.languages}
## Technologies Used
HTML,CSS,JavaScript,Node.JS

with no spaces. My preference would be to have them appear as a list. How would I go about formatting this?

1

There are 1 best solutions below

1
Phil On

Inquirer's checkbox prompt resolves with an array.

To format that as Markdown, you would use something like

inquirer
  .prompt([
    /*...*/
  ])
  .then((answers) => {
    const { languages } = answers;

    const languagesList = languages
      .map((language) => `* ${language}`)
      .join("\n");
  });

This should produce a markdown list like

* HTML
* CSS
* JavaScript
* Node.JS