Package Exports
- @topcli/prompts
- @topcli/prompts/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@topcli/prompts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
prompts
Node.js user input library for command-line interfaces.
Requirements
- Node.js v14 or higher
Getting Started
Note This package is ESM only.
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @topcli/prompts
# or
$ yarn add @topcli/prompts
Usage exemple
You can locally run node ./demo.js
import { prompt, confirm, select } from '@topcli/prompts'
const kTestRunner = ['node', 'tap', 'tape', 'vitest', 'mocha', 'ava']
const name = await prompt('Project name ?')
const runner = await select('Choose a test runner', { choices: kTestRunner, maxVisible: 5 })
const isCLI = await confirm('Your project is a CLI ?', { initial: true })
console.log(name, runner, isCLI)
API
prompt()
prompt(message: string): Promise<string>
Simple prompt, similar to rl.question()
with an improved UI.
select()
select(message: string, options: SelectOptions): Promise<string>
Scrollable select depending maxVisible
(default 8
).
Use ignoreValues
to skip result render & clear lines after a selected one.
confirm()
confirm(message: string, options?: ConfirmOptions): Promise<string>
Boolean prompt, return options.initial
if user input is different from "y"/"yes"/"n"/"no", (default false
).
Interfaces
export interface Choice {
value: any;
label: string;
description?: string;
}
export interface SelectOptions {
choices: (Choice | string)[];
maxVisible?: number = 8;
ignoreValues?: (string | number | boolean)[];
}
export interface ConfirmOptions {
initial?: boolean = false;
}