prompts
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
kleur | 3.0.3 | 4.19 kB | MIT | prod | |
sisteransi | 1.0.5 | 2.54 kB | MIT | prod |
Prompts is a lightweight, user-friendly, and attractive NPM package that provides interactive command line interfaces. Specific features that make Prompts stand out include its use of promises and async/await functionality, eliminating callback clutter. Each prompt type is independent and can be used separately. Their interfaces leverage layout and colors to create a beautiful CLI experience.
To use prompts, you'll first need to install the NPM package in your project using the command npm install --save prompts
. After this, you can import it into your JavaScript file with const prompts = require('prompts');
There are multiple ways to use prompts, depending on the interaction you want with the user. Here are a few examples:
For a single text prompt usage:
const prompts = require('prompts');
(async () => {
const response = await prompts({
type: 'text',
name: 'meaning',
message: 'What is the meaning of life?'
});
console.log(response.meaning);
})();
For multiple questions, you can chain the prompts together:
const prompts = require('prompts');
const questions = [
{
type: 'text',
name: 'username',
message: 'What is your GitHub username?'
},
{
type: 'number',
name: 'age',
message: 'How old are you?'
},
{
type: 'text',
name: 'about',
message: 'Tell something about yourself',
initial: 'Why should I?'
}
];
(async () => {
const response = await prompts(questions);
// => response => { username, age, about }
})();
Dynamic prompts, where the property values can be functions are also supported:
const prompts = require('prompts');
const questions = [
{
type: 'text',
name: 'dish',
message: 'Do you like pizza?'
},
{
type: prev => prev == 'pizza' ? 'text' : null,
name: 'topping',
message: 'Name a topping'
}
];
(async () => {
const response = await prompts(questions);
})();
The Prompts documentation can be found directly in its README file on its GitHub page, at the URL https://github.com/terkelg/prompts
. The README contains detailed information on how to install and use Prompts, examples of its usage, API details, and more.