speedy-prompt
v1.1.0
Published
A fast and efficient prompt library for Node.js
Downloads
22
Readme
Speedy Prompt
A fast and efficient prompt library for Node.js with type-safe input handling and interactive selection menus.
Features
- Type-safe prompts - String, number, boolean, and custom types with full TypeScript support
- Interactive selection - Navigate through choices with keyboard controls
- Input validation - Built-in validation with custom validators
- Password masking - Hide sensitive input with custom mask characters
- Flexible layouts - Horizontal or vertical selection menu layouts
- Lightweight - Zero dependencies, minimal footprint
Installation
# npm
npm install speedy-prompt
# yarn
yarn add speedy-prompt
# pnpm
pnpm install speedy-prompt
# bun
bun install speedy-promptUsage
Basic Text Input
import { prompt } from "speedy-prompt";
const name = await prompt("Enter your name: ", {
type: "string",
required: true,
});
console.log("Hello,", name);Number Input
const age = await prompt("Enter your age: ", {
type: "number",
required: true,
validate: (value) => value < 0 ? "Age must be positive" : null,
});Boolean Input
const isAdmin = await prompt("Are you admin? ", {
type: "boolean",
required: true,
});Password Input
const password = await prompt("Enter password: ", {
type: "string",
mask: "*",
required: true,
});Selection Menu (Horizontal)
import { promptSelect } from "speedy-prompt";
const color = await promptSelect("Choose a color:", [
"Red",
"Green",
"Blue",
]);Selection Menu (Vertical)
const country = await promptSelect("Where are you from?", [
"Brazil",
"Portugal",
"USA",
"Germany",
"France",
], {
vertical: true,
});Complete Example
import { prompt, promptSelect } from "speedy-prompt";
(async () => {
const name = await prompt("Enter your name: ", {
type: "string",
required: true,
});
const age = await prompt("Enter your age: ", {
type: "number",
required: true,
});
const isAdmin = await prompt("Are you admin? ", {
type: "boolean",
required: true,
});
const color = await promptSelect("Choose a color:", [
"Red",
"Green",
"Blue",
], {
vertical: true,
});
console.log({ name, age, isAdmin, color });
})();API
prompt(label, options?)
Creates a text-based input prompt.
Parameters:
label(string) - The prompt label/questionoptions(PromptOptions) - Optional configuration:type- Input type:"string"|"number"|"boolean"|"any"(default:"any")required- Whether input is required (default:false)mask- Character to mask input (e.g.,"*"for passwords)defaultValue- Default value if user presses Entervalidate- Custom validation function returning error message or null
Returns: Promise<T> - The parsed input value
promptSelect(label, choices, options?)
Creates an interactive selection menu.
Parameters:
label(string) - The menu label/questionchoices(T[]) - Array of selectable optionsoptions(SelectOptions) - Optional configuration:vertical- Display choices vertically (default:false)highlightColor- ANSI color code for highlighting (default: cyan)
Returns: Promise<T> - The selected choice
Keyboard Controls
Text Input
- Enter - Submit input
- Backspace - Delete character
- Ctrl+C - Exit
Boolean Input
- Left Arrow - Select "Yes"
- Right Arrow - Select "No"
- Enter - Submit
- Ctrl+C - Exit
Selection Menu (Horizontal)
- Left/Right Arrow - Navigate choices
- Enter - Select
- Ctrl+C - Exit
Selection Menu (Vertical)
- Up/Down Arrow - Navigate choices
- Enter - Select
- Ctrl+C - Exit
License
Speedy Prompt is licensed under the MIT License.
Contributing
We welcome contributions from the community! If you'd like to contribute, please follow these steps:
- Star the repository
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and commit them
- Push your changes to your fork
- Submit a pull request
Support
If you need help or have any questions, please feel free to open an issue on GitHub Issues.
