[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

feat(@clack/core,@clack/prompts): add `Error` support for `prompt.validate` (#165)

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>

authored by

Bruno Rocha
Nate Moore
and committed by
GitHub
(Jan 8, 2025, 10:15 PM -0600) 8093f3c2 98925e3f

+10 -4
+6
.changeset/moody-hairs-learn.md
··· 1 + --- 2 + '@clack/prompts': patch 3 + '@clack/core': patch 4 + --- 5 + 6 + Adds `Error` support to the `validate` function
+2 -2
packages/core/src/prompts/prompt.ts
··· 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 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 }
+2 -2
packages/prompts/src/index.ts
··· 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 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({