@vangware/prompts v2.2.16
āļø CLI interactive prompts. Can be used to wrap anything that matches the
interface of node:readline/promises
.
Usage
š¦ Node
Install @vangware/prompts
as a dependency:
pnpm add @vangware/prompts
# or
npm install @vangware/prompts
# or
yarn add @vangware/prompts
Import it and use it:
import { question } from "@vangware/prompts";
import { createInterface } from "node:readline/promises";
const exampleQuestion = question(
createInterface({
input: process.stdin,
output: process.stdout,
}),
);
exampleQuestion({
format: value => parseInt(value, 18),
query: "How old are you?",
validate: value => (value < 18 ? "You must be at least 18 years old." : ""),
})
.then(console.log)
.catch(console.error)
.finally(() => readlineInterface.close());
š¦ Deno
Import @vangware/prompts
using the npm:
prefix, and use it directly with the
native prompt
:
import { question } from "npm:@vangware/prompts";
const exampleQuestion = question({
question: query => Promise.resolve(prompt(query)),
});
exampleQuestion({
format: value => parseInt(value, 18),
query: "How old are you?",
validate: value => (value < 18 ? "You must be at least 18 years old." : ""),
})
.then(console.log)
.catch(console.error);
š Browser
Import @vangware/prompts
using esm.sh, and use it directly with the
native prompt
:
import { question } from "https://esm.sh/@vangware/prompts";
const exampleQuestion = question({
question: query => Promise.resolve(prompt(query)),
});
exampleQuestion({
format: value => parseInt(value, 18),
query: "How old are you?",
validate: value => (value < 18 ? "You must be at least 18 years old." : ""),
})
.then(console.log)
.catch(console.error);
Useful links
- š Documentation: TypeDoc generated documentation.
- ā³ Changelog: List of changes between versions.
- ā Tests Coverage: Coveralls page with tests coverage.
9 months ago
9 months ago
7 months ago
8 months ago
7 months ago
9 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
9 months ago
9 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
8 months ago
8 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago