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> {
1414 render ( this : Omit < Self , 'prompt' > ) : string | undefined ;
1515 placeholder ?: string ;
1616 initialValue ?: any ;
17- validate ?: ( ( value : any ) => string | undefined ) | undefined ;
17+ validate ?: ( ( value : any ) => string | Error | undefined ) | undefined ;
1818 input ?: Readable ;
1919 output ?: Writable ;
2020 debug ?: boolean ;
@@ -207,7 +207,7 @@ export default class Prompt {
207207 if ( this . opts . validate ) {
208208 const problem = this . opts . validate ( this . value ) ;
209209 if ( problem ) {
210- this . error = problem ;
210+ this . error = problem instanceof Error ? problem . message : problem ;
211211 this . state = 'error' ;
212212 this . rl ?. write ( this . value ) ;
213213 }
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ export interface TextOptions {
102102 placeholder ?: string ;
103103 defaultValue ?: string ;
104104 initialValue ?: string ;
105- validate ?: ( value : string ) => string | undefined ;
105+ validate ?: ( value : string ) => string | Error | undefined ;
106106}
107107export const text = ( opts : TextOptions ) => {
108108 return new TextPrompt ( {
@@ -138,7 +138,7 @@ export const text = (opts: TextOptions) => {
138138export interface PasswordOptions {
139139 message : string ;
140140 mask ?: string ;
141- validate ?: ( value : string ) => string | undefined ;
141+ validate ?: ( value : string ) => string | Error | undefined ;
142142}
143143export const password = ( opts : PasswordOptions ) => {
144144 return new PasswordPrompt ( {
You can’t perform that action at this time.
0 commit comments