1.0.29 • Published 1 year ago

@lou.codes/prompts v1.0.29

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.0.26

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.25

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago