Prompts Reference
⁉️ CLI interactive prompts. Can be used to wrap anything that matches the
interface of node:readline/promises
.
Usage
📦 Node
Install @lou.codes/prompts
as a dependency:
Import it and use it:
🦕 Deno
Import @lou.codes/prompts
using the npm:
prefix, and use it directly with
the native prompt
:
🌎 Browser
Import @lou.codes/prompts
using esm.sh, and use it directly with the
native prompt
:
Useful links
- 📝 Documentation: TypeDoc generated documentation.
- ⏳ Changelog: List of changes between versions.
- ✅ Tests Coverage: Coveralls page with tests coverage.
Type Aliases
QuestionObject
Question object.
Remarks
Small abstraction layer on top the question
method of Node’s readline
module.
Type declaration
Member | Type | Description |
---|---|---|
question | (query : string ) => Awaitable <string > | Question function. |
QuestionOptions<FormattedValue>
Options object for the question
function.
Type parameters
Type parameter | Value |
---|---|
FormattedValue | string |
Type declaration
Member | Type | Description |
---|---|---|
format | Unary <string , FormattedValue > | Function to format the question’s answer given by the user. Example typescript{ format: value => parseInt(value, 18),} Param The question’s answer given by the user. |
query | string | Query to show to the user. |
retry | boolean | Whether to retry the question if the answer is invalid. |
validate | Unary <FormattedValue , Maybe <string >> | Function to validate the question’s answer given by the user (after formatting). Returning an string will be used to reject with an error, while an empty string or undefined is considered valid. Example typescript{ validate: value => value % 2 === 0,} Param The question’s answer given by the user. |
Functions
question()
Interactive question.
Parameters
Parameter | Type | Description |
---|---|---|
questionObject | QuestionObject | Object with a question function that returns a promise. |
Returns
Function
Curried function with questionObject
set in context.
Interactive question with questionObject
set in context.
Type parameters
Type parameter | Value | Description |
---|---|---|
FormattedValue | string | Result of the value after formatting. |
Parameters
Parameter | Type | Description |
---|---|---|
options | QuestionOptions <FormattedValue > | Options object for the question. |
Returns
Promise
<FormattedValue
>
Promise with the question’s answer.
See
Remarks
Small abstraction layer on top the question
method of Node’s readline
module.