number Read user input which must be a number. Extra params like this:
filed
type
required
description
default
min
number
N
Min number.
max
number
N
Max number.
confirm Read user input and returns as boolean. Extra params like this:
filed
type
required
description
default
yes
string
N
Yes string.
no
string
N
No string.
basic usages
importPromptfrom"../mod.ts";const answers =awaitPrompt.prompts([{ type:"text", name:"name", message:"Please input your name: "},{
type:"text",
name:"sex",
message:"Please input your sex(male or female): ",validate(result:string){if(!["male","female"].includes(result)){thrownewPromptError("input must be [male] or [female]");}},},{ type:"number", name:"birthYear", min:1900},{ type:"number", name:"age", min:1, max:100},{ type:"confirm", name:"agree", defaultValue:true},]);console.log(answers);
custom usages
It supported to define custom component. Here is am example.
Define component which must has static function called run and accept args which extends PromptParams.
importPromptfrom"../mod.ts";classCustomComponent{staticasyncrun<TextendsPromptParams>(args:T){// Your define code to do something.}}Prompt.registerComponent("custom",CustomComponent);
Usage.(You must put bellow code after define component)
importPromptfrom"../mod.ts";const answers =awaitPrompt.prompts([{ type:"custom", name:"name", message:"Please input your name: "},]);console.log(answers);