@bemoje/prompt
v2.0.0
Published
Interactive terminal prompt utilities for Node.js with a fluent builder API.
Maintainers
Readme
@bemoje/prompt
Interactive terminal prompt utilities for Node.js with a fluent builder API.
Exports
- AbstractUserPrompt: Interactive terminal user prompts.
- AutocompleteMultiselectPrompt: Interactive multiselect user prompts in the terminal.
- AutocompletePrompt: Interactive autocomplete user prompts in the terminal.
- ConfirmPrompt: Interactive confirm user prompts in the terminal.
- DatePrompt: Interactive date user prompts in the terminal.
- InvisiblePrompt: Interactive invisible user prompts in the terminal.
- ListPrompt: Interactive list user prompts in the terminal.
- MultiselectPrompt: Interactive multiselect user prompts in the terminal.
- NumberPrompt: Interactive numner user prompts in the terminal.
- PROMPT_META_DATA: WeakMap storing search prompt meta data associated with each prompt object.
- PasswordPrompt: Interactive password user prompts in the terminal.
- SearchPrompt: Interactive autocomplete user prompts in the terminal.
- SelectPrompt: Interactive select user prompts in the terminal.
- TextPrompt: Interactive text user prompts in the terminal.
- TogglePrompt: Interactive toggle user prompts in the terminal.
- createSearchPromptObject
from npm package:prompts`. The point of this would be to run them in series. To run run a prompt directly, use - getSearchPromptMetaData: Retrieve the search prompt meta data associated with the given prompt object.
- initChoices: Initialize choices for a prompt by attaching meta data to each choice object.
- prompt: Collection of factory functions for creating interactive terminal prompts.
- regExact: Create a regular expression that matches the keyword exactly.
- regIncludes: Create a regular expression that matches strings containing the keyword.
- regStartsWith: Create a regular expression that matches strings starting with the keyword.
- searchPrompt: Start a command-line prompt in which the user can search a provided list.
- suggestDefault: Default suggest function for autocomplete prompts. Filters and highlights choices based on user input.
Installation
npm install @bemoje/promptFeatures
- Fluent builder API for all prompt types
- 13 prompt types: text, number, confirm, password, select, multiselect, and more
- Searchable list prompt with fuzzy filtering
- Autocomplete and autocomplete-multiselect variants
- Built on the
promptsnpm package
Usage
Basic Prompts
import { prompt } from '@bemoje/prompt'
// Text input
const name = await prompt.text('What is your name?').run()
// Confirm (yes/no)
const ok = await prompt.confirm('Continue?').run()
// Number input
const age = await prompt.number('Enter your age:').run()
// Password (masked input)
const pw = await prompt.password('Enter password:').run()Selection Prompts
import { prompt } from '@bemoje/prompt'
// Single select from a list
const color = await prompt
.select('Pick a color:')
.choices([
{ title: 'Red', value: 'red' },
{ title: 'Blue', value: 'blue' },
{ title: 'Green', value: 'green' },
])
.run()
// Multiple select
const colors = await prompt
.multiselect('Pick colors:')
.choices([
{ title: 'Red', value: 'red' },
{ title: 'Blue', value: 'blue' },
{ title: 'Green', value: 'green' },
])
.run()Search Prompt
import { searchPrompt } from '@bemoje/prompt'
const result = await searchPrompt(['apple', 'banana', 'cherry', 'dragonfruit'])
// User types to fuzzy-filter the list, then selects a match
// result.selected => 'cherry'
// result.input => the raw text typed
// result.matches => all matching items