Skip to content

Commit

Permalink
feat: prompt.validate error support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mist3rBru committed Sep 4, 2023
1 parent 90f8e3d commit 261333e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface PromptOptions<Self extends Prompt> {
render(this: Omit<Self, 'prompt'>): string | void;
placeholder?: string;
initialValue?: any;
validate?: ((value: any) => string | void) | undefined;
validate?: ((value: any) => string | Error | void) | undefined;
input?: Readable;
output?: Writable;
debug?: boolean;
Expand Down Expand Up @@ -180,7 +180,7 @@ export default class Prompt {
if (this.opts.validate) {
const problem = this.opts.validate(this.value);
if (problem) {
this.error = problem;
this.error = problem instanceof Error ? problem.message : problem;
this.state = 'error';
this.rl.write(this.value);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export interface TextOptions {
placeholder?: string;
defaultValue?: string;
initialValue?: string;
validate?: (value: string) => string | void;
validate?: (value: string) => string | Error | void;
}
export const text = (opts: TextOptions) => {
return new TextPrompt({
Expand Down Expand Up @@ -134,7 +134,7 @@ export const text = (opts: TextOptions) => {
export interface PasswordOptions {
message: string;
mask?: string;
validate?: (value: string) => string | void;
validate?: (value: string) => string | Error | void;
}
export const password = (opts: PasswordOptions) => {
return new PasswordPrompt({
Expand Down

0 comments on commit 261333e

Please sign in to comment.