( message: string, options?: OptionalStringInputOptions, )
| 48 | } |
| 49 | |
| 50 | export const optionalStringInput = async ( |
| 51 | message: string, |
| 52 | options?: OptionalStringInputOptions, |
| 53 | ): Promise<string | undefined> => { |
| 54 | const internalOptions = { ...options, required: false } |
| 55 | // ensure empty input is allowed regardless of the validator |
| 56 | const originalValidate = internalOptions.validate |
| 57 | if (originalValidate) { |
| 58 | internalOptions.validate = input => !input || originalValidate(input) |
| 59 | } |
| 60 | const entered = await internalStringInput(message, internalOptions) |
| 61 | |
| 62 | // inquirer returns an empty string when nothing entered; convert that to undefined |
| 63 | return entered ? entered : undefined |
| 64 | } |
| 65 | |
| 66 | export type StringInputOptions = |
| 67 | & Omit<OptionalStringInputOptions, 'default'> |
no test coverage detected