@lou.codes/prompts
TypeScript icon, indicating that this package has built-in type declarations

1.0.29 • Public • Published

Coverage License NPM Version Open Issues Size

⁉️ 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

Package Sidebar

Install

npm i @lou.codes/prompts

Weekly Downloads

29

Version

1.0.29

License

MIT

Unpacked Size

10.3 kB

Total Files

11

Last publish

Collaborators

  • loucyx