(typeString: string)
| 120 | * Generate a sample value expression for a prop type. |
| 121 | */ |
| 122 | export function sampleValueForType(typeString: string): string { |
| 123 | const t = typeString.trim(); |
| 124 | |
| 125 | if (t === 'boolean') return 'false'; |
| 126 | if (t === 'string') return "'Sample'"; |
| 127 | if (t === 'number') return '42'; |
| 128 | if (t === 'Date') return 'new Date()'; |
| 129 | |
| 130 | // Function types |
| 131 | if (/^\(\s*\)\s*=>/.test(t)) return '() => {}'; |
| 132 | if (/=>/.test(t)) return '() => {}'; |
| 133 | |
| 134 | // Array |
| 135 | if (t.endsWith('[]') || t.startsWith('Array<')) return '[]'; |
| 136 | |
| 137 | // Fallback |
| 138 | return 'undefined as any'; |
| 139 | } |
| 140 | |
| 141 | function escapeRegex(str: string): string { |
| 142 | return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
no test coverage detected