Lightweight, beautiful and user-friendly interactive CLI prompts library with promise-based API
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Binary choice prompts for yes/no confirmations, toggle switches, and list input. These prompts handle simple binary decisions and comma-separated list input with custom formatting options.
const prompts = require('prompts');Classic yes/no confirmation prompt. Users can press Y/N keys or use arrow keys to select Yes/No options.
{
/** Prompt type identifier */
type: 'confirm',
/** Property name for response object */
name: string,
/** Display message for user */
message: string,
/** Default boolean value. Defaults to false */
initial?: boolean,
/** Custom formatter for boolean value */
format?: (value: boolean, values: Answers) => any,
/** Render callback with kleur styling */
onRender?: (kleur: any) => void,
/** State change callback */
onState?: (state: { value: boolean; aborted: boolean }) => void,
/** Input stream */
stdin?: NodeJS.ReadableStream,
/** Output stream */
stdout?: NodeJS.WritableStream
}Usage Examples:
const prompts = require('prompts');
// Basic confirmation
const response = await prompts({
type: 'confirm',
name: 'continue',
message: 'Do you want to continue?',
initial: true
});
// Confirmation with custom formatting
const response = await prompts({
type: 'confirm',
name: 'subscribe',
message: 'Subscribe to newsletter?',
initial: false,
format: value => value ? 'Subscribed' : 'Not subscribed'
});
// Confirmation in a sequence
const questions = [
{
type: 'text',
name: 'name',
message: 'Enter your name:'
},
{
type: 'confirm',
name: 'isCorrect',
message: (prev, values) => `Is "${values.name}" correct?`,
initial: true
}
];
const response = await prompts(questions);Interactive toggle/switch prompt with custom labels for active and inactive states. Users can use arrow keys, Tab, or Space to switch between states.
{
/** Prompt type identifier */
type: 'toggle',
/** Property name for response object */
name: string,
/** Display message for user */
message: string,
/** Default boolean value. Defaults to false */
initial?: boolean,
/** Text for active/true state. Defaults to 'on' */
active?: string,
/** Text for inactive/false state. Defaults to 'off' */
inactive?: string,
/** Custom formatter for boolean value */
format?: (value: boolean, values: Answers) => any,
/** Render callback with kleur styling */
onRender?: (kleur: any) => void,
/** State change callback */
onState?: (state: { value: boolean; aborted: boolean }) => void,
/** Input stream */
stdin?: NodeJS.ReadableStream,
/** Output stream */
stdout?: NodeJS.WritableStream
}Usage Examples:
// Basic toggle prompt
const response = await prompts({
type: 'toggle',
name: 'notifications',
message: 'Enable notifications?',
initial: true,
active: 'enabled',
inactive: 'disabled'
});
// Toggle with custom labels
const response = await prompts({
type: 'toggle',
name: 'mode',
message: 'Development mode?',
initial: false,
active: 'development',
inactive: 'production'
});
// Toggle with formatting
const response = await prompts({
type: 'toggle',
name: 'privacy',
message: 'Make profile public?',
initial: false,
active: 'public',
inactive: 'private',
format: (value, values) => ({
isPublic: value,
visibility: value ? 'public' : 'private',
username: values.username
})
});Both prompts return the boolean value directly, or the result of the format function if provided.
Confirm Prompt:
? Do you want to continue? › (Y/n)
? Do you want to continue? › (y/N) // when initial: falseToggle Prompt:
? Enable notifications? › enabled / disabled
? Development mode? › development / production// Confirm with custom format
{
type: 'confirm',
name: 'terms',
message: 'Accept terms and conditions?',
format: value => ({
accepted: value,
timestamp: value ? new Date().toISOString() : null
})
}
// Toggle with status mapping
{
type: 'toggle',
name: 'feature',
message: 'Enable beta features?',
active: 'enabled',
inactive: 'disabled',
format: value => value ? 'FEATURE_ON' : 'FEATURE_OFF'
}These prompts are ideal for:
Install with Tessl CLI
npx tessl i tessl/npm-prompts