MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / stripBasicTypescriptTypes

Function stripBasicTypescriptTypes

lib/v2/prompts/dataAnalysis.ts:232–279  ·  view source on GitHub ↗
(
  jsCodeString: string,
  definedTypeNames?: string[],
)

Source from the content-addressed store, hash-verified

230}
231
232export function stripBasicTypescriptTypes(
233 jsCodeString: string,
234 definedTypeNames?: string[],
235): string {
236 /** Remove type definitions like `: string`, `: number`, `: any` etc. **/
237 definedTypeNames = definedTypeNames ?? [];
238
239 // Remove interface definitions
240 const interfaces = jsCodeString.match(
241 /(?:export )?interface\s+(\w+)\s*\{[^}]+}/g,
242 );
243 if (interfaces) {
244 definedTypeNames.push(
245 // ...interfaces.map((i) => i.match(/(?:export )?interface\s+(\w+)/)[1]),
246 ...interfaces.map((i) => i.match(/(?:export )?interface\s+(\w+)/)![1]),
247 );
248 }
249 jsCodeString = jsCodeString.replace(
250 /(?:export )?interface\s+(\w+)\s*\{[^}]+}/g,
251 "",
252 );
253
254 // Remove type definitions
255 const types = jsCodeString.match(/(?:export )?type\s*(\w+)\s*=\s*\w+;?/g);
256 if (types) {
257 definedTypeNames.push(
258 // ...types.map((i) => i.match(/(?:export )?type\s*(\w+)\s*=\s*\w+;?/)[1]),
259 ...types.map((i) => i.match(/(?:export )?type\s*(\w+)\s*=\s*\w+;?/)![1]),
260 );
261 }
262 jsCodeString = jsCodeString.replace(/(export )?type\s*\w+\s*=\s*\w+;?/g, "");
263
264 jsCodeString = jsCodeString.replace(
265 new RegExp(
266 `: (${
267 definedTypeNames.length > 0
268 ? definedTypeNames
269 .map((t) => t.replace(/([\[|(){])/g, "\\$1") + "\\b")
270 .join("|") + "|"
271 : ""
272 }any\[]|string\[]|number\[]|null\[]|boolean\[]|object\[]|any|string|number|null|boolean|object|Record<string,\s*(any|string|number|null|boolean|object)>)(\[])?`,
273 "g",
274 ),
275 "",
276 );
277
278 return jsCodeString;
279}
280
281export function shouldTerminateDataAnalysisStreaming(
282 streamedText: string,

Callers 2

parseGeneratedCodeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected