| | |
| | | } |
| | | export const extractReturnType = (code: string, language: CodeLanguage): OutputVar => { |
| | | const codeWithoutComments = code.replace(/\/\*\*[\s\S]*?\*\//, '') |
| | | // console.log(codeWithoutComments) |
| | | console.log(codeWithoutComments) |
| | | |
| | | const returnIndex = codeWithoutComments.indexOf('return') |
| | | if (returnIndex === -1) |
| | |
| | | return {} |
| | | |
| | | const returnContent = codeAfterReturn.slice(startIndex + 1, endIndex - 1) |
| | | // console.log(returnContent) |
| | | console.log(returnContent) |
| | | |
| | | const result: OutputVar = {} |
| | | |
| | |
| | | const matches = returnContent.matchAll(keyRegex) |
| | | |
| | | for (const match of matches) { |
| | | // console.log(`Found key: "${match[1]}" from match: "${match[0]}"`) |
| | | console.log(`Found key: "${match[1]}" from match: "${match[0]}"`) |
| | | const key = match[1] |
| | | result[key] = { |
| | | type: VarType.string, |
| | |
| | | } |
| | | } |
| | | |
| | | // console.log(result) |
| | | console.log(result) |
| | | |
| | | return result |
| | | } |