1.0.23 ā¢ Published 11 days ago
@lou.codes/prompts v1.0.23
āļø 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:
pnpm add @lou.codes/prompts
# or
npm install @lou.codes/prompts
# or
yarn add @lou.codes/prompts
Import it and use it:
import { question } from "@lou.codes/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 @lou.codes/prompts
using the npm:
prefix, and use it directly with
the native prompt
:
import { question } from "npm:@lou.codes/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 @lou.codes/prompts
using esm.sh, and use it directly with the
native prompt
:
import { question } from "https://esm.sh/@lou.codes/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.
1.0.23
11 days ago
1.0.22
24 days ago
1.0.21
26 days ago
1.0.20
1 month ago
1.0.18
1 month ago
1.0.17
1 month ago
1.0.16
1 month ago
1.0.15
1 month ago
1.0.14
2 months ago
1.0.13
2 months ago
1.0.12
3 months ago
1.0.11
4 months ago
1.0.10
4 months ago
1.0.9
4 months ago
1.0.8
4 months ago
1.0.7
5 months ago
1.0.6
5 months ago
1.0.2
5 months ago
1.0.5
5 months ago
1.0.4
5 months ago
1.0.3
5 months ago
1.0.1
6 months ago
1.0.0
6 months ago