@topcli/prompts 1.8.1 → 1.10.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/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # prompts
1
+ <div align="center">
2
+ <img src="./public/banner.png" alt="@topcli/prompts">
2
3
 
3
- ![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)
4
- [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=for-the-badge)](https://github.com/TopCli/prompts/commit-activity)
5
- [![isc](https://img.shields.io/badge/License-ISC-blue.svg?style=for-the-badge)](https://github.com/TopCli/prompts/blob/main/LICENSE)
6
- ![build](https://img.shields.io/github/actions/workflow/status/TopCli/prompts/node.js.yml?style=for-the-badge)
7
-
8
- Node.js user prompt library for command-line interfaces.
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
+ ![build](https://img.shields.io/github/actions/workflow/status/TopCli/prompts/node.js.yml?style=for-the-badge)
8
+ </div>
9
9
 
10
10
  ## Requirements
11
11
  - [Node.js](https://nodejs.org/en/) v18 or higher
@@ -49,9 +49,13 @@ question(message: string, options?: PromptOptions): Promise<string>
49
49
  ```
50
50
 
51
51
  Simple prompt, similar to `rl.question()` with an improved UI.
52
+
52
53
  Use `options.secure` if you need to hide both input and answer.
54
+
53
55
  Use `options.validators` to handle user input.
54
56
 
57
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
58
+
55
59
  **Example**
56
60
 
57
61
  ```js
@@ -84,8 +88,17 @@ select(message: string, options: SelectOptions): Promise<string>
84
88
  ```
85
89
 
86
90
  Scrollable select depending `maxVisible` (default `8`).
91
+
87
92
  Use `ignoreValues` to skip result render & clear lines after a selected one.
88
93
 
94
+ Use `validators` to handle user input.
95
+
96
+ Use `autocomplete` to allow filtered choices. This can be useful for a large list of choices.
97
+
98
+ Use `caseSensitive` to make autocomplete filters case sensitive. Default `false`
99
+
100
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
101
+
89
102
  ### `multiselect()`
90
103
 
91
104
  ```ts
@@ -97,18 +110,13 @@ Use `preSelectedChoices` to pre-select choices.
97
110
 
98
111
  Use `validators` to handle user input.
99
112
 
100
- **Example**
113
+ Use `showHint: false` to disable hint (this option is truthy by default).
101
114
 
102
- ```js
103
- const os = await multiselect('Choose OS', {
104
- choices: ["linux", "mac", "windows"]
105
- validators: [required()]
106
- });
107
- ```
115
+ Use `autocomplete` to allow filtered choices. This can be useful for a large list of choices.
108
116
 
109
- Use `autocomplete` to allow filtered choices. This can be usefull for a large list of choices.
117
+ Use `caseSensitive` to make autocomplete filters case sensitive. Default `false`.
110
118
 
111
- Use `caseSensitive` to make autocomplete filters case sensitive. Default `false`
119
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
112
120
 
113
121
  ### `confirm()`
114
122
 
@@ -118,6 +126,8 @@ confirm(message: string, options?: ConfirmOptions): Promise<boolean>
118
126
 
119
127
  Boolean prompt, return `options.initial` if user input is different from `y`/`yes`/`n`/`no` (case insensitive), (default `false`).
120
128
 
129
+ Use `options.signal` to set an `AbortSignal` (throws a [AbortError](#aborterror)).
130
+
121
131
  ### `PromptAgent`
122
132
 
123
133
  The `PromptAgent` class allows to programmatically set the next answers for any prompt function, this can be useful for testing.
@@ -139,16 +149,35 @@ assert.equal(input, "John");
139
149
  > - etc<br>
140
150
  > **Use with caution**
141
151
 
152
+ ## Errors
153
+
154
+ ### `AbortError`
155
+
156
+ ```ts
157
+ export class AbortError extends Error {
158
+ constructor(message: string) {
159
+ super(message);
160
+ this.name = "AbortError";
161
+ }
162
+ }
163
+ ```
164
+
142
165
  ## Interfaces
143
166
 
144
167
  ```ts
145
- export interface SharedOptions {
146
- stdin?: NodeJS.ReadStream & {
147
- fd: 0;
148
- };
149
- stdout?: NodeJS.WriteStream & {
150
- fd: 1;
151
- };
168
+ type Stdin = NodeJS.ReadStream & {
169
+ fd: 0;
170
+ };
171
+
172
+ type Stdout = NodeJS.WriteStream & {
173
+ fd: 1;
174
+ }
175
+
176
+ export interface AbstractPromptOptions {
177
+ stdin?: Stdin;
178
+ stdout?: Stdout;
179
+ message: string;
180
+ sginal?: AbortSignal;
152
181
  }
153
182
 
154
183
  export interface PromptValidator<T = string | string[] | boolean> {
@@ -172,6 +201,9 @@ export interface SelectOptions extends SharedOptions {
172
201
  choices: (Choice | string)[];
173
202
  maxVisible?: number;
174
203
  ignoreValues?: (string | number | boolean)[];
204
+ validators?: Validator[];
205
+ autocomplete?: boolean;
206
+ caseSensitive?: boolean;
175
207
  }
176
208
 
177
209
  export interface MultiselectOptions extends SharedOptions {
@@ -181,6 +213,7 @@ export interface MultiselectOptions extends SharedOptions {
181
213
  validators?: Validator[];
182
214
  autocomplete?: boolean;
183
215
  caseSensitive?: boolean;
216
+ showHint?: boolean;
184
217
  }
185
218
 
186
219
  export interface ConfirmOptions extends SharedOptions {
@@ -202,6 +235,10 @@ export interface ConfirmOptions extends SharedOptions {
202
235
  <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>
203
236
  <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>
204
237
  <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>
238
+ <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>
239
+ </tr>
240
+ <tr>
241
+ <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>
205
242
  </tr>
206
243
  </tbody>
207
244
  </table>