(
message: string,
options: {
placeholder?: string;
initialValue?: string;
validate?: (value: string) => string | undefined;
} = {},
)
| 140 | } |
| 141 | |
| 142 | export async function text( |
| 143 | message: string, |
| 144 | options: { |
| 145 | placeholder?: string; |
| 146 | initialValue?: string; |
| 147 | validate?: (value: string) => string | undefined; |
| 148 | } = {}, |
| 149 | ): Promise<string> { |
| 150 | const result = await clackText({ |
| 151 | message, |
| 152 | placeholder: options.placeholder, |
| 153 | initialValue: options.initialValue, |
| 154 | validate: options.validate |
| 155 | ? (value) => { |
| 156 | const str = typeof value === "string" ? value : ""; |
| 157 | const err = options.validate?.(str); |
| 158 | return err ?? undefined; |
| 159 | } |
| 160 | : undefined, |
| 161 | }); |
| 162 | handleCancel(result); |
| 163 | return result as string; |
| 164 | } |
| 165 | |
| 166 | // Clack's Option<T> is a distributed conditional that resolves differently |
| 167 | // for primitive vs object values; the structural shape we build is correct |
no test coverage detected