What is @types/prompts?
@types/prompts provides TypeScript type definitions for the 'prompts' library, which is used to create interactive command-line prompts.
What are @types/prompts's main functionalities?
Basic Text Prompt
This feature allows you to create a basic text prompt where the user can input a string. The example asks for the user's name and then greets them.
const prompts = require('prompts');
(async () => {
const response = await prompts({
type: 'text',
name: 'value',
message: 'What is your name?'
});
console.log(`Hello, ${response.value}!`);
})();
Select Prompt
This feature allows you to create a select prompt where the user can choose from a list of options. The example lets the user pick a color from a list.
const prompts = require('prompts');
(async () => {
const response = await prompts({
type: 'select',
name: 'color',
message: 'Pick a color',
choices: [
{ title: 'Red', value: 'red' },
{ title: 'Green', value: 'green' },
{ title: 'Blue', value: 'blue' }
],
initial: 1
});
console.log(`You chose: ${response.color}`);
})();
Confirm Prompt
This feature allows you to create a confirm prompt where the user can answer with a yes or no. The example asks if the user wants to continue and logs the response.
const prompts = require('prompts');
(async () => {
const response = await prompts({
type: 'confirm',
name: 'value',
message: 'Do you want to continue?'
});
console.log(response.value ? 'Continuing...' : 'Aborted');
})();
Other packages similar to @types/prompts
inquirer
Inquirer.js is a collection of common interactive command-line user interfaces. It provides similar functionalities to 'prompts' but with a more extensive set of features and customization options.
enquirer
Enquirer is a stylish, intuitive, and user-friendly prompt system for Node.js. It offers similar functionalities to 'prompts' but focuses more on customization and user experience.
vorpal
Vorpal is a framework for building interactive CLI applications. It provides similar prompt functionalities but also includes features for building more complex command-line interfaces.