@topcli/prompts 2.4.0 → 2.4.1
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 +21 -20
- package/dist/index.cjs +49 -44
- package/dist/index.d.cts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.js +48 -43
- package/package.json +14 -9
package/README.md
CHANGED
|
@@ -84,9 +84,9 @@ const packageName = await question('Package name', {
|
|
|
84
84
|
- required
|
|
85
85
|
|
|
86
86
|
```js
|
|
87
|
-
import {
|
|
87
|
+
import { question, required } from "@topcli/prompts";
|
|
88
88
|
|
|
89
|
-
const name = await
|
|
89
|
+
const name = await question("What's your name ?", {
|
|
90
90
|
validators: [required()]
|
|
91
91
|
});
|
|
92
92
|
```
|
|
@@ -94,7 +94,7 @@ const name = await prompt("What's your name ?", {
|
|
|
94
94
|
### `select()`
|
|
95
95
|
|
|
96
96
|
```ts
|
|
97
|
-
select(message: string, options: SelectOptions): Promise<
|
|
97
|
+
select<T extends string>(message: string, options: SelectOptions<T>): Promise<T>
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
Scrollable select depending `maxVisible` (default `8`).
|
|
@@ -114,7 +114,7 @@ Use `options.skip` to skip prompt. It will return the first choice.
|
|
|
114
114
|
### `multiselect()`
|
|
115
115
|
|
|
116
116
|
```ts
|
|
117
|
-
multiselect(message: string, options: MultiselectOptions): Promise<[
|
|
117
|
+
multiselect<T extends string>(message: string, options: MultiselectOptions<T>): Promise<T[]>
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
Scrollable multiselect depending `options.maxVisible` (default `8`).<br>
|
|
@@ -196,46 +196,46 @@ export interface AbstractPromptOptions {
|
|
|
196
196
|
stdin?: Stdin;
|
|
197
197
|
stdout?: Stdout;
|
|
198
198
|
message: string;
|
|
199
|
-
|
|
199
|
+
skip?: boolean;
|
|
200
|
+
signal?: AbortSignal;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
|
-
export interface PromptValidator<T
|
|
203
|
-
|
|
204
|
-
error: (input: T) => string;
|
|
203
|
+
export interface PromptValidator<T extends string | string[]> {
|
|
204
|
+
validate: (input: T) => boolean;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
export interface QuestionOptions extends SharedOptions {
|
|
208
208
|
defaultValue?: string;
|
|
209
|
-
validators?:
|
|
209
|
+
validators?: PromptValidator<string>[];
|
|
210
210
|
secure?: boolean;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
export interface Choice {
|
|
214
|
-
value:
|
|
213
|
+
export interface Choice<T = any> {
|
|
214
|
+
value: T;
|
|
215
215
|
label: string;
|
|
216
216
|
description?: string;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
export interface SelectOptions extends
|
|
220
|
-
choices: (Choice |
|
|
219
|
+
export interface SelectOptions<T extends string> extends AbstractPromptOptions {
|
|
220
|
+
choices: (Choice<T> | T)[];
|
|
221
221
|
maxVisible?: number;
|
|
222
|
-
ignoreValues?: (
|
|
223
|
-
validators?:
|
|
222
|
+
ignoreValues?: (T | number | boolean)[];
|
|
223
|
+
validators?: PromptValidator<string>[];
|
|
224
224
|
autocomplete?: boolean;
|
|
225
225
|
caseSensitive?: boolean;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
export interface MultiselectOptions extends
|
|
229
|
-
choices: (Choice |
|
|
228
|
+
export interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
|
|
229
|
+
choices: (Choice<T> | T)[];
|
|
230
230
|
maxVisible?: number;
|
|
231
|
-
preSelectedChoices?: (Choice |
|
|
232
|
-
validators?:
|
|
231
|
+
preSelectedChoices?: (Choice<T> | T)[];
|
|
232
|
+
validators?: PromptValidator<string[]>[];
|
|
233
233
|
autocomplete?: boolean;
|
|
234
234
|
caseSensitive?: boolean;
|
|
235
235
|
showHint?: boolean;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
export interface ConfirmOptions extends
|
|
238
|
+
export interface ConfirmOptions extends AbstractPromptOptions {
|
|
239
239
|
initial?: boolean;
|
|
240
240
|
}
|
|
241
241
|
```
|
|
@@ -264,6 +264,7 @@ Open an issue if you want to provide feedback such as bug reports or enchancemen
|
|
|
264
264
|
</tr>
|
|
265
265
|
<tr>
|
|
266
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
|
+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ItsHarper"><img src="https://avatars.githubusercontent.com/u/10224994?v=4?s=100" width="100px;" alt="Harper Andrews"/><br /><sub><b>Harper Andrews</b></sub></a><br /><a href="https://github.com/TopCli/prompts/commits?author=ItsHarper" title="Documentation">📖</a></td>
|
|
267
268
|
</tr>
|
|
268
269
|
</tbody>
|
|
269
270
|
</table>
|
package/dist/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// index.ts
|
|
30
|
+
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
PromptAgent: () => PromptAgent,
|
|
@@ -39,16 +39,30 @@ __export(index_exports, {
|
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(index_exports);
|
|
41
41
|
|
|
42
|
-
// src/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
// src/validators.ts
|
|
43
|
+
function required() {
|
|
44
|
+
return {
|
|
45
|
+
validate: (input) => {
|
|
46
|
+
const isValid2 = Array.isArray(input) ? input.length > 0 : Boolean(input);
|
|
47
|
+
return isValid2 ? null : { isValid: isValid2, error: "required" };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function isValid(result) {
|
|
52
|
+
if (typeof result === "object") {
|
|
53
|
+
return result?.isValid !== false;
|
|
54
|
+
}
|
|
55
|
+
if (typeof result === "string") {
|
|
56
|
+
return result.length > 0;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
function resultError(result) {
|
|
61
|
+
if (typeof result === "object") {
|
|
62
|
+
return result.error;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
52
66
|
|
|
53
67
|
// src/prompt-agent.ts
|
|
54
68
|
var kPrivateInstancier = Symbol("instancier");
|
|
@@ -93,6 +107,13 @@ var PromptAgent = class _PromptAgent {
|
|
|
93
107
|
}
|
|
94
108
|
};
|
|
95
109
|
|
|
110
|
+
// src/prompts/abstract.ts
|
|
111
|
+
var import_node_os = require("os");
|
|
112
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
113
|
+
var import_node_stream = require("stream");
|
|
114
|
+
var import_node_events = __toESM(require("events"), 1);
|
|
115
|
+
var import_node_util = require("util");
|
|
116
|
+
|
|
96
117
|
// src/errors/abort.ts
|
|
97
118
|
var AbortError = class extends Error {
|
|
98
119
|
constructor(message) {
|
|
@@ -205,6 +226,10 @@ var AbstractPrompt = class _AbstractPrompt extends import_node_events.default {
|
|
|
205
226
|
}
|
|
206
227
|
};
|
|
207
228
|
|
|
229
|
+
// src/prompts/question.ts
|
|
230
|
+
var import_node_os2 = require("os");
|
|
231
|
+
var import_node_util4 = require("util");
|
|
232
|
+
|
|
208
233
|
// src/utils.ts
|
|
209
234
|
var import_node_process = __toESM(require("process"), 1);
|
|
210
235
|
var import_node_util2 = require("util");
|
|
@@ -263,31 +288,6 @@ var SYMBOLS = {
|
|
|
263
288
|
Inactive: (0, import_node_util3.styleText)("gray", kSymbols.inactive)
|
|
264
289
|
};
|
|
265
290
|
|
|
266
|
-
// src/validators.ts
|
|
267
|
-
function required() {
|
|
268
|
-
return {
|
|
269
|
-
validate: (input) => {
|
|
270
|
-
const isValid2 = Array.isArray(input) ? input.length > 0 : Boolean(input);
|
|
271
|
-
return isValid2 ? null : { isValid: isValid2, error: "required" };
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
function isValid(result) {
|
|
276
|
-
if (typeof result === "object") {
|
|
277
|
-
return result?.isValid !== false;
|
|
278
|
-
}
|
|
279
|
-
if (typeof result === "string") {
|
|
280
|
-
return result.length > 0;
|
|
281
|
-
}
|
|
282
|
-
return true;
|
|
283
|
-
}
|
|
284
|
-
function resultError(result) {
|
|
285
|
-
if (typeof result === "object") {
|
|
286
|
-
return result.error;
|
|
287
|
-
}
|
|
288
|
-
return result;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
291
|
// src/prompts/question.ts
|
|
292
292
|
var QuestionPrompt = class extends AbstractPrompt {
|
|
293
293
|
defaultValue;
|
|
@@ -1049,21 +1049,26 @@ var MultiselectPrompt = class extends AbstractPrompt {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
};
|
|
1051
1051
|
|
|
1052
|
-
// index.ts
|
|
1052
|
+
// src/index.ts
|
|
1053
1053
|
function question(message, options = {}) {
|
|
1054
|
-
return new QuestionPrompt(
|
|
1054
|
+
return new QuestionPrompt(
|
|
1055
|
+
{ ...options, message }
|
|
1056
|
+
).question();
|
|
1055
1057
|
}
|
|
1056
1058
|
function select(message, options) {
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
+
return new SelectPrompt(
|
|
1060
|
+
{ ...options, message }
|
|
1061
|
+
).select();
|
|
1059
1062
|
}
|
|
1060
1063
|
function confirm(message, options = {}) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1064
|
+
return new ConfirmPrompt(
|
|
1065
|
+
{ ...options, message }
|
|
1066
|
+
).confirm();
|
|
1063
1067
|
}
|
|
1064
1068
|
function multiselect(message, options) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1069
|
+
return new MultiselectPrompt(
|
|
1070
|
+
{ ...options, message }
|
|
1071
|
+
).multiselect();
|
|
1067
1072
|
}
|
|
1068
1073
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1069
1074
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -5,13 +5,14 @@ type InvalidResponseObject = {
|
|
|
5
5
|
isValid: false;
|
|
6
6
|
error: string;
|
|
7
7
|
};
|
|
8
|
+
type ValidationResponseObject = ValidResponseObject | InvalidResponseObject;
|
|
8
9
|
type ValidationResponse = InvalidResponse | ValidResponse;
|
|
9
10
|
type InvalidResponse = string | InvalidResponseObject;
|
|
10
11
|
type ValidResponse = null | undefined | true | ValidResponseObject;
|
|
11
|
-
interface PromptValidator<T
|
|
12
|
+
interface PromptValidator<T extends string | string[]> {
|
|
12
13
|
validate: (input: T) => ValidationResponse;
|
|
13
14
|
}
|
|
14
|
-
declare function required
|
|
15
|
+
declare function required(): PromptValidator<any>;
|
|
15
16
|
|
|
16
17
|
declare class PromptAgent<T = string> {
|
|
17
18
|
#private;
|
|
@@ -39,6 +40,12 @@ declare class PromptAgent<T = string> {
|
|
|
39
40
|
nextAnswer(value: T): void;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
interface Choice<T extends string> {
|
|
44
|
+
value: T;
|
|
45
|
+
label: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
type Stdin = NodeJS.ReadStream & {
|
|
43
50
|
fd: 0;
|
|
44
51
|
};
|
|
@@ -53,15 +60,9 @@ interface AbstractPromptOptions {
|
|
|
53
60
|
signal?: AbortSignal;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
interface Choice<T = any> {
|
|
57
|
-
value: T;
|
|
58
|
-
label: string;
|
|
59
|
-
description?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
63
|
interface QuestionOptions extends AbstractPromptOptions {
|
|
63
64
|
defaultValue?: string;
|
|
64
|
-
validators?: PromptValidator[];
|
|
65
|
+
validators?: PromptValidator<string>[];
|
|
65
66
|
secure?: boolean | {
|
|
66
67
|
placeholder: string;
|
|
67
68
|
};
|
|
@@ -71,23 +72,23 @@ interface ConfirmOptions extends AbstractPromptOptions {
|
|
|
71
72
|
initial?: boolean;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
interface
|
|
75
|
+
interface SelectOptions<T extends string> extends AbstractPromptOptions {
|
|
75
76
|
choices: (Choice<T> | T)[];
|
|
76
77
|
maxVisible?: number;
|
|
77
|
-
|
|
78
|
-
validators?: PromptValidator<
|
|
78
|
+
ignoreValues?: (T | number | boolean)[];
|
|
79
|
+
validators?: PromptValidator<string>[];
|
|
79
80
|
autocomplete?: boolean;
|
|
80
81
|
caseSensitive?: boolean;
|
|
81
|
-
showHint?: boolean;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
interface
|
|
84
|
+
interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
|
|
85
85
|
choices: (Choice<T> | T)[];
|
|
86
86
|
maxVisible?: number;
|
|
87
|
-
|
|
88
|
-
validators?: PromptValidator<
|
|
87
|
+
preSelectedChoices?: (Choice<T> | T)[];
|
|
88
|
+
validators?: PromptValidator<string[]>[];
|
|
89
89
|
autocomplete?: boolean;
|
|
90
90
|
caseSensitive?: boolean;
|
|
91
|
+
showHint?: boolean;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
|
|
@@ -95,4 +96,4 @@ declare function select<T extends string>(message: string, options: Omit<SelectO
|
|
|
95
96
|
declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
|
|
96
97
|
declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
|
|
97
98
|
|
|
98
|
-
export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
|
|
99
|
+
export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type InvalidResponse, type InvalidResponseObject, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, type ValidResponse, type ValidResponseObject, type ValidationResponse, type ValidationResponseObject, confirm, multiselect, question, required, select };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,13 +5,14 @@ type InvalidResponseObject = {
|
|
|
5
5
|
isValid: false;
|
|
6
6
|
error: string;
|
|
7
7
|
};
|
|
8
|
+
type ValidationResponseObject = ValidResponseObject | InvalidResponseObject;
|
|
8
9
|
type ValidationResponse = InvalidResponse | ValidResponse;
|
|
9
10
|
type InvalidResponse = string | InvalidResponseObject;
|
|
10
11
|
type ValidResponse = null | undefined | true | ValidResponseObject;
|
|
11
|
-
interface PromptValidator<T
|
|
12
|
+
interface PromptValidator<T extends string | string[]> {
|
|
12
13
|
validate: (input: T) => ValidationResponse;
|
|
13
14
|
}
|
|
14
|
-
declare function required
|
|
15
|
+
declare function required(): PromptValidator<any>;
|
|
15
16
|
|
|
16
17
|
declare class PromptAgent<T = string> {
|
|
17
18
|
#private;
|
|
@@ -39,6 +40,12 @@ declare class PromptAgent<T = string> {
|
|
|
39
40
|
nextAnswer(value: T): void;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
interface Choice<T extends string> {
|
|
44
|
+
value: T;
|
|
45
|
+
label: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
42
49
|
type Stdin = NodeJS.ReadStream & {
|
|
43
50
|
fd: 0;
|
|
44
51
|
};
|
|
@@ -53,15 +60,9 @@ interface AbstractPromptOptions {
|
|
|
53
60
|
signal?: AbortSignal;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
interface Choice<T = any> {
|
|
57
|
-
value: T;
|
|
58
|
-
label: string;
|
|
59
|
-
description?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
63
|
interface QuestionOptions extends AbstractPromptOptions {
|
|
63
64
|
defaultValue?: string;
|
|
64
|
-
validators?: PromptValidator[];
|
|
65
|
+
validators?: PromptValidator<string>[];
|
|
65
66
|
secure?: boolean | {
|
|
66
67
|
placeholder: string;
|
|
67
68
|
};
|
|
@@ -71,23 +72,23 @@ interface ConfirmOptions extends AbstractPromptOptions {
|
|
|
71
72
|
initial?: boolean;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
interface
|
|
75
|
+
interface SelectOptions<T extends string> extends AbstractPromptOptions {
|
|
75
76
|
choices: (Choice<T> | T)[];
|
|
76
77
|
maxVisible?: number;
|
|
77
|
-
|
|
78
|
-
validators?: PromptValidator<
|
|
78
|
+
ignoreValues?: (T | number | boolean)[];
|
|
79
|
+
validators?: PromptValidator<string>[];
|
|
79
80
|
autocomplete?: boolean;
|
|
80
81
|
caseSensitive?: boolean;
|
|
81
|
-
showHint?: boolean;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
interface
|
|
84
|
+
interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
|
|
85
85
|
choices: (Choice<T> | T)[];
|
|
86
86
|
maxVisible?: number;
|
|
87
|
-
|
|
88
|
-
validators?: PromptValidator<
|
|
87
|
+
preSelectedChoices?: (Choice<T> | T)[];
|
|
88
|
+
validators?: PromptValidator<string[]>[];
|
|
89
89
|
autocomplete?: boolean;
|
|
90
90
|
caseSensitive?: boolean;
|
|
91
|
+
showHint?: boolean;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
|
|
@@ -95,4 +96,4 @@ declare function select<T extends string>(message: string, options: Omit<SelectO
|
|
|
95
96
|
declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
|
|
96
97
|
declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
|
|
97
98
|
|
|
98
|
-
export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
|
|
99
|
+
export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type InvalidResponse, type InvalidResponseObject, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, type ValidResponse, type ValidResponseObject, type ValidationResponse, type ValidationResponseObject, confirm, multiselect, question, required, select };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
// src/validators.ts
|
|
2
|
+
function required() {
|
|
3
|
+
return {
|
|
4
|
+
validate: (input) => {
|
|
5
|
+
const isValid2 = Array.isArray(input) ? input.length > 0 : Boolean(input);
|
|
6
|
+
return isValid2 ? null : { isValid: isValid2, error: "required" };
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function isValid(result) {
|
|
11
|
+
if (typeof result === "object") {
|
|
12
|
+
return result?.isValid !== false;
|
|
13
|
+
}
|
|
14
|
+
if (typeof result === "string") {
|
|
15
|
+
return result.length > 0;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function resultError(result) {
|
|
20
|
+
if (typeof result === "object") {
|
|
21
|
+
return result.error;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
11
25
|
|
|
12
26
|
// src/prompt-agent.ts
|
|
13
27
|
var kPrivateInstancier = Symbol("instancier");
|
|
@@ -52,6 +66,13 @@ var PromptAgent = class _PromptAgent {
|
|
|
52
66
|
}
|
|
53
67
|
};
|
|
54
68
|
|
|
69
|
+
// src/prompts/abstract.ts
|
|
70
|
+
import { EOL } from "node:os";
|
|
71
|
+
import readline from "node:readline";
|
|
72
|
+
import { Writable } from "node:stream";
|
|
73
|
+
import EventEmitter from "node:events";
|
|
74
|
+
import { stripVTControlCharacters } from "node:util";
|
|
75
|
+
|
|
55
76
|
// src/errors/abort.ts
|
|
56
77
|
var AbortError = class extends Error {
|
|
57
78
|
constructor(message) {
|
|
@@ -164,6 +185,10 @@ var AbstractPrompt = class _AbstractPrompt extends EventEmitter {
|
|
|
164
185
|
}
|
|
165
186
|
};
|
|
166
187
|
|
|
188
|
+
// src/prompts/question.ts
|
|
189
|
+
import { EOL as EOL2 } from "node:os";
|
|
190
|
+
import { styleText as styleText2 } from "node:util";
|
|
191
|
+
|
|
167
192
|
// src/utils.ts
|
|
168
193
|
import process2 from "node:process";
|
|
169
194
|
import { stripVTControlCharacters as stripVTControlCharacters2 } from "node:util";
|
|
@@ -222,31 +247,6 @@ var SYMBOLS = {
|
|
|
222
247
|
Inactive: styleText("gray", kSymbols.inactive)
|
|
223
248
|
};
|
|
224
249
|
|
|
225
|
-
// src/validators.ts
|
|
226
|
-
function required() {
|
|
227
|
-
return {
|
|
228
|
-
validate: (input) => {
|
|
229
|
-
const isValid2 = Array.isArray(input) ? input.length > 0 : Boolean(input);
|
|
230
|
-
return isValid2 ? null : { isValid: isValid2, error: "required" };
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
function isValid(result) {
|
|
235
|
-
if (typeof result === "object") {
|
|
236
|
-
return result?.isValid !== false;
|
|
237
|
-
}
|
|
238
|
-
if (typeof result === "string") {
|
|
239
|
-
return result.length > 0;
|
|
240
|
-
}
|
|
241
|
-
return true;
|
|
242
|
-
}
|
|
243
|
-
function resultError(result) {
|
|
244
|
-
if (typeof result === "object") {
|
|
245
|
-
return result.error;
|
|
246
|
-
}
|
|
247
|
-
return result;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
250
|
// src/prompts/question.ts
|
|
251
251
|
var QuestionPrompt = class extends AbstractPrompt {
|
|
252
252
|
defaultValue;
|
|
@@ -1008,21 +1008,26 @@ var MultiselectPrompt = class extends AbstractPrompt {
|
|
|
1008
1008
|
}
|
|
1009
1009
|
};
|
|
1010
1010
|
|
|
1011
|
-
// index.ts
|
|
1011
|
+
// src/index.ts
|
|
1012
1012
|
function question(message, options = {}) {
|
|
1013
|
-
return new QuestionPrompt(
|
|
1013
|
+
return new QuestionPrompt(
|
|
1014
|
+
{ ...options, message }
|
|
1015
|
+
).question();
|
|
1014
1016
|
}
|
|
1015
1017
|
function select(message, options) {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
+
return new SelectPrompt(
|
|
1019
|
+
{ ...options, message }
|
|
1020
|
+
).select();
|
|
1018
1021
|
}
|
|
1019
1022
|
function confirm(message, options = {}) {
|
|
1020
|
-
|
|
1021
|
-
|
|
1023
|
+
return new ConfirmPrompt(
|
|
1024
|
+
{ ...options, message }
|
|
1025
|
+
).confirm();
|
|
1022
1026
|
}
|
|
1023
1027
|
function multiselect(message, options) {
|
|
1024
|
-
|
|
1025
|
-
|
|
1028
|
+
return new MultiselectPrompt(
|
|
1029
|
+
{ ...options, message }
|
|
1030
|
+
).multiselect();
|
|
1026
1031
|
}
|
|
1027
1032
|
export {
|
|
1028
1033
|
PromptAgent,
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topcli/prompts",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Node.js user input library for command-line interfaces.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
|
-
"build": "tsup index.ts --format cjs,esm --dts --clean",
|
|
7
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
7
8
|
"prepublishOnly": "npm run build",
|
|
8
|
-
"test": "glob -c \"tsx --test\" \"./test/**/*.test.ts\"",
|
|
9
|
-
"
|
|
9
|
+
"test-only": "glob -c \"tsx --test\" \"./test/**/*.test.ts\"",
|
|
10
|
+
"test-types": "npm run build && tsd && attw --pack .",
|
|
11
|
+
"test": "c8 -r html npm run test-only && npm run test-types",
|
|
10
12
|
"lint": "eslint src test",
|
|
11
13
|
"lint:fix": "eslint . --fix"
|
|
12
14
|
},
|
|
@@ -14,9 +16,8 @@
|
|
|
14
16
|
"types": "./dist/index.d.ts",
|
|
15
17
|
"exports": {
|
|
16
18
|
".": {
|
|
17
|
-
"
|
|
18
|
-
"require": "./dist/index.cjs"
|
|
19
|
-
"import": "./dist/index.js"
|
|
19
|
+
"import": "./dist/index.js",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
"keywords": [
|
|
@@ -29,13 +30,14 @@
|
|
|
29
30
|
],
|
|
30
31
|
"author": "PierreDemailly <pierredemailly.pro@gmail.com>",
|
|
31
32
|
"license": "ISC",
|
|
32
|
-
"type": "module",
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
34
35
|
"@openally/config.eslint": "^2.0.0",
|
|
35
36
|
"@openally/config.typescript": "^1.0.3",
|
|
36
37
|
"@types/node": "^24.0.3",
|
|
37
38
|
"c8": "^10.1.3",
|
|
38
39
|
"glob": "^11.0.0",
|
|
40
|
+
"tsd": "^0.33.0",
|
|
39
41
|
"tsup": "^8.3.5",
|
|
40
42
|
"tsx": "^4.19.2",
|
|
41
43
|
"typescript": "^5.7.2"
|
|
@@ -46,5 +48,8 @@
|
|
|
46
48
|
"bugs": {
|
|
47
49
|
"url": "https://github.com/TopCli/prompts/issues"
|
|
48
50
|
},
|
|
49
|
-
"homepage": "https://github.com/TopCli/prompts#readme"
|
|
51
|
+
"homepage": "https://github.com/TopCli/prompts#readme",
|
|
52
|
+
"tsd": {
|
|
53
|
+
"directory": "test/types"
|
|
54
|
+
}
|
|
50
55
|
}
|