Build dynamic prompts

Build advanced dynamic prompts with just a JSON, easy as it has never been before.

app.js
package.json
const prompts = [
{ prompts: '...' },
{ cond: '...' },
{ loop: '...' },
{ variables: '...' },
// ...
]

How to use

Tutorial

Follow this tutorial to learn everything you need to know.


Overview

The Prompts package empowers users to craft engaging and interactive prompts. Within these prompts, users are presented with questions, and they can respond using a variety of prompt types, such as text, number, select, and multiselect.

However, for users seeking to incorporate advanced logic and dependencies based on previous answers, the process can become intricate. That's where Promptsity steps in, offering a streamlined solution through the use of just a JSON.

Dependencies

Promptsity depends on two packages, Mongu and Prompts. We suggest you to be at least a little familiar with these packages before moving on with this tutorial.

Installation

To install this package you have to run the following command.

npm install promptsity

Basic usage

To use this package you have to import the promptsity function and call this function passing as argument a JSON that defines all the logic of the prompts.

const { promptsity } = require('promptsity')

const prompts = require('./prompts.json')

async function main() {
  const result = await promptsity(prompts)
  console.log(result)
}

main()

This is an example of a JSON that we could use.

[
  {
    "prompts": [
      { "type": "text", "name": "name", "message": "What is your name?" },
      { "type": "text", "name": "surname", "message": "What is your surname?" }
    ]
  },
  {
    "return": { "$concat": ["$name", " ", "$surname"] }
  }
]

The JSON is defined as an array of elements of different types. All of these used in combination let you create any kind of logic you want.

The type of elements that exist are Prompts, Return, Variables, Condition and Loop. You can find more about them in the next part of the documentation.

License

MIT License