@topcli/prompts 2.4.1 → 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
@@ -9,8 +9,16 @@ type ValidationResponseObject = ValidResponseObject | InvalidResponseObject;
9
9
  type ValidationResponse = InvalidResponse | ValidResponse;
10
10
  type InvalidResponse = string | InvalidResponseObject;
11
11
  type ValidResponse = null | undefined | true | ValidResponseObject;
12
+ type ValidTransformationResponse<T> = {
13
+ isValid: true;
14
+ transformed: T;
15
+ };
16
+ type TransformationResponse<T> = InvalidResponse | ValidTransformationResponse<T>;
12
17
  interface PromptValidator<T extends string | string[]> {
13
- validate: (input: T) => ValidationResponse;
18
+ validate: (input: T) => ValidationResponse | Promise<ValidationResponse>;
19
+ }
20
+ interface PromptTransformer<T> {
21
+ transform: (input: string) => TransformationResponse<T> | Promise<TransformationResponse<T>>;
14
22
  }
15
23
  declare function required(): PromptValidator<any>;
16
24
 
@@ -40,6 +48,10 @@ declare class PromptAgent<T = string> {
40
48
  nextAnswer(value: T): void;
41
49
  }
42
50
 
51
+ declare function number(): PromptTransformer<number>;
52
+ declare function integer(): PromptTransformer<number>;
53
+ declare function url(): PromptTransformer<URL>;
54
+
43
55
  interface Choice<T extends string> {
44
56
  value: T;
45
57
  label: string;
@@ -60,9 +72,10 @@ interface AbstractPromptOptions {
60
72
  signal?: AbortSignal;
61
73
  }
62
74
 
63
- interface QuestionOptions extends AbstractPromptOptions {
75
+ interface QuestionOptions<T = string> extends AbstractPromptOptions {
64
76
  defaultValue?: string;
65
77
  validators?: PromptValidator<string>[];
78
+ transformer?: PromptTransformer<T>;
66
79
  secure?: boolean | {
67
80
  placeholder: string;
68
81
  };
@@ -91,9 +104,18 @@ interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
91
104
  showHint?: boolean;
92
105
  }
93
106
 
94
- 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>;
95
108
  declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
96
109
  declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
97
110
  declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
98
111
 
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 };
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
@@ -9,8 +9,16 @@ type ValidationResponseObject = ValidResponseObject | InvalidResponseObject;
9
9
  type ValidationResponse = InvalidResponse | ValidResponse;
10
10
  type InvalidResponse = string | InvalidResponseObject;
11
11
  type ValidResponse = null | undefined | true | ValidResponseObject;
12
+ type ValidTransformationResponse<T> = {
13
+ isValid: true;
14
+ transformed: T;
15
+ };
16
+ type TransformationResponse<T> = InvalidResponse | ValidTransformationResponse<T>;
12
17
  interface PromptValidator<T extends string | string[]> {
13
- validate: (input: T) => ValidationResponse;
18
+ validate: (input: T) => ValidationResponse | Promise<ValidationResponse>;
19
+ }
20
+ interface PromptTransformer<T> {
21
+ transform: (input: string) => TransformationResponse<T> | Promise<TransformationResponse<T>>;
14
22
  }
15
23
  declare function required(): PromptValidator<any>;
16
24
 
@@ -40,6 +48,10 @@ declare class PromptAgent<T = string> {
40
48
  nextAnswer(value: T): void;
41
49
  }
42
50
 
51
+ declare function number(): PromptTransformer<number>;
52
+ declare function integer(): PromptTransformer<number>;
53
+ declare function url(): PromptTransformer<URL>;
54
+
43
55
  interface Choice<T extends string> {
44
56
  value: T;
45
57
  label: string;
@@ -60,9 +72,10 @@ interface AbstractPromptOptions {
60
72
  signal?: AbortSignal;
61
73
  }
62
74
 
63
- interface QuestionOptions extends AbstractPromptOptions {
75
+ interface QuestionOptions<T = string> extends AbstractPromptOptions {
64
76
  defaultValue?: string;
65
77
  validators?: PromptValidator<string>[];
78
+ transformer?: PromptTransformer<T>;
66
79
  secure?: boolean | {
67
80
  placeholder: string;
68
81
  };
@@ -91,9 +104,18 @@ interface MultiselectOptions<T extends string> extends AbstractPromptOptions {
91
104
  showHint?: boolean;
92
105
  }
93
106
 
94
- 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>;
95
108
  declare function select<T extends string>(message: string, options: Omit<SelectOptions<T>, "message">): Promise<T>;
96
109
  declare function confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>;
97
110
  declare function multiselect<T extends string>(message: string, options: Omit<MultiselectOptions<T>, "message">): Promise<T[]>;
98
111
 
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 };
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 };