Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prompts

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompts

Lightweight, beautiful and user-friendly prompts

  • 2.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26M
decreased by-1.17%
Maintainers
1
Weekly downloads
 
Created

What is prompts?

The 'prompts' npm package is a lightweight, beautiful, and user-friendly command-line prompts library. It helps developers create interactive command-line interfaces (CLIs) with ease. It supports various types of input, validation, and conditional prompts.

What are prompts's main functionalities?

Text Input

This feature allows for simple text input. The user is prompted to enter their name, and the input is then greeted.

const prompts = require('prompts');

(async () => {
  const response = await prompts({
    type: 'text',
    name: 'name',
    message: 'What is your name?'
  });

  console.log(`Hello, ${response.name}!`);
})();

Password Input

This feature is for password input where the input is masked. The user is prompted to enter a password without displaying it on the screen.

const prompts = require('prompts');

(async () => {
  const response = await prompts({
    type: 'password',
    name: 'password',
    message: 'Enter your password'
  });

  console.log(`Your password is ${response.password}`);
})();

Number Input

This feature allows for number input. The user is prompted to enter their age, and the input is then confirmed.

const prompts = require('prompts');

(async () => {
  const response = await prompts({
    type: 'number',
    name: 'age',
    message: 'How old are you?'
  });

  console.log(`You are ${response.age} years old.`);
})();

Confirmation

This feature is for yes/no confirmation prompts. The user is asked to confirm, and the response is a boolean.

const prompts = require('prompts');

(async () => {
  const response = await prompts({
    type: 'confirm',
    name: 'confirm',
    message: 'Can you confirm?'
  });

  console.log(`You ${response.confirm ? 'confirmed' : 'did not confirm'}.`);
})();

Choice Selection

This feature allows users to select from a list of choices. The user is prompted to pick a color from a list, and the selected value is then displayed.

const prompts = require('prompts');

(async () => {
  const response = await prompts({
    type: 'select',
    name: 'color',
    message: 'Pick a color',
    choices: [
      { title: 'Red', value: '#ff0000' },
      { title: 'Green', value: '#00ff00' },
      { title: 'Blue', value: '#0000ff' }
    ]
  });

  console.log(`You picked ${response.color}`);
})();

Multiple Selection

This feature allows users to select multiple items from a list. The user is prompted to select fruits, and the selected values are then displayed.

const prompts = require('prompts');

(async () => {
  const response = await prompts({
    type: 'multiselect',
    name: 'fruits',
    message: 'Select fruits',
    choices: [
      { title: 'Apple', value: 'apple' },
      { title: 'Orange', value: 'orange' },
      { title: 'Pear', value: 'pear' }
    ]
  });

  console.log(`You selected ${response.fruits.join(', ')}`);
})();

Other packages similar to prompts

Keywords

FAQs

Package last updated on 18 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc