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
Prompts for numeric and temporal input with specialized controls, validation, and formatting. Number prompts support integer and floating-point input with increment/decrement controls, while date prompts provide interactive date selection with locale support.
const prompts = require('prompts');Interactive number input prompt with support for integer and floating-point numbers, min/max validation, and arrow key increment/decrement controls.
{
/** Prompt type identifier */
type: 'number',
/** Property name for response object */
name: string,
/** Display message for user */
message: string,
/** Default number value */
initial?: number,
/** Maximum allowed value. Defaults to Infinity */
max?: number,
/** Minimum allowed value. Defaults to -Infinity */
min?: number,
/** Allow floating point inputs. Defaults to false */
float?: boolean,
/** Round float values to x decimals. Defaults to 2 */
round?: number,
/** Increment step when using arrow keys. Defaults to 1 */
increment?: number,
/** Render style controlling input display */
style?: 'default' | 'password' | 'invisible' | 'emoji',
/** Custom formatter for user input */
format?: (value: number, values: Answers) => any,
/** Input validation function */
validate?: (value: number, values: Answers) => boolean | string,
/** Render callback with kleur styling */
onRender?: (kleur: any) => void,
/** State change callback */
onState?: (state: { value: number; aborted: boolean }) => void,
/** Input stream */
stdin?: NodeJS.ReadableStream,
/** Output stream */
stdout?: NodeJS.WritableStream
}Usage Examples:
const prompts = require('prompts');
// Basic number input
const response = await prompts({
type: 'number',
name: 'age',
message: 'How old are you?',
initial: 0,
min: 0,
max: 120
});
// Floating-point number with custom increment
const response = await prompts({
type: 'number',
name: 'price',
message: 'Enter price:',
initial: 9.99,
min: 0,
float: true,
round: 2,
increment: 0.50,
format: value => `$${value.toFixed(2)}`
});
// Number with validation
const response = await prompts({
type: 'number',
name: 'port',
message: 'Enter port number:',
initial: 3000,
validate: value => {
if (value < 1024) return 'Port must be 1024 or higher';
if (value > 65535) return 'Port must be 65535 or lower';
return true;
}
});Interactive date selection prompt with keyboard navigation, locale support, and custom date formatting masks.
{
/** Prompt type identifier */
type: 'date',
/** Property name for response object */
name: string,
/** Display message for user */
message: string,
/** Default date value */
initial?: Date,
/** Custom locales for month/day names */
locales?: DateLocales,
/** Date format mask. Defaults to 'YYYY-MM-DD HH:mm:ss' */
mask?: string,
/** Input validation function */
validate?: (date: Date, values: Answers) => boolean | string,
/** Custom formatter for date value */
format?: (date: Date, values: Answers) => any,
/** Render callback with kleur styling */
onRender?: (kleur: any) => void,
/** State change callback */
onState?: (state: { value: Date; aborted: boolean }) => void,
/** Input stream */
stdin?: NodeJS.ReadableStream,
/** Output stream */
stdout?: NodeJS.WritableStream
}
interface DateLocales {
/** Full month names */
months?: string[];
/** Short month names */
monthsShort?: string[];
/** Full weekday names */
weekdays?: string[];
/** Short weekday names */
weekdaysShort?: string[];
}Usage Examples:
// Basic date input
const response = await prompts({
type: 'date',
name: 'birthday',
message: 'Enter your birthday:',
initial: new Date(1990, 0, 1)
});
// Date with validation (no future dates)
const response = await prompts({
type: 'date',
name: 'eventDate',
message: 'Enter event date:',
validate: date => {
const now = new Date();
return date > now ? 'Date cannot be in the future' : true;
}
});
// Date with custom format and locales
const response = await prompts({
type: 'date',
name: 'appointmentDate',
message: 'Select appointment date:',
mask: 'DD/MM/YYYY',
locales: {
months: [
'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'
],
weekdays: [
'Domingo', 'Lunes', 'Martes', 'Miércoles',
'Jueves', 'Viernes', 'Sábado'
]
},
format: date => date.toLocaleDateString('es-ES')
});The date prompt supports various formatting masks for display:
// Year formats
'YYYY' // 2023 (4-digit year)
'YY' // 23 (2-digit year)
// Month formats
'MM' // 01-12 (2-digit month)
'M' // 1-12 (1-digit month)
'MMMM' // January (full month name)
'MMM' // Jan (short month name)
// Day formats
'DD' // 01-31 (2-digit day)
'D' // 1-31 (1-digit day)
'dddd' // Monday (full weekday name)
'ddd' // Mon (short weekday name)
// Time formats
'HH' // 00-23 (24-hour format)
'hh' // 01-12 (12-hour format)
'mm' // 00-59 (minutes)
'ss' // 00-59 (seconds)
'SSS' // 000-999 (milliseconds)
'A' // AM/PMUsage Examples:
// Different date format examples
const formats = [
'YYYY-MM-DD', // 2023-12-25
'DD/MM/YYYY', // 25/12/2023
'MMMM D, YYYY', // December 25, 2023
'dddd, MMM D, YYYY', // Monday, Dec 25, 2023
'YYYY-MM-DD HH:mm:ss', // 2023-12-25 14:30:00
'hh:mm A' // 02:30 PM
];The default English locales provided by the date prompt:
const defaultLocales = {
months: [
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
],
monthsShort: [
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
],
weekdays: [
'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'
],
weekdaysShort: [
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
]
};increment valuefloat: truefloat settingInstall with Tessl CLI
npx tessl i tessl/npm-prompts