@topcli/prompts 1.6.0 → 1.7.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 +8 -4
- package/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/prompts/multiselect.js +27 -14
package/README.md
CHANGED
|
@@ -12,7 +12,8 @@ Node.js user prompt library for command-line interfaces.
|
|
|
12
12
|
|
|
13
13
|
## Getting Started
|
|
14
14
|
|
|
15
|
-
>
|
|
15
|
+
> [!CAUTION]
|
|
16
|
+
> This package is ESM only.
|
|
16
17
|
|
|
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).
|
|
18
19
|
|
|
@@ -94,7 +95,7 @@ Use `ignoreValues` to skip result render & clear lines after a selected one.
|
|
|
94
95
|
multiselect(message: string, options: MultiselectOptions): Promise<[string]>
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
Scrollable multiselect depending `maxVisible` (default `8`)
|
|
98
|
+
Scrollable multiselect depending `maxVisible` (default `8`).<br>
|
|
98
99
|
Use `preSelectedChoices` to pre-select choices.
|
|
99
100
|
|
|
100
101
|
Use `validators` to handle user input.
|
|
@@ -110,6 +111,8 @@ const os = await multiselect('Choose OS', {
|
|
|
110
111
|
|
|
111
112
|
Use `autocomplete` to allow filtered choices. This can be usefull for a large list of choices.
|
|
112
113
|
|
|
114
|
+
Use `caseSensitive` to make autocomplete filters case sensitive. Default `false`
|
|
115
|
+
|
|
113
116
|
### `confirm()`
|
|
114
117
|
|
|
115
118
|
```ts
|
|
@@ -136,7 +139,7 @@ assert.equal(input, "John");
|
|
|
136
139
|
> - When using `question()`, `validators` functions will not be executed.
|
|
137
140
|
> - When using `select()`, the answer can be different from the available choices.
|
|
138
141
|
> - When using `confirm()`, the answer can be any type other than boolean.
|
|
139
|
-
> - etc
|
|
142
|
+
> - etc<br>
|
|
140
143
|
> **Use with caution**
|
|
141
144
|
|
|
142
145
|
## Interfaces
|
|
@@ -180,6 +183,7 @@ export interface MultiselectOptions extends SharedOptions {
|
|
|
180
183
|
preSelectedChoices?: (Choice | string)[];
|
|
181
184
|
validators?: Validator[];
|
|
182
185
|
autocomplete?: boolean;
|
|
186
|
+
caseSensitive?: boolean;
|
|
183
187
|
}
|
|
184
188
|
|
|
185
189
|
export interface ConfirmOptions extends SharedOptions {
|
|
@@ -196,7 +200,7 @@ export interface ConfirmOptions extends SharedOptions {
|
|
|
196
200
|
<tbody>
|
|
197
201
|
<tr>
|
|
198
202
|
<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>
|
|
199
|
-
<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></td>
|
|
203
|
+
<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>
|
|
200
204
|
<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>
|
|
201
205
|
<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>
|
|
202
206
|
<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>
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -28,23 +28,35 @@ export class MultiselectPrompt extends AbstractPrompt {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
get filteredChoices() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return this.autocompleteValue.split(" ").every((word) => choice.includes(word)) ||
|
|
35
|
-
choice.includes(this.autocompleteValue);
|
|
36
|
-
}
|
|
31
|
+
if (!(this.options.autocomplete && this.autocompleteValue.length > 0)) {
|
|
32
|
+
return this.choices;
|
|
33
|
+
}
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
const isCaseSensitive = this.options.caseSensitive;
|
|
36
|
+
const autocompleteValue = isCaseSensitive ? this.autocompleteValue : this.autocompleteValue.toLowerCase();
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
return this.choices.filter((choice) => this.#filterChoice(choice, autocompleteValue, isCaseSensitive));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#filterChoice(choice, autocompleteValue, isCaseSensitive) {
|
|
42
|
+
// eslint-disable-next-line no-nested-ternary
|
|
43
|
+
const choiceValue = typeof choice === "string" ?
|
|
44
|
+
(isCaseSensitive ? choice : choice.toLowerCase()) :
|
|
45
|
+
(isCaseSensitive ? choice.label : choice.label.toLowerCase());
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (autocompleteValue.includes(" ")) {
|
|
48
|
+
return this.#filterMultipleWords(choiceValue, autocompleteValue, isCaseSensitive);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return choiceValue.includes(autocompleteValue);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#filterMultipleWords(choiceValue, autocompleteValue, isCaseSensitive) {
|
|
55
|
+
return autocompleteValue.split(" ").every((word) => {
|
|
56
|
+
const wordValue = isCaseSensitive ? word : word.toLowerCase();
|
|
57
|
+
|
|
58
|
+
return choiceValue.includes(wordValue) || choiceValue.includes(autocompleteValue);
|
|
59
|
+
});
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
get longestChoice() {
|
|
@@ -109,6 +121,7 @@ export class MultiselectPrompt extends AbstractPrompt {
|
|
|
109
121
|
});
|
|
110
122
|
|
|
111
123
|
if (choiceIndex === -1) {
|
|
124
|
+
this.destroy();
|
|
112
125
|
throw new Error(`Invalid pre-selected choice: ${choice.value ?? choice}`);
|
|
113
126
|
}
|
|
114
127
|
|