MCPcopy Create free account
hub / github.com/Snapchat/Valdi / sampleValueForType

Function sampleValueForType

npm_modules/cli/src/preview/viewModelParser.ts:122–139  ·  view source on GitHub ↗
(typeString: string)

Source from the content-addressed store, hash-verified

120 * Generate a sample value expression for a prop type.
121 */
122export 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
141function escapeRegex(str: string): string {
142 return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

Callers 2

generateComponentJsxFunction · 0.90

Calls 3

startsWithMethod · 0.80
trimMethod · 0.45
testMethod · 0.45

Tested by

no test coverage detected