File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @clack/prompts ' : patch
3
+ ' @clack/core ' : patch
4
+ ---
5
+
6
+ Adds ` Error ` support to the ` validate ` function
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export interface PromptOptions<Self extends Prompt> {
14
14
render ( this : Omit < Self , 'prompt' > ) : string | undefined ;
15
15
placeholder ?: string ;
16
16
initialValue ?: any ;
17
- validate ?: ( ( value : any ) => string | undefined ) | undefined ;
17
+ validate ?: ( ( value : any ) => string | Error | undefined ) | undefined ;
18
18
input ?: Readable ;
19
19
output ?: Writable ;
20
20
debug ?: boolean ;
@@ -207,7 +207,7 @@ export default class Prompt {
207
207
if ( this . opts . validate ) {
208
208
const problem = this . opts . validate ( this . value ) ;
209
209
if ( problem ) {
210
- this . error = problem ;
210
+ this . error = problem instanceof Error ? problem . message : problem ;
211
211
this . state = 'error' ;
212
212
this . rl ?. write ( this . value ) ;
213
213
}
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ export interface TextOptions {
102
102
placeholder ?: string ;
103
103
defaultValue ?: string ;
104
104
initialValue ?: string ;
105
- validate ?: ( value : string ) => string | undefined ;
105
+ validate ?: ( value : string ) => string | Error | undefined ;
106
106
}
107
107
export const text = ( opts : TextOptions ) => {
108
108
return new TextPrompt ( {
@@ -138,7 +138,7 @@ export const text = (opts: TextOptions) => {
138
138
export interface PasswordOptions {
139
139
message : string ;
140
140
mask ?: string ;
141
- validate ?: ( value : string ) => string | undefined ;
141
+ validate ?: ( value : string ) => string | Error | undefined ;
142
142
}
143
143
export const password = ( opts : PasswordOptions ) => {
144
144
return new PasswordPrompt ( {
You can’t perform that action at this time.
0 commit comments