MCPcopy Index your code
hub / github.com/bombshell-dev/clack / main

Function main

examples/basic/text-validation.ts:4–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { isCancel, note, text } from '@clack/prompts';
3
4async function main() {
5 console.clear();
6
7 // Example demonstrating the issue with initial value validation
8 const name = await text({
9 message: 'Enter your name (letters and spaces only)',
10 initialValue: 'John123', // Invalid initial value with numbers
11 validate: (value) => {
12 if (!value || !/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces';
13 return undefined;
14 },
15 });
16
17 if (!isCancel(name)) {
18 note(`Valid name: ${name}`, 'Success');
19 }
20
21 await setTimeout(1000);
22
23 // Example with a valid initial value for comparison
24 const validName = await text({
25 message: 'Enter another name (letters and spaces only)',
26 initialValue: 'John Doe', // Valid initial value
27 validate: (value) => {
28 if (!value || !/^[a-zA-Z\s]+$/.test(value)) return 'Name can only contain letters and spaces';
29 return undefined;
30 },
31 });
32
33 if (!isCancel(validName)) {
34 note(`Valid name: ${validName}`, 'Success');
35 }
36
37 await setTimeout(1000);
38}
39
40main().catch(console.error);

Callers 1

text-validation.tsFile · 0.70

Calls 4

textFunction · 0.90
noteFunction · 0.90
isCancelFunction · 0.85
clearMethod · 0.65

Tested by

no test coverage detected