@topcli/prompts 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,13 +1,13 @@
1
- Copyright 2023-2025 TopCli
2
-
3
- Permission to use, copy, modify, and/or distribute this software for any purpose
4
- with or without fee is hereby granted, provided that the above copyright notice
5
- and this permission notice appear in all copies.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
- FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
- THIS SOFTWARE.
1
+ Copyright 2023-2025 TopCli
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
package/README.md CHANGED
@@ -1,274 +1,274 @@
1
- <div align="center">
2
- <img src="./public/banner.png" alt="@topcli/prompts">
3
-
4
- ![version](https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/TopCli/prompts/main/package.json&query=$.version&label=Version)
5
- [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=for-the-badge)](https://github.com/TopCli/prompts/commit-activity)
6
- [![isc](https://img.shields.io/badge/License-ISC-blue.svg?style=for-the-badge)](https://github.com/TopCli/prompts/blob/main/LICENSE)
7
- [![scorecard](https://api.securityscorecards.dev/projects/github.com/TopCli/prompts/badge?style=for-the-badge)](https://ossf.github.io/scorecard-visualizer/#/projects/github.com/TopCli/prompts)
8
- ![build](https://img.shields.io/github/actions/workflow/status/TopCli/prompts/node.js.yml?style=for-the-badge)
9
-
10
- <img src="./public/topcli.gif" alt="demo">
11
- </div>
12
-
13
- ## Requirements
14
- - [Node.js](https://nodejs.org/en/) v20 or higher
15
-
16
- ## Getting Started
17
-
18
- This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
19
-
20
- ```bash
21
- $ npm i @topcli/prompts
22
- # or
23
- $ yarn add @topcli/prompts
24
- ```
25
-
26
- ## Usage exemple
27
-
28
- You can locally run `node ./demo.js`
29
-
30
- ```js
31
- import { question, confirm, select, multiselect } from "@topcli/prompts";
32
-
33
- const kTestRunner = ["node", "tap", "tape", "vitest", "mocha", "ava"];
34
-
35
- const name = await question("Project name ?", { defaultValue: "foo" });
36
- const runner = await select("Choose a test runner", { choices: kTestRunner, maxVisible: 5 });
37
- const isCLI = await confirm("Your project is a CLI ?", { initial: true });
38
- const os = await multiselect("Choose OS", {
39
- choices: ["linux", "mac", "windows"],
40
- preSelectedChoices: ["linux"]
41
- });
42
-
43
- console.log(name, runner, isCLI, os);
44
- ```
45
-
46
- ## API
47
-
48
- ### `question()`
49
-
50
- ```ts
51
- question(message: string, options?: PromptOptions): Promise<string>
52
- ```
53
-
54
- Simple prompt, similar to `rl.question()` with an improved UI.
55
-
56
- Use `options.defaultValue` to set a default value.
57
-
58
- Use `options.secure` if you need to hide both input and answer.
59
-
60
- Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
61
-
62
- Use `options.validators` to handle user input.
63
-
64
- Use `options.skip` to skip prompt. It will return `options.defaultValue` if given, `""` otherwise.
65
-
66
- **Example**
67
-
68
- ```js
69
- const packageName = await question('Package name', {
70
- validators: [
71
- {
72
- validate: (value) => {
73
- if (!existsSync(join(process.cwd(), value))) {
74
- return `Folder ${value} already exists`
75
- }
76
- }
77
- }
78
- ]
79
- });
80
- ```
81
-
82
- **This package provide some validators for common usage**
83
-
84
- - required
85
-
86
- ```js
87
- import { prompt, required } from "@topcli/prompts";
88
-
89
- const name = await prompt("What's your name ?", {
90
- validators: [required()]
91
- });
92
- ```
93
-
94
- ### `select()`
95
-
96
- ```ts
97
- select(message: string, options: SelectOptions): Promise<string>
98
- ```
99
-
100
- Scrollable select depending `maxVisible` (default `8`).
101
-
102
- Use `options.ignoreValues` to skip result render & clear lines after a selected one.
103
-
104
- Use `options.validators` to handle user input.
105
-
106
- Use `options.autocomplete` to allow filtered choices. This can be useful for a large list of choices.
107
-
108
- Use `options.caseSensitive` to make autocomplete filters case sensitive. Default `false`
109
-
110
- Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
111
-
112
- Use `options.skip` to skip prompt. It will return the first choice.
113
-
114
- ### `multiselect()`
115
-
116
- ```ts
117
- multiselect(message: string, options: MultiselectOptions): Promise<[string]>
118
- ```
119
-
120
- Scrollable multiselect depending `options.maxVisible` (default `8`).<br>
121
- Use `options.preSelectedChoices` to pre-select choices.
122
-
123
- Use `options.validators` to handle user input.
124
-
125
- Use `options.showHint: false` to disable hint (this option is truthy by default).
126
-
127
- Use `options.autocomplete` to allow filtered choices. This can be useful for a large list of choices.
128
-
129
- Use `options.caseSensitive` to make autocomplete filters case sensitive. Default `false`.
130
-
131
- Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
132
-
133
- Use `options.skip` to skip prompt. It will return `options.preSelectedChoices` if given, `[]` otherwise.
134
-
135
- ### `confirm()`
136
-
137
- ```ts
138
- confirm(message: string, options?: ConfirmOptions): Promise<boolean>
139
- ```
140
-
141
- Boolean prompt, default to `options.initial` (`false`).
142
-
143
- > [!TIP]
144
- > You can answer pressing <kbd>Y</kbd> or <kbd>N</kbd>
145
-
146
- Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
147
-
148
- Use `options.skip` to skip prompt. It will return `options.initial` (`false` by default)
149
-
150
- ### `PromptAgent`
151
-
152
- The `PromptAgent` class allows to programmatically set the next answers for any prompt function, this can be useful for testing.
153
-
154
- ```ts
155
- const agent = PromptAgent.agent();
156
- agent.nextAnswer("John");
157
-
158
- const input = await question("What's your name?");
159
- assert.equal(input, "John");
160
- ```
161
-
162
- > [!WARNING]
163
- > Answers set with `PromptAgent` will **bypass** any logical & validation rules.
164
- > Examples:
165
- > - When using `question()`, `validators` functions will not be executed.
166
- > - When using `select()`, the answer can be different from the available choices.
167
- > - When using `confirm()`, the answer can be any type other than boolean.
168
- > - etc<br>
169
- > **Use with caution**
170
-
171
- ## Errors
172
-
173
- ### `AbortError`
174
-
175
- ```ts
176
- export class AbortError extends Error {
177
- constructor(message: string) {
178
- super(message);
179
- this.name = "AbortError";
180
- }
181
- }
182
- ```
183
-
184
- ## Interfaces
185
-
186
- ```ts
187
- type Stdin = NodeJS.ReadStream & {
188
- fd: 0;
189
- };
190
-
191
- type Stdout = NodeJS.WriteStream & {
192
- fd: 1;
193
- }
194
-
195
- export interface AbstractPromptOptions {
196
- stdin?: Stdin;
197
- stdout?: Stdout;
198
- message: string;
199
- sginal?: AbortSignal;
200
- }
201
-
202
- export interface PromptValidator<T = string | string[] | boolean> {
203
- validate: (input: T) => boolean;
204
- error: (input: T) => string;
205
- }
206
-
207
- export interface QuestionOptions extends SharedOptions {
208
- defaultValue?: string;
209
- validators?: Validator[];
210
- secure?: boolean;
211
- }
212
-
213
- export interface Choice {
214
- value: any;
215
- label: string;
216
- description?: string;
217
- }
218
-
219
- export interface SelectOptions extends SharedOptions {
220
- choices: (Choice | string)[];
221
- maxVisible?: number;
222
- ignoreValues?: (string | number | boolean)[];
223
- validators?: Validator[];
224
- autocomplete?: boolean;
225
- caseSensitive?: boolean;
226
- }
227
-
228
- export interface MultiselectOptions extends SharedOptions {
229
- choices: (Choice | string)[];
230
- maxVisible?: number;
231
- preSelectedChoices?: (Choice | string)[];
232
- validators?: Validator[];
233
- autocomplete?: boolean;
234
- caseSensitive?: boolean;
235
- showHint?: boolean;
236
- }
237
-
238
- export interface ConfirmOptions extends SharedOptions {
239
- initial?: boolean;
240
- }
241
- ```
242
-
243
- ## Contributing
244
-
245
- Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
246
-
247
- Open an issue if you want to provide feedback such as bug reports or enchancements.
248
-
249
- ## Contributors
250
-
251
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
252
- <!-- prettier-ignore-start -->
253
- <!-- markdownlint-disable -->
254
- <table>
255
- <tbody>
256
- <tr>
257
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/PierreDemailly"><img src="https://avatars.githubusercontent.com/u/39910767?v=4?s=100" width="100px;" alt="PierreDemailly"/><br /><sub><b>PierreDemailly</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=PierreDemailly" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=PierreDemailly" title="Tests">⚠️</a></td>
258
- <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Gentilhomme"/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/TopCli/prompts/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/TopCli/prompts/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=fraxken" title="Documentation">📖</a></td>
259
- <td align="center" valign="top" width="14.28%"><a href="http://tonygo.dev"><img src="https://avatars0.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt="Tony Gorez"/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/TopCli/prompts/pulls?q=is%3Apr+reviewed-by%3Atony-go" title="Reviewed Pull Requests">👀</a></td>
260
- <td align="center" valign="top" width="14.28%"><a href="http://sofiand.github.io/portfolio-client/"><img src="https://avatars.githubusercontent.com/u/39944043?v=4?s=100" width="100px;" alt="Yefis"/><br /><sub><b>Yefis</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=SofianD" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=SofianD" title="Documentation">📖</a></td>
261
- <td align="center" valign="top" width="14.28%"><a href="http://justie.dev"><img src="https://avatars.githubusercontent.com/u/7118300?v=4?s=100" width="100px;" alt="Ben"/><br /><sub><b>Ben</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=JUSTIVE" title="Documentation">📖</a> <a href="#maintenance-JUSTIVE" title="Maintenance">🚧</a></td>
262
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/ncukondo"><img src="https://avatars.githubusercontent.com/u/17022138?v=4?s=100" width="100px;" alt="Takeshi Kondo"/><br /><sub><b>Takeshi Kondo</b></sub></a><br /><a href="#maintenance-ncukondo" title="Maintenance">🚧</a></td>
263
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/FredGuiou"><img src="https://avatars.githubusercontent.com/u/99122562?v=4?s=100" width="100px;" alt="FredGuiou"/><br /><sub><b>FredGuiou</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Tests">⚠️</a> <a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Documentation">📖</a></td>
264
- </tr>
265
- <tr>
266
- <td align="center" valign="top" width="14.28%"><a href="https://github.com/noxify"><img src="https://avatars.githubusercontent.com/u/521777?v=4?s=100" width="100px;" alt="Marcus Reinhardt"/><br /><sub><b>Marcus Reinhardt</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Tests">⚠️</a> <a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Documentation">📖</a></td>
267
- </tr>
268
- </tbody>
269
- </table>
270
-
271
- <!-- markdownlint-restore -->
272
- <!-- prettier-ignore-end -->
273
-
274
- <!-- ALL-CONTRIBUTORS-LIST:END -->
1
+ <div align="center">
2
+ <img src="./public/banner.png" alt="@topcli/prompts">
3
+
4
+ ![version](https://img.shields.io/badge/dynamic/json.svg?style=for-the-badge&url=https://raw.githubusercontent.com/TopCli/prompts/main/package.json&query=$.version&label=Version)
5
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=for-the-badge)](https://github.com/TopCli/prompts/commit-activity)
6
+ [![isc](https://img.shields.io/badge/License-ISC-blue.svg?style=for-the-badge)](https://github.com/TopCli/prompts/blob/main/LICENSE)
7
+ [![scorecard](https://api.securityscorecards.dev/projects/github.com/TopCli/prompts/badge?style=for-the-badge)](https://ossf.github.io/scorecard-visualizer/#/projects/github.com/TopCli/prompts)
8
+ ![build](https://img.shields.io/github/actions/workflow/status/TopCli/prompts/node.js.yml?style=for-the-badge)
9
+
10
+ <img src="./public/topcli.gif" alt="demo">
11
+ </div>
12
+
13
+ ## Requirements
14
+ - [Node.js](https://nodejs.org/en/) v20 or higher
15
+
16
+ ## Getting Started
17
+
18
+ This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
19
+
20
+ ```bash
21
+ $ npm i @topcli/prompts
22
+ # or
23
+ $ yarn add @topcli/prompts
24
+ ```
25
+
26
+ ## Usage exemple
27
+
28
+ You can locally run `node ./demo.js`
29
+
30
+ ```js
31
+ import { question, confirm, select, multiselect } from "@topcli/prompts";
32
+
33
+ const kTestRunner = ["node", "tap", "tape", "vitest", "mocha", "ava"];
34
+
35
+ const name = await question("Project name ?", { defaultValue: "foo" });
36
+ const runner = await select("Choose a test runner", { choices: kTestRunner, maxVisible: 5 });
37
+ const isCLI = await confirm("Your project is a CLI ?", { initial: true });
38
+ const os = await multiselect("Choose OS", {
39
+ choices: ["linux", "mac", "windows"],
40
+ preSelectedChoices: ["linux"]
41
+ });
42
+
43
+ console.log(name, runner, isCLI, os);
44
+ ```
45
+
46
+ ## API
47
+
48
+ ### `question()`
49
+
50
+ ```ts
51
+ question(message: string, options?: PromptOptions): Promise<string>
52
+ ```
53
+
54
+ Simple prompt, similar to `rl.question()` with an improved UI.
55
+
56
+ Use `options.defaultValue` to set a default value.
57
+
58
+ Use `options.secure` if you need to hide both input and answer.
59
+
60
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
61
+
62
+ Use `options.validators` to handle user input.
63
+
64
+ Use `options.skip` to skip prompt. It will return `options.defaultValue` if given, `""` otherwise.
65
+
66
+ **Example**
67
+
68
+ ```js
69
+ const packageName = await question('Package name', {
70
+ validators: [
71
+ {
72
+ validate: (value) => {
73
+ if (!existsSync(join(process.cwd(), value))) {
74
+ return `Folder ${value} already exists`
75
+ }
76
+ }
77
+ }
78
+ ]
79
+ });
80
+ ```
81
+
82
+ **This package provide some validators for common usage**
83
+
84
+ - required
85
+
86
+ ```js
87
+ import { prompt, required } from "@topcli/prompts";
88
+
89
+ const name = await prompt("What's your name ?", {
90
+ validators: [required()]
91
+ });
92
+ ```
93
+
94
+ ### `select()`
95
+
96
+ ```ts
97
+ select(message: string, options: SelectOptions): Promise<string>
98
+ ```
99
+
100
+ Scrollable select depending `maxVisible` (default `8`).
101
+
102
+ Use `options.ignoreValues` to skip result render & clear lines after a selected one.
103
+
104
+ Use `options.validators` to handle user input.
105
+
106
+ Use `options.autocomplete` to allow filtered choices. This can be useful for a large list of choices.
107
+
108
+ Use `options.caseSensitive` to make autocomplete filters case sensitive. Default `false`
109
+
110
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
111
+
112
+ Use `options.skip` to skip prompt. It will return the first choice.
113
+
114
+ ### `multiselect()`
115
+
116
+ ```ts
117
+ multiselect(message: string, options: MultiselectOptions): Promise<[string]>
118
+ ```
119
+
120
+ Scrollable multiselect depending `options.maxVisible` (default `8`).<br>
121
+ Use `options.preSelectedChoices` to pre-select choices.
122
+
123
+ Use `options.validators` to handle user input.
124
+
125
+ Use `options.showHint: false` to disable hint (this option is truthy by default).
126
+
127
+ Use `options.autocomplete` to allow filtered choices. This can be useful for a large list of choices.
128
+
129
+ Use `options.caseSensitive` to make autocomplete filters case sensitive. Default `false`.
130
+
131
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
132
+
133
+ Use `options.skip` to skip prompt. It will return `options.preSelectedChoices` if given, `[]` otherwise.
134
+
135
+ ### `confirm()`
136
+
137
+ ```ts
138
+ confirm(message: string, options?: ConfirmOptions): Promise<boolean>
139
+ ```
140
+
141
+ Boolean prompt, default to `options.initial` (`false`).
142
+
143
+ > [!TIP]
144
+ > You can answer pressing <kbd>Y</kbd> or <kbd>N</kbd>
145
+
146
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
147
+
148
+ Use `options.skip` to skip prompt. It will return `options.initial` (`false` by default)
149
+
150
+ ### `PromptAgent`
151
+
152
+ The `PromptAgent` class allows to programmatically set the next answers for any prompt function, this can be useful for testing.
153
+
154
+ ```ts
155
+ const agent = PromptAgent.agent();
156
+ agent.nextAnswer("John");
157
+
158
+ const input = await question("What's your name?");
159
+ assert.equal(input, "John");
160
+ ```
161
+
162
+ > [!WARNING]
163
+ > Answers set with `PromptAgent` will **bypass** any logical & validation rules.
164
+ > Examples:
165
+ > - When using `question()`, `validators` functions will not be executed.
166
+ > - When using `select()`, the answer can be different from the available choices.
167
+ > - When using `confirm()`, the answer can be any type other than boolean.
168
+ > - etc<br>
169
+ > **Use with caution**
170
+
171
+ ## Errors
172
+
173
+ ### `AbortError`
174
+
175
+ ```ts
176
+ export class AbortError extends Error {
177
+ constructor(message: string) {
178
+ super(message);
179
+ this.name = "AbortError";
180
+ }
181
+ }
182
+ ```
183
+
184
+ ## Interfaces
185
+
186
+ ```ts
187
+ type Stdin = NodeJS.ReadStream & {
188
+ fd: 0;
189
+ };
190
+
191
+ type Stdout = NodeJS.WriteStream & {
192
+ fd: 1;
193
+ }
194
+
195
+ export interface AbstractPromptOptions {
196
+ stdin?: Stdin;
197
+ stdout?: Stdout;
198
+ message: string;
199
+ sginal?: AbortSignal;
200
+ }
201
+
202
+ export interface PromptValidator<T = string | string[] | boolean> {
203
+ validate: (input: T) => boolean;
204
+ error: (input: T) => string;
205
+ }
206
+
207
+ export interface QuestionOptions extends SharedOptions {
208
+ defaultValue?: string;
209
+ validators?: Validator[];
210
+ secure?: boolean;
211
+ }
212
+
213
+ export interface Choice {
214
+ value: any;
215
+ label: string;
216
+ description?: string;
217
+ }
218
+
219
+ export interface SelectOptions extends SharedOptions {
220
+ choices: (Choice | string)[];
221
+ maxVisible?: number;
222
+ ignoreValues?: (string | number | boolean)[];
223
+ validators?: Validator[];
224
+ autocomplete?: boolean;
225
+ caseSensitive?: boolean;
226
+ }
227
+
228
+ export interface MultiselectOptions extends SharedOptions {
229
+ choices: (Choice | string)[];
230
+ maxVisible?: number;
231
+ preSelectedChoices?: (Choice | string)[];
232
+ validators?: Validator[];
233
+ autocomplete?: boolean;
234
+ caseSensitive?: boolean;
235
+ showHint?: boolean;
236
+ }
237
+
238
+ export interface ConfirmOptions extends SharedOptions {
239
+ initial?: boolean;
240
+ }
241
+ ```
242
+
243
+ ## Contributing
244
+
245
+ Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
246
+
247
+ Open an issue if you want to provide feedback such as bug reports or enchancements.
248
+
249
+ ## Contributors
250
+
251
+ <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
252
+ <!-- prettier-ignore-start -->
253
+ <!-- markdownlint-disable -->
254
+ <table>
255
+ <tbody>
256
+ <tr>
257
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/PierreDemailly"><img src="https://avatars.githubusercontent.com/u/39910767?v=4?s=100" width="100px;" alt="PierreDemailly"/><br /><sub><b>PierreDemailly</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=PierreDemailly" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=PierreDemailly" title="Tests">⚠️</a></td>
258
+ <td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/thomas-gentilhomme/"><img src="https://avatars.githubusercontent.com/u/4438263?v=4?s=100" width="100px;" alt="Gentilhomme"/><br /><sub><b>Gentilhomme</b></sub></a><br /><a href="https://github.com/TopCli/prompts/pulls?q=is%3Apr+reviewed-by%3Afraxken" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/TopCli/prompts/commits?author=fraxken" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=fraxken" title="Documentation">📖</a></td>
259
+ <td align="center" valign="top" width="14.28%"><a href="http://tonygo.dev"><img src="https://avatars0.githubusercontent.com/u/22824417?v=4?s=100" width="100px;" alt="Tony Gorez"/><br /><sub><b>Tony Gorez</b></sub></a><br /><a href="https://github.com/TopCli/prompts/pulls?q=is%3Apr+reviewed-by%3Atony-go" title="Reviewed Pull Requests">👀</a></td>
260
+ <td align="center" valign="top" width="14.28%"><a href="http://sofiand.github.io/portfolio-client/"><img src="https://avatars.githubusercontent.com/u/39944043?v=4?s=100" width="100px;" alt="Yefis"/><br /><sub><b>Yefis</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=SofianD" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=SofianD" title="Documentation">📖</a></td>
261
+ <td align="center" valign="top" width="14.28%"><a href="http://justie.dev"><img src="https://avatars.githubusercontent.com/u/7118300?v=4?s=100" width="100px;" alt="Ben"/><br /><sub><b>Ben</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=JUSTIVE" title="Documentation">📖</a> <a href="#maintenance-JUSTIVE" title="Maintenance">🚧</a></td>
262
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/ncukondo"><img src="https://avatars.githubusercontent.com/u/17022138?v=4?s=100" width="100px;" alt="Takeshi Kondo"/><br /><sub><b>Takeshi Kondo</b></sub></a><br /><a href="#maintenance-ncukondo" title="Maintenance">🚧</a></td>
263
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/FredGuiou"><img src="https://avatars.githubusercontent.com/u/99122562?v=4?s=100" width="100px;" alt="FredGuiou"/><br /><sub><b>FredGuiou</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Tests">⚠️</a> <a href="https://github.com/TopCli/prompts/commits?author=FredGuiou" title="Documentation">📖</a></td>
264
+ </tr>
265
+ <tr>
266
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/noxify"><img src="https://avatars.githubusercontent.com/u/521777?v=4?s=100" width="100px;" alt="Marcus Reinhardt"/><br /><sub><b>Marcus Reinhardt</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Code">💻</a> <a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Tests">⚠️</a> <a href="https://github.com/TopCli/prompts/commits?author=noxify" title="Documentation">📖</a></td>
267
+ </tr>
268
+ </tbody>
269
+ </table>
270
+
271
+ <!-- markdownlint-restore -->
272
+ <!-- prettier-ignore-end -->
273
+
274
+ <!-- ALL-CONTRIBUTORS-LIST:END -->
package/dist/index.cjs CHANGED
@@ -46,7 +46,7 @@ var import_wcwidth = __toESM(require("@topcli/wcwidth"), 1);
46
46
 
47
47
  // src/prompts/abstract.ts
48
48
  var import_node_os = require("os");
49
- var import_node_readline = require("readline");
49
+ var import_node_readline = __toESM(require("readline"), 1);
50
50
  var import_node_stream = require("stream");
51
51
  var import_node_events = __toESM(require("events"), 1);
52
52
 
@@ -166,7 +166,7 @@ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
166
166
  if (this.stdout.isTTY) {
167
167
  this.stdin.setRawMode(true);
168
168
  }
169
- this.rl = (0, import_node_readline.createInterface)({
169
+ this.rl = import_node_readline.default.createInterface({
170
170
  input,
171
171
  output: new import_node_stream.Writable({
172
172
  write: (chunk, encoding, callback) => {
@@ -1028,18 +1028,18 @@ var MultiselectPrompt = class extends AbstractPrompt {
1028
1028
  };
1029
1029
 
1030
1030
  // index.ts
1031
- async function question(message, options = {}) {
1031
+ function question(message, options = {}) {
1032
1032
  return new QuestionPrompt({ ...options, message }).question();
1033
1033
  }
1034
- async function select(message, options) {
1034
+ function select(message, options) {
1035
1035
  const selectPrompt = new SelectPrompt({ ...options, message });
1036
1036
  return selectPrompt.select();
1037
1037
  }
1038
- async function confirm(message, options = {}) {
1038
+ function confirm(message, options = {}) {
1039
1039
  const confirmPrompt = new ConfirmPrompt({ ...options, message });
1040
1040
  return confirmPrompt.confirm();
1041
1041
  }
1042
- async function multiselect(message, options) {
1042
+ function multiselect(message, options) {
1043
1043
  const multiselectPrompt = new MultiselectPrompt({ ...options, message });
1044
1044
  return multiselectPrompt.multiselect();
1045
1045
  }
package/dist/index.d.cts CHANGED
@@ -69,8 +69,8 @@ interface ConfirmOptions extends AbstractPromptOptions {
69
69
  initial?: boolean;
70
70
  }
71
71
 
72
- interface MultiselectOptions extends AbstractPromptOptions {
73
- choices: (Choice | string)[];
72
+ interface MultiselectOptions<T extends string = string> extends AbstractPromptOptions {
73
+ choices: (Choice | T)[];
74
74
  maxVisible?: number;
75
75
  preSelectedChoices?: (Choice | string)[];
76
76
  validators?: PromptValidator[];
@@ -79,8 +79,8 @@ interface MultiselectOptions extends AbstractPromptOptions {
79
79
  showHint?: boolean;
80
80
  }
81
81
 
82
- interface SelectOptions extends AbstractPromptOptions {
83
- choices: (Choice | string)[];
82
+ interface SelectOptions<T extends string = string> extends AbstractPromptOptions {
83
+ choices: (Choice | T)[];
84
84
  maxVisible?: number;
85
85
  ignoreValues?: (string | number | boolean)[];
86
86
  validators?: PromptValidator[];
@@ -89,8 +89,8 @@ interface SelectOptions extends AbstractPromptOptions {
89
89
  }
90
90
 
91
91
  declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
92
- declare function select(message: string, options: Omit<SelectOptions, "message">): Promise<string>;
92
+ declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
93
93
  declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
94
- declare function multiselect(message: string, options: Omit<MultiselectOptions, "message">): Promise<string[]>;
94
+ declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
95
95
 
96
96
  export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
package/dist/index.d.ts CHANGED
@@ -69,8 +69,8 @@ interface ConfirmOptions extends AbstractPromptOptions {
69
69
  initial?: boolean;
70
70
  }
71
71
 
72
- interface MultiselectOptions extends AbstractPromptOptions {
73
- choices: (Choice | string)[];
72
+ interface MultiselectOptions<T extends string = string> extends AbstractPromptOptions {
73
+ choices: (Choice | T)[];
74
74
  maxVisible?: number;
75
75
  preSelectedChoices?: (Choice | string)[];
76
76
  validators?: PromptValidator[];
@@ -79,8 +79,8 @@ interface MultiselectOptions extends AbstractPromptOptions {
79
79
  showHint?: boolean;
80
80
  }
81
81
 
82
- interface SelectOptions extends AbstractPromptOptions {
83
- choices: (Choice | string)[];
82
+ interface SelectOptions<T extends string = string> extends AbstractPromptOptions {
83
+ choices: (Choice | T)[];
84
84
  maxVisible?: number;
85
85
  ignoreValues?: (string | number | boolean)[];
86
86
  validators?: PromptValidator[];
@@ -89,8 +89,8 @@ interface SelectOptions extends AbstractPromptOptions {
89
89
  }
90
90
 
91
91
  declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
92
- declare function select(message: string, options: Omit<SelectOptions, "message">): Promise<string>;
92
+ declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
93
93
  declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
94
- declare function multiselect(message: string, options: Omit<MultiselectOptions, "message">): Promise<string[]>;
94
+ declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
95
95
 
96
96
  export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import wcwidth from "@topcli/wcwidth";
5
5
 
6
6
  // src/prompts/abstract.ts
7
7
  import { EOL } from "node:os";
8
- import { createInterface } from "node:readline";
8
+ import readline from "node:readline";
9
9
  import { Writable } from "node:stream";
10
10
  import EventEmitter from "node:events";
11
11
 
@@ -125,7 +125,7 @@ var AbstractPrompt = class _AbstractPrompt extends EventEmitter {
125
125
  if (this.stdout.isTTY) {
126
126
  this.stdin.setRawMode(true);
127
127
  }
128
- this.rl = createInterface({
128
+ this.rl = readline.createInterface({
129
129
  input,
130
130
  output: new Writable({
131
131
  write: (chunk, encoding, callback) => {
@@ -987,18 +987,18 @@ var MultiselectPrompt = class extends AbstractPrompt {
987
987
  };
988
988
 
989
989
  // index.ts
990
- async function question(message, options = {}) {
990
+ function question(message, options = {}) {
991
991
  return new QuestionPrompt({ ...options, message }).question();
992
992
  }
993
- async function select(message, options) {
993
+ function select(message, options) {
994
994
  const selectPrompt = new SelectPrompt({ ...options, message });
995
995
  return selectPrompt.select();
996
996
  }
997
- async function confirm(message, options = {}) {
997
+ function confirm(message, options = {}) {
998
998
  const confirmPrompt = new ConfirmPrompt({ ...options, message });
999
999
  return confirmPrompt.confirm();
1000
1000
  }
1001
- async function multiselect(message, options) {
1001
+ function multiselect(message, options) {
1002
1002
  const multiselectPrompt = new MultiselectPrompt({ ...options, message });
1003
1003
  return multiselectPrompt.multiselect();
1004
1004
  }
package/package.json CHANGED
@@ -1,54 +1,53 @@
1
- {
2
- "name": "@topcli/prompts",
3
- "version": "2.1.0",
4
- "description": "Node.js user input library for command-line interfaces.",
5
- "scripts": {
6
- "build": "tsup index.ts --format cjs,esm --dts --clean",
7
- "prepublishOnly": "npm run build",
8
- "test": "glob -c \"tsx --no-warnings=ExperimentalWarning --loader=esmock --test\" \"./test/**/*.test.ts\"",
9
- "coverage": "c8 -r html npm run test",
10
- "lint": "eslint src test",
11
- "lint:fix": "eslint . --fix"
12
- },
13
- "main": "./dist/index.js",
14
- "types": "./dist/index.d.ts",
15
- "exports": {
16
- ".": {
17
- "types": "./dist/index.d.ts",
18
- "require": "./dist/index.cjs",
19
- "import": "./dist/index.js"
20
- }
21
- },
22
- "keywords": [
23
- "node.js",
24
- "cli",
25
- "prompt"
26
- ],
27
- "files": [
28
- "dist"
29
- ],
30
- "author": "PierreDemailly <pierredemailly.pro@gmail.com>",
31
- "license": "ISC",
32
- "type": "module",
33
- "devDependencies": {
34
- "@openally/config.eslint": "^1.3.0",
35
- "@openally/config.typescript": "^1.0.3",
36
- "@types/node": "^22.10.5",
37
- "c8": "^10.1.3",
38
- "esmock": "^2.6.9",
39
- "glob": "^11.0.0",
40
- "tsup": "^8.3.5",
41
- "tsx": "^4.19.2",
42
- "typescript": "^5.7.2"
43
- },
44
- "dependencies": {
45
- "@topcli/wcwidth": "^1.0.1"
46
- },
47
- "engines": {
48
- "node": "^20.12.0 || >=21.7.0"
49
- },
50
- "bugs": {
51
- "url": "https://github.com/TopCli/prompts/issues"
52
- },
53
- "homepage": "https://github.com/TopCli/prompts#readme"
54
- }
1
+ {
2
+ "name": "@topcli/prompts",
3
+ "version": "2.2.0",
4
+ "description": "Node.js user input library for command-line interfaces.",
5
+ "scripts": {
6
+ "build": "tsup index.ts --format cjs,esm --dts --clean",
7
+ "prepublishOnly": "npm run build",
8
+ "test": "glob -c \"tsx --test\" \"./test/**/*.test.ts\"",
9
+ "coverage": "c8 -r html npm run test",
10
+ "lint": "eslint src test",
11
+ "lint:fix": "eslint . --fix"
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "require": "./dist/index.cjs",
19
+ "import": "./dist/index.js"
20
+ }
21
+ },
22
+ "keywords": [
23
+ "node.js",
24
+ "cli",
25
+ "prompt"
26
+ ],
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "author": "PierreDemailly <pierredemailly.pro@gmail.com>",
31
+ "license": "ISC",
32
+ "type": "module",
33
+ "devDependencies": {
34
+ "@openally/config.eslint": "^2.0.0",
35
+ "@openally/config.typescript": "^1.0.3",
36
+ "@types/node": "^22.10.5",
37
+ "c8": "^10.1.3",
38
+ "glob": "^11.0.0",
39
+ "tsup": "^8.3.5",
40
+ "tsx": "^4.19.2",
41
+ "typescript": "^5.7.2"
42
+ },
43
+ "dependencies": {
44
+ "@topcli/wcwidth": "^1.0.1"
45
+ },
46
+ "engines": {
47
+ "node": "^20.12.0 || >=21.7.0"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/TopCli/prompts/issues"
51
+ },
52
+ "homepage": "https://github.com/TopCli/prompts#readme"
53
+ }