@topcli/prompts 2.4.0 → 3.0.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/dist/index.d.cts CHANGED
@@ -5,13 +5,22 @@ 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 = string | string[] | boolean> {
12
- validate: (input: T) => ValidationResponse;
12
+ type ValidTransformationResponse<T> = {
13
+ isValid: true;
14
+ transformed: T;
15
+ };
16
+ type TransformationResponse<T> = InvalidResponse | ValidTransformationResponse<T>;
17
+ interface PromptValidator<T extends string | string[]> {
18
+ validate: (input: T) => ValidationResponse | Promise<ValidationResponse>;
19
+ }
20
+ interface PromptTransformer<T> {
21
+ transform: (input: string) => TransformationResponse<T> | Promise<TransformationResponse<T>>;
13
22
  }
14
- declare function required<T = string | string[] | boolean>(): PromptValidator<T>;
23
+ declare function required(): PromptValidator<any>;
15
24
 
16
25
  declare class PromptAgent<T = string> {
17
26
  #private;
@@ -39,6 +48,16 @@ declare class PromptAgent<T = string> {
39
48
  nextAnswer(value: T): void;
40
49
  }
41
50
 
51
+ declare function number(): PromptTransformer<number>;
52
+ declare function integer(): PromptTransformer<number>;
53
+ declare function url(): PromptTransformer<URL>;
54
+
55
+ interface Choice<T extends string> {
56
+ value: T;
57
+ label: string;
58
+ description?: string;
59
+ }
60
+
42
61
  type Stdin = NodeJS.ReadStream & {
43
62
  fd: 0;
44
63
  };
@@ -53,15 +72,10 @@ interface AbstractPromptOptions {
53
72
  signal?: AbortSignal;
54
73
  }
55
74
 
56
- interface Choice<T = any> {
57
- value: T;
58
- label: string;
59
- description?: string;
60
- }
61
-
62
- interface QuestionOptions extends AbstractPromptOptions {
75
+ interface QuestionOptions<T = string> extends AbstractPromptOptions {
63
76
  defaultValue?: string;
64
- validators?: PromptValidator[];
77
+ validators?: PromptValidator<string>[];
78
+ transformer?: PromptTransformer<T>;
65
79
  secure?: boolean | {
66
80
  placeholder: string;
67
81
  };
@@ -71,28 +85,37 @@ interface ConfirmOptions extends AbstractPromptOptions {
71
85
  initial?: boolean;
72
86
  }
73
87
 
74
- interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
88
+ interface SelectOptions<T extends string> extends AbstractPromptOptions {
75
89
  choices: (Choice<T> | T)[];
76
90
  maxVisible?: number;
77
- preSelectedChoices?: (Choice | T)[];
78
- validators?: PromptValidator<T[]>[];
91
+ ignoreValues?: (T | number | boolean)[];
92
+ validators?: PromptValidator<string>[];
79
93
  autocomplete?: boolean;
80
94
  caseSensitive?: boolean;
81
- showHint?: boolean;
82
95
  }
83
96
 
84
- interface SelectOptions<T extends string> extends AbstractPromptOptions {
97
+ interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
85
98
  choices: (Choice<T> | T)[];
86
99
  maxVisible?: number;
87
- ignoreValues?: (T | number | boolean)[];
88
- validators?: PromptValidator<T>[];
100
+ preSelectedChoices?: (Choice<T> | T)[];
101
+ validators?: PromptValidator<string[]>[];
89
102
  autocomplete?: boolean;
90
103
  caseSensitive?: boolean;
104
+ showHint?: boolean;
91
105
  }
92
106
 
93
- declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
107
+ declare function question<T = string>(message: string, options?: Omit<QuestionOptions<T>, "message">): Promise<T>;
94
108
  declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
95
109
  declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
96
110
  declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
97
111
 
98
- export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
112
+ declare const validators: {
113
+ required: typeof required;
114
+ };
115
+ declare const transformers: {
116
+ number: typeof number;
117
+ integer: typeof integer;
118
+ url: typeof url;
119
+ };
120
+
121
+ export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type InvalidResponse, type InvalidResponseObject, type MultiselectOptions, PromptAgent, type PromptTransformer, type PromptValidator, type QuestionOptions, type SelectOptions, type TransformationResponse, type ValidResponse, type ValidResponseObject, type ValidTransformationResponse, type ValidationResponse, type ValidationResponseObject, confirm, multiselect, question, select, transformers, validators };
package/dist/index.d.ts CHANGED
@@ -5,13 +5,22 @@ 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 = string | string[] | boolean> {
12
- validate: (input: T) => ValidationResponse;
12
+ type ValidTransformationResponse<T> = {
13
+ isValid: true;
14
+ transformed: T;
15
+ };
16
+ type TransformationResponse<T> = InvalidResponse | ValidTransformationResponse<T>;
17
+ interface PromptValidator<T extends string | string[]> {
18
+ validate: (input: T) => ValidationResponse | Promise<ValidationResponse>;
19
+ }
20
+ interface PromptTransformer<T> {
21
+ transform: (input: string) => TransformationResponse<T> | Promise<TransformationResponse<T>>;
13
22
  }
14
- declare function required<T = string | string[] | boolean>(): PromptValidator<T>;
23
+ declare function required(): PromptValidator<any>;
15
24
 
16
25
  declare class PromptAgent<T = string> {
17
26
  #private;
@@ -39,6 +48,16 @@ declare class PromptAgent<T = string> {
39
48
  nextAnswer(value: T): void;
40
49
  }
41
50
 
51
+ declare function number(): PromptTransformer<number>;
52
+ declare function integer(): PromptTransformer<number>;
53
+ declare function url(): PromptTransformer<URL>;
54
+
55
+ interface Choice<T extends string> {
56
+ value: T;
57
+ label: string;
58
+ description?: string;
59
+ }
60
+
42
61
  type Stdin = NodeJS.ReadStream & {
43
62
  fd: 0;
44
63
  };
@@ -53,15 +72,10 @@ interface AbstractPromptOptions {
53
72
  signal?: AbortSignal;
54
73
  }
55
74
 
56
- interface Choice<T = any> {
57
- value: T;
58
- label: string;
59
- description?: string;
60
- }
61
-
62
- interface QuestionOptions extends AbstractPromptOptions {
75
+ interface QuestionOptions<T = string> extends AbstractPromptOptions {
63
76
  defaultValue?: string;
64
- validators?: PromptValidator[];
77
+ validators?: PromptValidator<string>[];
78
+ transformer?: PromptTransformer<T>;
65
79
  secure?: boolean | {
66
80
  placeholder: string;
67
81
  };
@@ -71,28 +85,37 @@ interface ConfirmOptions extends AbstractPromptOptions {
71
85
  initial?: boolean;
72
86
  }
73
87
 
74
- interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
88
+ interface SelectOptions<T extends string> extends AbstractPromptOptions {
75
89
  choices: (Choice<T> | T)[];
76
90
  maxVisible?: number;
77
- preSelectedChoices?: (Choice | T)[];
78
- validators?: PromptValidator<T[]>[];
91
+ ignoreValues?: (T | number | boolean)[];
92
+ validators?: PromptValidator<string>[];
79
93
  autocomplete?: boolean;
80
94
  caseSensitive?: boolean;
81
- showHint?: boolean;
82
95
  }
83
96
 
84
- interface SelectOptions<T extends string> extends AbstractPromptOptions {
97
+ interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
85
98
  choices: (Choice<T> | T)[];
86
99
  maxVisible?: number;
87
- ignoreValues?: (T | number | boolean)[];
88
- validators?: PromptValidator<T>[];
100
+ preSelectedChoices?: (Choice<T> | T)[];
101
+ validators?: PromptValidator<string[]>[];
89
102
  autocomplete?: boolean;
90
103
  caseSensitive?: boolean;
104
+ showHint?: boolean;
91
105
  }
92
106
 
93
- declare function question(message: string, options?: Omit<QuestionOptions, "message">): Promise<string>;
107
+ declare function question<T = string>(message: string, options?: Omit<QuestionOptions<T>, "message">): Promise<T>;
94
108
  declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
95
109
  declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
96
110
  declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
97
111
 
98
- export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type MultiselectOptions, PromptAgent, type PromptValidator, type QuestionOptions, type SelectOptions, confirm, multiselect, question, required, select };
112
+ declare const validators: {
113
+ required: typeof required;
114
+ };
115
+ declare const transformers: {
116
+ number: typeof number;
117
+ integer: typeof integer;
118
+ url: typeof url;
119
+ };
120
+
121
+ export { type AbstractPromptOptions, type Choice, type ConfirmOptions, type InvalidResponse, type InvalidResponseObject, type MultiselectOptions, PromptAgent, type PromptTransformer, type PromptValidator, type QuestionOptions, type SelectOptions, type TransformationResponse, type ValidResponse, type ValidResponseObject, type ValidTransformationResponse, type ValidationResponse, type ValidationResponseObject, confirm, multiselect, question, select, transformers, validators };